Esempio n. 1
0
 /**
  * Constructor
  *
  * @param MongoC|MongoClient|array|Traversable $mongo
  * @param string $database
  * @param string $collection
  * @param array $saveOptions
  * @throws Exception\InvalidArgumentException
  * @throws Exception\ExtensionNotLoadedException
  */
 public function __construct($mongo, $database = null, $collection = null, array $saveOptions = [])
 {
     if (!extension_loaded('mongo')) {
         throw new Exception\ExtensionNotLoadedException('Missing ext/mongo');
     }
     if ($mongo instanceof Traversable) {
         // Configuration may be multi-dimensional due to save options
         $mongo = ArrayUtils::iteratorToArray($mongo);
     }
     if (is_array($mongo)) {
         parent::__construct($mongo);
         $saveOptions = isset($mongo['save_options']) ? $mongo['save_options'] : [];
         $collection = isset($mongo['collection']) ? $mongo['collection'] : null;
         $database = isset($mongo['database']) ? $mongo['database'] : null;
         $mongo = isset($mongo['mongo']) ? $mongo['mongo'] : null;
     }
     if (null === $collection) {
         throw new Exception\InvalidArgumentException('The collection parameter cannot be empty');
     }
     if (null === $database) {
         throw new Exception\InvalidArgumentException('The database parameter cannot be empty');
     }
     if (!($mongo instanceof MongoClient || $mongo instanceof MongoC)) {
         throw new Exception\InvalidArgumentException(sprintf('Parameter of type %s is invalid; must be MongoClient or Mongo', is_object($mongo) ? get_class($mongo) : gettype($mongo)));
     }
     $this->mongoCollection = $mongo->selectCollection($database, $collection);
     $this->saveOptions = $saveOptions;
 }
Esempio n. 2
0
 /**
  * Constructor
  *
  * @param  MailMessage|array|Traversable $mail
  * @param  Transport\TransportInterface $transport Optional
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($mail, Transport\TransportInterface $transport = null)
 {
     if ($mail instanceof Traversable) {
         $mail = iterator_to_array($mail);
     }
     if (is_array($mail)) {
         parent::__construct($mail);
         if (isset($mail['subject_prepend_text'])) {
             $this->setSubjectPrependText($mail['subject_prepend_text']);
         }
         $transport = isset($mail['transport']) ? $mail['transport'] : null;
         $mail = isset($mail['mail']) ? $mail['mail'] : null;
     }
     // Ensure we have a valid mail message
     if (!$mail instanceof MailMessage) {
         throw new Exception\InvalidArgumentException(sprintf('Mail parameter of type %s is invalid; must be of type Zend\\Mail\\Message', is_object($mail) ? get_class($mail) : gettype($mail)));
     }
     $this->mail = $mail;
     // Ensure we have a valid mail transport
     if (null === $transport) {
         $transport = new Transport\Sendmail();
     }
     if (!$transport instanceof Transport\TransportInterface) {
         throw new Exception\InvalidArgumentException(sprintf('Transport parameter of type %s is invalid; must be of type Zend\\Mail\\Transport\\TransportInterface', is_object($transport) ? get_class($transport) : gettype($transport)));
     }
     $this->setTransport($transport);
     if ($this->formatter === null) {
         $this->formatter = new SimpleFormatter();
     }
 }
Esempio n. 3
0
 /**
  * Constructor
  *
  * We used the Adapter instead of Zend\Db for a performance reason.
  *
  * @param Adapter|array|Traversable $db
  * @param string $tableName
  * @param array $columnMap
  * @param string $separator
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($db, $tableName = null, array $columnMap = null, $separator = null)
 {
     if ($db instanceof Traversable) {
         $db = iterator_to_array($db);
     }
     if (is_array($db)) {
         parent::__construct($db);
         $separator = isset($db['separator']) ? $db['separator'] : null;
         $columnMap = isset($db['column']) ? $db['column'] : null;
         $tableName = isset($db['table']) ? $db['table'] : null;
         $db = isset($db['db']) ? $db['db'] : null;
     }
     if (!$db instanceof Adapter) {
         throw new Exception\InvalidArgumentException('You must pass a valid Zend\\Db\\Adapter\\Adapter');
     }
     $tableName = (string) $tableName;
     if ('' === $tableName) {
         throw new Exception\InvalidArgumentException('You must specify a table name. Either directly in the constructor, or via options');
     }
     $this->db = $db;
     $this->tableName = $tableName;
     $this->columnMap = $columnMap;
     if (!empty($separator)) {
         $this->separator = $separator;
     }
     $this->setFormatter(new DbFormatter());
 }
Esempio n. 4
0
 /**
  * @param array $options
  */
 public function __construct($options = [])
 {
     parent::__construct($options);
     $this->client = new Client($options);
     if (!isset($options['index'])) {
         $options['index'] = 'log';
     }
     $this->index = $this->client->getIndex($options['index']);
 }
Esempio n. 5
0
 /**
  * Udp constructor.
  * @param array|null|\Traversable $options
  */
 public function __construct($options)
 {
     if ($options instanceof \Traversable) {
         $options = iterator_to_array($options);
     }
     parent::__construct($options);
     $host = array_key_exists('host', $options) ? $options['host'] : '127.0.0.1';
     $port = array_key_exists('port', $options) ? $options['port'] : 12201;
     $transport = new TcpTransport($host, $port);
     $publisher = new Publisher($transport);
     $this->setPublisher($publisher);
 }
Esempio n. 6
0
 /**
  * Sentry constructor.
  *
  * @param array $options
  *
  * @throws \RuntimeException
  * @throws \Zend\Log\Exception\InvalidArgumentException
  */
 public function __construct(array $options = null)
 {
     parent::__construct($options);
     if ($options instanceof Traversable) {
         $options = iterator_to_array($options);
     }
     if (!is_array($options) || !array_key_exists('client', $options)) {
         throw new \RuntimeException('No client specified in options');
     }
     if (array_key_exists('excluded_backtrace_namespaces', $options) && is_array($options['excluded_backtrace_namespaces'])) {
         $this->excludedBacktraceNamespaces = array_merge($this->excludedBacktraceNamespaces, $options['excluded_backtrace_namespaces']);
     }
     $this->client = $options['client'];
 }
Esempio n. 7
0
 /**
  * Initializes a new instance of this class.
  *
  * @param null|FirePhp\FirePhpInterface|array|Traversable $instance An instance of FirePhpInterface
  *        that should be used for logging
  */
 public function __construct($instance = null)
 {
     if ($instance instanceof Traversable) {
         $instance = iterator_to_array($instance);
     }
     if (is_array($instance)) {
         parent::__construct($instance);
         $instance = isset($instance['instance']) ? $instance['instance'] : null;
     }
     if ($instance instanceof FirePhpInterface) {
         throw new Exception\InvalidArgumentException('You must pass a valid FirePhp\\FirePhpInterface');
     }
     $this->firephp = $instance;
     $this->formatter = new FirePhpFormatter();
 }
Esempio n. 8
0
 /**
  * Udp constructor.
  * @param array|null|\Traversable $options
  */
 public function __construct($options)
 {
     if ($options instanceof \Traversable) {
         $options = iterator_to_array($options);
     }
     parent::__construct($options);
     if (array_key_exists('facility', $options)) {
         $this->setFacility($options['facility']);
     }
     $host = array_key_exists('host', $options) ? $options['host'] : '127.0.0.1';
     $port = array_key_exists('port', $options) ? $options['port'] : 12201;
     $transport = new UdpTransport($host, $port, UdpTransport::CHUNK_SIZE_LAN);
     $publisher = new Publisher($transport);
     $this->setPublisher($publisher);
 }
Esempio n. 9
0
 /**
  * Initializes a new instance of this class.
  *
  * @param null|ChromePhpInterface|array|Traversable $instance An instance of ChromePhpInterface
  *        that should be used for logging
  */
 public function __construct($instance = null)
 {
     if ($instance instanceof Traversable) {
         $instance = iterator_to_array($instance);
     }
     if (is_array($instance)) {
         parent::__construct($instance);
         $instance = isset($instance['instance']) ? $instance['instance'] : null;
     }
     if (!($instance instanceof ChromePhpInterface || $instance === null)) {
         throw new Exception\InvalidArgumentException('You must pass a valid Zend\\Log\\Writer\\ChromePhp\\ChromePhpInterface');
     }
     $this->chromephp = $instance === null ? $this->getChromePhp() : $instance;
     $this->formatter = new ChromePhpFormatter();
 }
Esempio n. 10
0
 /**
  * Constructor
  *
  * Set options for a writer. Accepted options are:
  *
  * - filters: array of filters to add to this filter
  * - formatter: formatter for this writer
  * - logger: PsrLoggerInterface implementation
  *
  * @param  array|Traversable|LoggerInterface $options
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($options = null)
 {
     if ($options instanceof PsrLoggerInterface) {
         $this->setLogger($options);
     }
     if ($options instanceof Traversable) {
         $options = iterator_to_array($options);
     }
     if (is_array($options) && isset($options['logger'])) {
         $this->setLogger($options['logger']);
     }
     parent::__construct($options);
     if (null === $this->logger) {
         $this->setLogger(new NullLogger());
     }
 }
Esempio n. 11
0
 /**
  * Constructor
  *
  * @param  string|resource|array|Traversable $streamOrUrl Stream or URL to open as a stream
  * @param  string|null $mode Mode, only applicable if a URL is given
  * @param  null|string $logSeparator Log separator string
  * @param  null|int $filePermissions Permissions value, only applicable if a filename is given;
  *     when $streamOrUrl is an array of options, use the 'chmod' key to specify this.
  * @return Stream
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public function __construct($streamOrUrl, $mode = null, $logSeparator = null, $filePermissions = null)
 {
     if ($streamOrUrl instanceof Traversable) {
         $streamOrUrl = iterator_to_array($streamOrUrl);
     }
     if (is_array($streamOrUrl)) {
         parent::__construct($streamOrUrl);
         $mode = isset($streamOrUrl['mode']) ? $streamOrUrl['mode'] : null;
         $logSeparator = isset($streamOrUrl['log_separator']) ? $streamOrUrl['log_separator'] : null;
         $filePermissions = isset($streamOrUrl['chmod']) ? $streamOrUrl['chmod'] : $filePermissions;
         $streamOrUrl = isset($streamOrUrl['stream']) ? $streamOrUrl['stream'] : null;
     }
     // Setting the default mode
     if (null === $mode) {
         $mode = 'a';
     }
     if (is_resource($streamOrUrl)) {
         if ('stream' != get_resource_type($streamOrUrl)) {
             throw new Exception\InvalidArgumentException(sprintf('Resource is not a stream; received "%s', get_resource_type($streamOrUrl)));
         }
         if ('a' != $mode) {
             throw new Exception\InvalidArgumentException(sprintf('Mode must be "a" on existing streams; received "%s"', $mode));
         }
         $this->stream = $streamOrUrl;
     } else {
         ErrorHandler::start();
         if (isset($filePermissions) && !file_exists($streamOrUrl) && is_writable(dirname($streamOrUrl))) {
             touch($streamOrUrl);
             chmod($streamOrUrl, $filePermissions);
         }
         $this->stream = fopen($streamOrUrl, $mode, false);
         $error = ErrorHandler::stop();
         if (!$this->stream) {
             throw new Exception\RuntimeException(sprintf('"%s" cannot be opened with mode "%s"', $streamOrUrl, $mode), 0, $error);
         }
     }
     if (null !== $logSeparator) {
         $this->setLogSeparator($logSeparator);
     }
     if ($this->formatter === null) {
         $this->formatter = new SimpleFormatter();
     }
 }
 public function __construct($url, $application_id = null)
 {
     if ($url instanceof Traversable) {
         $url = iterator_to_array($url);
     }
     if (is_array($url)) {
         parent::__construct($url);
         $url = isset($url['url']) ? $url['url'] : null;
         $application_id = isset($url['application_id']) ? $url['application_id'] : null;
     }
     if (!isset($application_id)) {
         throw new Exception\InvalidArgumentException('You must specify a skidder application_id for this application');
     }
     $this->url = $url;
     $this->application_id = $application_id;
     if (!$this->hasFormatter()) {
         $this->setFormatter(new SkidderFormatter());
     }
 }
Esempio n. 13
0
 public function __construct($slack_config, $mode = null, $logSeparator = null)
 {
     if (!is_array($slack_config) || !isset($slack_config['token']) || !isset($slack_config['channel'])) {
         throw new Exception\InvalidArgumentException('Slack config must be an array with, at least, keys "token" and "channel"');
     }
     parent::__construct($slack_config);
     $this->slack_config['token'] = $slack_config['token'];
     $this->slack_config['channel'] = $slack_config['channel'];
     if (!empty($slack_config['username'])) {
         $this->slack_config['username'] = $slack_config['username'];
     }
     if (!empty($slack_config['icon_emoji'])) {
         $this->slack_config['icon_emoji'] = $slack_config['icon_emoji'];
     }
     if (!empty($slack_config['priority'])) {
         $filter = new Priority($slack_config['priority']);
         $this->addFilter($filter);
     }
     $this->formatter = new SlackFormatter();
     $this->curl = new Curl();
 }
Esempio n. 14
0
 /**
  * Constructor
  *
  * @param Manager|array|Traversable $manager
  * @param string $database
  * @param string $collection
  * @param WriteConcern|array|Traversable $writeConcern
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($manager, $database = null, $collection = null, $writeConcern = null)
 {
     if (!extension_loaded('mongodb')) {
         throw new Exception\ExtensionNotLoadedException('Missing ext/mongodb');
     }
     if ($manager instanceof Traversable) {
         // Configuration may be multi-dimensional due to save options
         $manager = ArrayUtils::iteratorToArray($manager);
     }
     if (is_array($manager)) {
         parent::__construct($manager);
         $writeConcern = isset($manager['write_concern']) ? $manager['write_concern'] : new WriteConcern(1);
         $collection = isset($manager['collection']) ? $manager['collection'] : null;
         $database = isset($manager['database']) ? $manager['database'] : null;
         $manager = isset($manager['manager']) ? $manager['manager'] : null;
     }
     if (null === $database) {
         throw new Exception\InvalidArgumentException('The database parameter cannot be empty');
     }
     if (null !== $collection) {
         $database = sprintf('%s.%s', $database, $collection);
     }
     if (!$manager instanceof Manager) {
         throw new Exception\InvalidArgumentException(sprintf('Parameter of type %s is invalid; must be MongoDB\\Driver\\Manager', is_object($manager) ? get_class($manager) : gettype($manager)));
     }
     if ($writeConcern instanceof Traversable) {
         $writeConcern = iterator_to_array($writeConcern);
     }
     if (is_array($writeConcern)) {
         $wstring = isset($writeConcern['wstring']) ? $writeConcern['wstring'] : 1;
         $wtimeout = isset($writeConcern['wtimeout']) ? $writeConcern['wtimeout'] : 0;
         $journal = isset($writeConcern['journal']) ? $writeConcern['journal'] : false;
         $writeConcern = new WriteConcern($wstring, $wtimeout, $journal);
     }
     $this->manager = $manager;
     $this->database = $database;
     $this->writeConcern = $writeConcern;
 }
Esempio n. 15
0
 /**
  * Constructor
  *
  * @param  array $params Array of options; may include "application" and "facility" keys
  * @return Syslog
  */
 public function __construct($params = null)
 {
     if ($params instanceof Traversable) {
         $params = iterator_to_array($params);
     }
     $runInitializeSyslog = true;
     if (is_array($params)) {
         parent::__construct($params);
         if (isset($params['application'])) {
             $this->appName = $params['application'];
         }
         if (isset($params['facility'])) {
             $this->setFacility($params['facility']);
             $runInitializeSyslog = false;
         }
     }
     if ($runInitializeSyslog) {
         $this->initializeSyslog();
     }
     if ($this->formatter === null) {
         $this->setFormatter(new SimpleFormatter('%message%'));
     }
 }
Esempio n. 16
0
 public function __construct($options)
 {
     if ($options instanceof \Traversable) {
         $options = iterator_to_array($options);
     }
     parent::__construct($options);
     if (array_key_exists('protocol', $options)) {
         $this->setProtocol($options['protocol']);
     } else {
         $this->setProtocol('udp');
     }
     if (array_key_exists('host', $options)) {
         $this->setHost($options['host']);
     } else {
         $this->setHost('127.0.0.1');
     }
     if (array_key_exists('port', $options)) {
         $this->setPort($options['port']);
     } else {
         $this->setPort(12201);
     }
     $this->initialize();
 }
Esempio n. 17
0
 public function __construct($options = null)
 {
     parent::__construct($options);
     $this->chromephp = ChromePhpClass::getInstance();
     $this->formatter = new ChromePhpFormatter();
 }
Esempio n. 18
0
 /**
  * Sentry constructor.
  *
  * @param Raven $raven
  * @param null  $options
  */
 public function __construct(Raven $raven, $options = null)
 {
     $this->raven = $raven;
     parent::__construct($options);
 }
Esempio n. 19
0
 /**
  *
  * @param AdapterInterface $console
  * @param int $level
  * @param string $options
  */
 public function __construct(AdapterInterface $console, $level = Logger::ERR, $options = null)
 {
     $this->setConsole($console)->setLevel($level);
     parent::__construct($options);
 }
Esempio n. 20
0
 /**
  * Constructor
  *
  * @param string $sentryApiKey
  * @return array $options
  */
 public function __construct($sentryApiKey, $options = null)
 {
     $this->raven = new Raven($sentryApiKey);
     parent::__construct($options);
 }