Horde_Push_Factory_Recipients::create PHP Méthode

create() public méthode

Create the recipient list.
public create ( array $options, array $conf ) : array
$options array Command line options.
$conf array The configuration.
Résultat array The list of recipients.
    public function create($options, $conf)
    {
        $result = array();
        if (isset($options['recipients'])) {
            $recipients = array_map('trim', explode(',', $options['recipients']));
        } elseif (isset($conf['recipients'])) {
            $recipients = $conf['recipients'];
        } else {
            return $result;
        }
        foreach ($recipients as $recipient) {
            if (strpos($recipient, ':') !== false) {
                list($recipient, $acl) = explode(':', $recipient);
            } else {
                $acl = null;
            }
            if (isset($conf['recipient'][$recipient])) {
                $type = $conf['recipient'][$recipient]['type'];
                if ($acl === null && isset($conf['recipient'][$recipient]['acl'])) {
                    $acl = $conf['recipient'][$recipient]['acl'];
                }
                $recipient_conf = array_merge($conf, $conf['recipient'][$recipient]);
            } else {
                $type = $recipient;
                $recipient_conf = $conf;
            }
            switch ($type) {
                case 'twitter':
                    $r = $this->_createTwitter($recipient_conf);
                    break;
                case 'facebook':
                    $r = $this->_createFacebook($recipient_conf);
                    break;
                case 'blogger':
                    $r = $this->_createBlogger($recipient_conf);
                    break;
                case 'mail':
                    $r = $this->_createMail($recipient_conf);
                    break;
                case 'mock':
                    $r = new Horde_Push_Recipient_Mock();
                    break;
                default:
                    throw new Horde_Push_Exception(sprintf('Unknown recipient type "%s"!', $type));
            }
            $r->setAcl($acl);
            $result[] = $r;
        }
        return $result;
    }

Usage Example

Exemple #1
0
 /**
  * The main entry point for the application.
  *
  * @param array $parameters A list of named configuration parameters.
  */
 public static function main(array $parameters = array())
 {
     $parser = new Horde_Argv_Parser(array('usage' => '%prog [OPTIONS] [SOURCE://ID]'));
     $parser->addOptions(array(new Horde_Argv_Option('-c', '--config', array('action' => 'store', 'help' => Horde_Push_Translation::t('Path to the configuration file.'))), new Horde_Argv_Option('-S', '--summary', array('action' => 'store', 'help' => Horde_Push_Translation::t('A summary replacing the value provided by the source.'))), new Horde_Argv_Option('-R', '--recipients', array('action' => 'store', 'help' => Horde_Push_Translation::t('A comma delimited list of recipients.'))), new Horde_Argv_Option('-T', '--tags', array('action' => 'store', 'help' => Horde_Push_Translation::t('A comma delimited list of tags.'))), new Horde_Argv_Option('-L', '--links', array('action' => 'store', 'help' => Horde_Push_Translation::t('A comma delimited list of links.'))), new Horde_Argv_Option('-p', '--pretend', array('action' => 'store_true', 'help' => Horde_Push_Translation::t('Do not push the content but display what would be done.')))));
     list($options, $arguments) = $parser->parseArgs();
     global $conf;
     if (isset($options['config'])) {
         if (!file_exists($options['config'])) {
             throw new Horde_Push_Exception(sprintf('The specified config file %s does not exist!', $options['config']));
         }
         include $options['config'];
     } else {
         $conf = array('recipients' => array('mock'));
     }
     if (empty($arguments)) {
         $arguments = explode(' ', trim(file_get_contents('php://stdin')));
     }
     $push_factory = new Horde_Push_Factory_Push();
     $pushes = $push_factory->create($arguments, $options, $conf);
     $fail = false;
     foreach ($pushes as $push) {
         if (isset($options['summary'])) {
             $push->setSummary($options['summary']);
         }
         if (isset($options['tags'])) {
             foreach (explode(',', $options['tags']) as $tag) {
                 $push->addTag($tag);
             }
         }
         if (isset($options['links'])) {
             foreach (explode(',', $options['links']) as $reference) {
                 $push->addReference($reference);
             }
         }
         $recipient_factory = new Horde_Push_Factory_Recipients();
         $recipients = $recipient_factory->create($options, $conf);
         foreach ($recipients as $recipient) {
             $push->addRecipient($recipient);
         }
         $results = $push->push(array('pretend' => !empty($options['pretend'])));
         $cli = Horde_Cli::init();
         foreach ($results as $result) {
             if ($result instanceof Exception) {
                 $cli->message($result->getMessage(), 'cli.error');
                 $fail = true;
             } else {
                 $cli->message((string) $result, 'cli.success');
             }
         }
     }
     if ($fail === true) {
         $status = 1;
     } else {
         $status = 0;
     }
     if (empty($parameters['no_exit'])) {
         exit($status);
     } else {
         return $status;
     }
 }
All Usage Examples Of Horde_Push_Factory_Recipients::create