Пример #1
0
 /**
  * Constructor
  *
  * @param  array|\Traversable $options
  * @param  \ZendQueue\Queue|null $queue
  * @return void
  */
 public function __construct($options, Queue $queue = null)
 {
     parent::__construct($options, $queue);
     if (!extension_loaded("jobqueue_client")) {
         throw new Exception\ExtensionNotLoadedException('Platform Job Queue extension does not appear to be loaded');
     }
     if (!isset($this->_options['daemonOptions'])) {
         throw new Exception\InvalidArgumentException('Job Queue host and password should be provided');
     }
     $options = $this->_options['daemonOptions'];
     if (!array_key_exists('host', $options)) {
         throw new Exception\InvalidArgumentException('Platform Job Queue host should be provided');
     }
     if (!array_key_exists('password', $options)) {
         throw new Exception\InvalidArgumentException('Platform Job Queue password should be provided');
     }
     $this->_zendQueue = new ZendAPI_Queue($options['host']);
     if (!$this->_zendQueue) {
         throw new Exception\ConnectionException('Platform Job Queue connection failed');
     }
     if (!$this->_zendQueue->login($options['password'])) {
         throw new Exception\ConnectionException('Job Queue login failed');
     }
     if ($this->_queue) {
         $this->_queue->setMessageClass('\\ZendQueue\\Message\\PlatformJob');
     }
 }
Пример #2
0
 /**
  * Constructor
  *
  * @param  array|\Traversable $options An array having configuration data
  * @param  \ZendQueue\Queue The \ZendQueue\Queue object that created this class
  */
 public function __construct($options, Queue $queue = null)
 {
     parent::__construct($options);
     $options =& $this->_options['driverOptions'];
     if (!array_key_exists('scheme', $options)) {
         $options['scheme'] = self::DEFAULT_SCHEME;
     }
     if (!array_key_exists('host', $options)) {
         $options['host'] = self::DEFAULT_HOST;
     }
     if (!array_key_exists('port', $options)) {
         $options['port'] = self::DEFAULT_PORT;
     }
     if (array_key_exists('stompClient', $options)) {
         $this->_client = $options['stompClient'];
     } else {
         $this->_client = new Client($options['scheme'], $options['host'], $options['port']);
     }
     $connect = $this->_client->createFrame();
     // Username and password are optional on some messaging servers
     // such as Apache's ActiveMQ
     $connect->setCommand('CONNECT');
     if (isset($options['username'])) {
         $connect->setHeader('login', $options['username']);
         $connect->setHeader('passcode', $options['password']);
     }
     $response = $this->_client->send($connect)->receive();
     if (false !== $response && $response->getCommand() != 'CONNECTED') {
         throw new Exception\ConnectionException("Unable to authenticate to '{$options['scheme']}://{$options['host']}:{$options['port']}'");
     }
 }
Пример #3
0
 /**
  * Constructor
  *
  * @param  array|\Traversable $options
  * @param  \ZendQueue\Queue|null $queue
  */
 public function __construct($options, Queue $queue = null)
 {
     parent::__construct($options, $queue);
     if (!isset($this->_options['options'][Select::FOR_UPDATE])) {
         // turn off auto update by default
         $this->_options['options'][Select::FOR_UPDATE] = false;
     }
     if (!is_bool($this->_options['options'][Select::FOR_UPDATE])) {
         throw new Exception\InvalidArgumentException('Options array item: \\Zend\\Db\\Select::FOR_UPDATE must be boolean');
     }
     if (isset($this->_options['dbAdapter']) && $this->_options['dbAdapter'] instanceof AbstractDBAdapter) {
         $db = $this->_options['dbAdapter'];
     } else {
         $db = $this->_initDBAdapter();
     }
     $this->_queueTable = new Db\Queue(array('db' => $db));
     $this->_messageTable = new Db\Message(array('db' => $db));
 }
Пример #4
0
 /**
  * Constructor
  *
  * @param  array|\Traversable $options
  * @param  null|\ZendQueue\Queue $queue
  * @return void
  */
 public function __construct($options, Queue $queue = null)
 {
     if (!extension_loaded('memcache')) {
         throw new Exception\ExtensionNotLoadedException('Memcache extension does not appear to be loaded');
     }
     parent::__construct($options, $queue);
     $options =& $this->_options['driverOptions'];
     if (!array_key_exists('host', $options)) {
         $options['host'] = self::DEFAULT_HOST;
     }
     if (!array_key_exists('port', $options)) {
         $options['port'] = self::DEFAULT_PORT;
     }
     $this->_cache = new Memcache();
     $result = $this->_cache->connect($options['host'], $options['port']);
     if ($result === false) {
         throw new Exception\ConnectionException('Could not connect to MemcacheQ');
     }
     $this->_host = $options['host'];
     $this->_port = (int) $options['port'];
 }
Пример #5
0
 /**
  * Constructor.
  *
  * @param array|Zend_Config $options options (host, port, login, password)
  * @param null|Queue        $queue
  */
 public function __construct($options, Queue $queue = null)
 {
     parent::__construct($options, $queue);
     if (!class_exists('PhpAmqpLib\\Message\\AMQPMessage')) {
         throw new \Exception('Please install videlalvaro/php-amqplib dependency');
     }
     if (is_array($options)) {
         try {
             $host = $options['host'];
             $port = $options['port'];
             $user = $options['user'];
             $password = $options['password'];
             $connection = new AMQPConnection($host, $port, $user, $password);
             $channel = $connection->channel();
             $this->connection = $connection;
             $this->channel = $channel;
         } catch (\Exception $e) {
             throw new AdapterRuntimeException("Unable to connect RabbitMQ server: {$e->getMessage()}");
         }
     } else {
         throw new MissingConfigurationException('The options must be an associative array of host, port, login, password...');
     }
 }
Пример #6
0
 /**
  * Constructor
  *
  * @param  array|\Traversable $options
  * @param  null|\ZendQueue\Queue $queue
  * @return void
  */
 public function __construct($options, Queue $queue = null)
 {
     if (!extension_loaded('mongo')) {
         throw new Exception\ExtensionNotLoadedException('Mongodb extension does not appear to be loaded');
     }
     parent::__construct($options, $queue);
     $defaultOptions = array('host' => self::DEFAULT_HOST, 'port' => self::DEFAULT_PORT, 'db' => self::DEFAULT_DB, 'dsn' => '', 'username' => '', 'password' => '');
     $options =& $this->_options['driverOptions'];
     $options = array_merge($defaultOptions, $options);
     $connectDsn = $options['dsn'] ? $options['dsn'] : "mongodb://{$options['host']}:{$options['port']}";
     $connectArray = array();
     if ($options['username'] || $options['password']) {
         $connectArray = array('username' => $options['username'], 'password' => $options['password']);
     }
     try {
         $this->mongo = $mongo = $connectArray ? new MongoClient($connectDsn, $connectArray) : new MongoClient($connectDsn);
         $mongo->selectDB($options['db']);
     } catch (\MongoConnectionException $e) {
         throw new Exception\ConnectionException('Could not connect to MongoDb');
     }
     $this->db = $options['db'];
     $this->host = $options['host'];
     $this->port = (int) $options['port'];
 }
Пример #7
0
 public function __construct($options = array(), ZendQueue $queue = null)
 {
     $this->db = $options['connection'];
     parent::__construct($options, $queue);
 }