/** * Sets validator options * * Mimetype to accept * - NULL means default PHP usage by using the environment variable 'magic' * - FALSE means disabling searching for mimetype, should be used for PHP 5.3 * - A string is the mimetype file to use * * @param string|array|Traversable $options */ public function __construct($options = null) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } elseif (is_string($options)) { $this->setMimeType($options); $options = []; } elseif (is_array($options)) { if (isset($options['magicFile'])) { $this->setMagicFile($options['magicFile']); unset($options['magicFile']); } if (isset($options['enableHeaderCheck'])) { $this->enableHeaderCheck($options['enableHeaderCheck']); unset($options['enableHeaderCheck']); } if (array_key_exists('mimeType', $options)) { $this->setMimeType($options['mimeType']); unset($options['mimeType']); } // Handle cases where mimetypes are interspersed with options, or // options are simply an array of mime types foreach (array_keys($options) as $key) { if (!is_int($key)) { continue; } $this->addMimeType($options[$key]); unset($options[$key]); } } parent::__construct($options); }
/** * Create and return a StorageInterface instance * * @param string $type * @param array|Traversable $options * @return StorageInterface * @throws Exception\InvalidArgumentException for unrecognized $type or individual options */ public static function factory($type, $options = array()) { if (!is_string($type)) { throw new Exception\InvalidArgumentException(sprintf('%s expects the $type argument to be a string class name; received "%s"', __METHOD__, is_object($type) ? get_class($type) : gettype($type))); } if (!class_exists($type)) { $class = __NAMESPACE__ . '\\' . $type; if (!class_exists($class)) { throw new Exception\InvalidArgumentException(sprintf('%s expects the $type argument to be a valid class name; received "%s"', __METHOD__, $type)); } $type = $class; } if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { throw new Exception\InvalidArgumentException(sprintf('%s expects the $options argument to be an array or Traversable; received "%s"', __METHOD__, is_object($options) ? get_class($options) : gettype($options))); } switch (true) { case in_array('Zend\\Session\\Storage\\AbstractSessionArrayStorage', class_parents($type)): return static::createSessionArrayStorage($type, $options); break; case $type === 'Zend\\Session\\Storage\\ArrayStorage': case in_array('Zend\\Session\\Storage\\ArrayStorage', class_parents($type)): return static::createArrayStorage($type, $options); break; case in_array('Zend\\Session\\Storage\\StorageInterface', class_implements($type)): return new $type($options); break; default: throw new Exception\InvalidArgumentException(sprintf('Unrecognized type "%s" provided; expects a class implementing %s\\StorageInterface', $type, __NAMESPACE__)); } }
/** * Sets validator options * * @param string|array|\Traversable $options */ public function __construct($options = null) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } $case = null; if (1 < func_num_args()) { $case = func_get_arg(1); } if (is_array($options)) { if (isset($options['case'])) { $case = $options['case']; unset($options['case']); } if (!array_key_exists('extension', $options)) { $options = array('extension' => $options); } } else { $options = array('extension' => $options); } if ($case !== null) { $options['case'] = $case; } parent::__construct($options); }
/** * Create a captcha adapter instance * * @param array|Traversable $options * @return AdapterInterface * @throws Exception\InvalidArgumentException for a non-array, non-Traversable $options * @throws Exception\DomainException if class is missing or invalid */ public static function factory($options) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { throw new Exception\InvalidArgumentException(sprintf('%s expects an array or Traversable argument; received "%s"', __METHOD__, is_object($options) ? get_class($options) : gettype($options))); } if (!isset($options['class'])) { throw new Exception\DomainException(sprintf('%s expects a "class" attribute in the options; none provided', __METHOD__)); } $class = $options['class']; if (isset(static::$classMap[strtolower($class)])) { $class = static::$classMap[strtolower($class)]; } if (!class_exists($class)) { throw new Exception\DomainException(sprintf('%s expects the "class" attribute to resolve to an existing class; received "%s"', __METHOD__, $class)); } unset($options['class']); if (isset($options['options'])) { $options = $options['options']; } $captcha = new $class($options); if (!$captcha instanceof AdapterInterface) { throw new Exception\DomainException(sprintf('%s expects the "class" attribute to resolve to a valid Zend\\Captcha\\AdapterInterface instance; received "%s"', __METHOD__, $class)); } return $captcha; }
public function setData($data) { if ($data instanceof Traversable) { $data = ArrayUtils::iteratorToArray($data); } $isAts = isset($data['atsEnabled']) && $data['atsEnabled']; $isUri = isset($data['uriApply']) && !empty($data['uriApply']); $email = isset($data['contactEmail']) ? $data['contactEmail'] : ''; if ($isAts && $isUri) { $data['atsMode']['mode'] = 'uri'; $data['atsMode']['uri'] = $data['uriApply']; $uri = new Http($data['uriApply']); if ($uri->getHost() == $this->host) { $data['atsMode']['mode'] = 'intern'; } } elseif ($isAts && !$isUri) { $data['atsMode']['mode'] = 'intern'; } elseif (!$isAts && !empty($email)) { $data['atsMode']['mode'] = 'email'; $data['atsMode']['email'] = $email; } else { $data['atsMode']['mode'] = 'none'; } if (!array_key_exists('job', $data)) { $data = array('job' => $data); } return parent::setData($data); }
/** * Set the element value * * @param mixed $value * @return TagList */ public function setValue($value) { if ($value instanceof Traversable) { $value = ArrayUtils::iteratorToArray($value); } return parent::setValue((array) $value); }
/** * Class constructor * (the default encoding is UTF-8) * * @param array|Traversable $options * @return Xml */ public function __construct($options = array()) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { $args = func_get_args(); $options = array('rootElement' => array_shift($args)); if (count($args)) { $options['elementMap'] = array_shift($args); } if (count($args)) { $options['encoding'] = array_shift($args); } if (count($args)) { $options['dateTimeFormat'] = array_shift($args); } } if (!array_key_exists('rootElement', $options)) { $options['rootElement'] = 'logEntry'; } if (!array_key_exists('encoding', $options)) { $options['encoding'] = 'UTF-8'; } $this->rootElement = $options['rootElement']; $this->setEncoding($options['encoding']); if (array_key_exists('elementMap', $options)) { $this->elementMap = $options['elementMap']; } if (array_key_exists('dateTimeFormat', $options)) { $this->setDateTimeFormat($options['dateTimeFormat']); } }
/** * Class constructor * * @param string|array|\Traversable $options Encryption Options */ public function __construct($options) { if (!extension_loaded('mcrypt')) { throw new Exception\ExtensionNotLoadedException('This filter needs the mcrypt extension'); } if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } elseif (is_string($options)) { $options = array('key' => $options); } elseif (!is_array($options)) { throw new Exception\InvalidArgumentException('Invalid options argument provided to filter'); } if (array_key_exists('compression', $options)) { $this->setCompression($options['compression']); unset($options['compress']); } if (array_key_exists('compression', $options)) { $this->setCompression($options['compression']); unset($options['compress']); } $this->setEncryption($options); }
/** * Sets default option values for this instance * * @param boolean|Traversable|array $allowWhiteSpace */ public function __construct($options = false) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { $options = func_get_args(); $temp = array(); if (!empty($options)) { $temp['allowWhiteSpace'] = array_shift($options); } if (!empty($options)) { $temp['locale'] = array_shift($options); } $options = $temp; } if (null === self::$unicodeEnabled) { self::$unicodeEnabled = (@preg_match('/\pL/u', 'a')) ? true : false; } if (array_key_exists('allowWhiteSpace', $options)) { $this->setAllowWhiteSpace($options['allowWhiteSpace']); } if (!array_key_exists('locale', $options)) { $options['locale'] = null; } $this->setLocale($options['locale']); }
public function listAction() { $console = $this->getServiceLocator()->get('console'); $sm = $this->getServiceLocator(); $isLocal = $this->params()->fromRoute('local'); if ($isLocal) { $appdir = getcwd(); echo $appdir; if (file_exists($appdir . '/config/autoload/local.php')) { $config = (include $appdir . '/config/autoload/local.php'); } else { echo 'FILE NO EXIST' . PHP_EOL; $config = array(); } } else { $config = $sm->get('Configuration'); } if (!is_array($config)) { $config = ArrayUtils::iteratorToArray($config, true); } $console->writeLine('Configuration:', Color::GREEN); // print_r($config); $ini = new IniWriter(); echo $ini->toString($config); }
/** * Constructor * * @param array|Traversable|int|null $typeOrOptions * @param bool $casting * @param array $translations */ public function __construct($typeOrOptions = null, $casting = true, $translations = array()) { if ($typeOrOptions !== null) { if ($typeOrOptions instanceof Traversable) { $typeOrOptions = ArrayUtils::iteratorToArray($typeOrOptions); } if (is_array($typeOrOptions)) { if (isset($typeOrOptions['type']) || isset($typeOrOptions['casting']) || isset($typeOrOptions['translations'])) { $this->setOptions($typeOrOptions); } else { $this->setType($typeOrOptions); $this->setCasting($casting); $this->setTranslations($translations); } } else { $this->setType($typeOrOptions); $this->setCasting($casting); $this->setTranslations($translations); } } }
/** * Sets the filter options * Allowed options are * 'allowTags' => Tags which are allowed * 'allowAttribs' => Attributes which are allowed * 'allowComments' => Are comments allowed ? * * @param string|array|Traversable $options * @return void */ public function __construct($options = null) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if ((!is_array($options)) || (is_array($options) && !array_key_exists('allowTags', $options) && !array_key_exists('allowAttribs', $options) && !array_key_exists('allowComments', $options))) { $options = func_get_args(); $temp['allowTags'] = array_shift($options); if (!empty($options)) { $temp['allowAttribs'] = array_shift($options); } if (!empty($options)) { $temp['allowComments'] = array_shift($options); } $options = $temp; } if (array_key_exists('allowTags', $options)) { $this->setTagsAllowed($options['allowTags']); } if (array_key_exists('allowAttribs', $options)) { $this->setAttributesAllowed($options['allowAttribs']); } }
/** * Constructor * * @param array|Traversable $options */ public function __construct($options = array()) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { throw new Exception\InvalidArgumentException('Invalid options provided'); } if (isset($options[self::MESSAGE_CLASS])) { $this->setMessageClass($options[self::MESSAGE_CLASS]); } if (isset($options[self::MESSAGESET_CLASS])) { $this->setMessageSetClass($options[self::MESSAGESET_CLASS]); } try { $this->_sqs = new AmazonSqs( $options[self::AWS_ACCESS_KEY], $options[self::AWS_SECRET_KEY] ); } catch(\Zend\Service\Amazon\Exception $e) { throw new Exception\RunTimeException('Error on create: '.$e->getMessage(), $e->getCode(), $e); } if(isset($options[self::HTTP_ADAPTER])) { $this->_sqs->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]); } }
public function __construct($options = null) { parent::__construct($options); if ($options instanceof \Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (is_array($options)) { if (!empty($options['stream'])) { if (!is_array($options['stream'])) { $options['stream'] = ['uri' => $options['stream']]; } if (!empty($options['stream']['uri'])) { $writer = new Stream($options['stream']['uri']); if (!empty($options['stream']['priority'])) { $filter = new Priority($options['stream']['priority']); $writer->addFilter($filter); } $this->addWriter($writer); } } if (!empty($options['slack'])) { $writer = new SlackWriter($options['slack']); $this->addWriter($writer); } if (!empty($options['register_error_handler'])) { Logger::registerErrorHandler($this); } if (!empty($options['register_exception_handler'])) { Logger::registerExceptionHandler($this); } } }
/** * 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; }
/** * Constructor * * @param array|Traversable $options */ public function __construct ($options = array()) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { throw new Exception\InvalidArgumentException('Invalid options provided'); } if (isset($options[self::MESSAGE_CLASS])) { $this->setMessageClass($options[self::MESSAGE_CLASS]); } if (isset($options[self::MESSAGESET_CLASS])) { $this->setMessageSetClass($options[self::MESSAGESET_CLASS]); } // Build Zend\Service\WindowsAzure\Storage\Blob instance if (!isset($options[self::ADAPTER])) { throw new Exception\InvalidArgumentException('No \Zend\Queue adapter provided'); } else { $adapter = $options[self::ADAPTER]; unset($options[self::ADAPTER]); } try { $this->_queue = new Queue($adapter, $options); } catch (\Zend\Queue\Exception\ExceptionInterface $e) { throw new Exception\RunTimeException('Error on create: '.$e->getMessage(), $e->getCode(), $e); } }
/** * Class constructor * * @param string|array|Traversable $options (Optional) Options to set, if null mcrypt is used */ public function __construct($options = null) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } $this->setAdapter($options); }
/** * Renders a template fragment within a variable scope distinct from the * calling View object. * * If no arguments are provided, returns object instance. * * @param string $name Name of view script * @param array $values Variables to populate in the view * @throws Exception\InvalidArgumentException * @return string */ public function __invoke($name = null, $values = null) { if (0 == func_num_args()) { return $this; } if (!is_array($values) && (!$values instanceof Traversable) && (is_object($values) && !method_exists($values, 'toArray')) ) { throw new Exception\InvalidArgumentException('PartialLoop helper requires iterable data'); } if (is_object($values) && (!$values instanceof Traversable) && method_exists($values, 'toArray') ) { $values = $values->toArray(); } if ($values instanceof Iterator) { $values = ArrayUtils::iteratorToArray($values); } // reset the counter if it's called again $this->partialCounter = 0; $content = ''; foreach ($values as $item) { $this->partialCounter++; $content .= parent::__invoke($name, $item); } return $content; }
/** * Allow patching one or more key/value pairs * * Expects data to be in the form of key/value pairs * * @param array|stdClass|Traversable $data * @return array */ public function patch($data, $tree = false) { if ($data instanceof Traversable) { $data = ArrayUtils::iteratorToArray($data); } if ($data instanceof stdClass) { $data = (array) $data; } // Update configuration from dot-separated key/value pairs if (!$tree) { $patchValues = []; foreach ($data as $key => $value) { $this->createNestedKeyValuePair($patchValues, $key, $value); } } else { $patchValues = $data; } // Get local config file $localConfig = []; if (file_exists($this->fileName)) { $localConfig = (include $this->fileName); if (!is_array($localConfig)) { $localConfig = []; } } $localConfig = ArrayUtils::merge($localConfig, $patchValues); // Write to configuration file $this->writer->toFile($this->fileName, $localConfig); $this->invalidateCache($this->fileName); // Reseed configuration $this->config = $localConfig; // Return written values return $data; }
/** * @param array $spec * @return TransportInterface * @throws Exception\InvalidArgumentException * @throws Exception\DomainException */ public static function create($spec = array()) { if ($spec instanceof Traversable) { $spec = ArrayUtils::iteratorToArray($spec); } if (!is_array($spec)) { throw new Exception\InvalidArgumentException(sprintf('%s expects an array or Traversable argument; received "%s"', __METHOD__, is_object($spec) ? get_class($spec) : gettype($spec))); } $type = isset($spec['type']) ? $spec['type'] : 'sendmail'; $normalizedType = strtolower($type); if (isset(static::$classMap[$normalizedType])) { $type = static::$classMap[$normalizedType]; } if (!class_exists($type)) { throw new Exception\DomainException(sprintf('%s expects the "type" attribute to resolve to an existing class; received "%s"', __METHOD__, $type)); } $transport = new $type(); if (!$transport instanceof TransportInterface) { throw new Exception\DomainException(sprintf('%s expects the "type" attribute to resolve to a valid' . ' Zend\\Mail\\Transport\\TransportInterface instance; received "%s"', __METHOD__, $type)); } if ($transport instanceof Smtp && isset($spec['options'])) { $transport->setOptions(new SmtpOptions($spec['options'])); } if ($transport instanceof File && isset($spec['options'])) { $transport->setOptions(new FileOptions($spec['options'])); } return $transport; }
/** * Sets filter options * * @param array|Traversable $options */ public function __construct($options = array()) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { $options = func_get_args(); $temp['quotestyle'] = array_shift($options); if (!empty($options)) { $temp['charset'] = array_shift($options); } $options = $temp; } if (!isset($options['quotestyle'])) { $options['quotestyle'] = ENT_QUOTES; } if (!isset($options['encoding'])) { $options['encoding'] = 'UTF-8'; } if (isset($options['charset'])) { $options['encoding'] = $options['charset']; } if (!isset($options['doublequote'])) { $options['doublequote'] = true; } $this->setQuoteStyle($options['quotestyle']); $this->setEncoding($options['encoding']); $this->setDoubleQuote($options['doublequote']); }
/** * Constructor * * @param array|Traversable $options */ public function __construct($options = array()) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { throw new Exception\InvalidArgumentException('Invalid options provided'); } if (!isset($options[self::AWS_ACCESS_KEY]) || !isset($options[self::AWS_SECRET_KEY])) { throw new Exception\InvalidArgumentException('AWS keys not specified!'); } try { $this->_s3 = new AmazonS3($options[self::AWS_ACCESS_KEY], $options[self::AWS_SECRET_KEY]); } catch (\ZendService\Amazon\S3\Exception $e) { throw new Exception\RuntimeException('Error on create: ' . $e->getMessage(), $e->getCode(), $e); } if (isset($options[self::HTTP_ADAPTER])) { $this->_s3->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]); } if (isset($options[self::BUCKET_NAME])) { $this->_defaultBucketName = $options[self::BUCKET_NAME]; } if (isset($options[self::BUCKET_AS_DOMAIN])) { $this->_defaultBucketAsDomain = $options[self::BUCKET_AS_DOMAIN]; } }
/** * Set default options for this instance * * @param array $options */ public function __construct($options = array()) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } elseif (!is_array($options)) { $options = func_get_args(); $temp['baseValue'] = array_shift($options); if (!empty($options)) { $temp['step'] = array_shift($options); } if (!empty($options)) { $temp['format'] = array_shift($options); } if (!empty($options)) { $temp['timezone'] = array_shift($options); } $options = $temp; } if (!isset($options['step'])) { $options['step'] = new DateInterval('P1D'); } if (!isset($options['timezone'])) { $options['timezone'] = new DateTimeZone(date_default_timezone_get()); } parent::__construct($options); }
/** * Set the list of items to white-list. * * @param array|Traversable $list */ public function setList($list = array()) { if (!is_array($list)) { $list = ArrayUtils::iteratorToArray($list); } $this->list = $list; }
/** * Constructor * * @param array|Traversable $options */ public function __construct($options = array()) { parent::__construct(); if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { $options = (array) $options; } foreach ($options as $key => $value) { switch (strtolower($key)) { case 'name': $this->setName($value); break; case 'salt': $this->setSalt($value); break; case 'session': $this->setSession($value); break; case 'timeout': $this->setTimeout($value); break; default: // ignore unknown options break; } } }
/** * @param array|\Traversable $options * @throws Exception\InvalidArgumentException * @return \Mail\Model\Template\Sendable */ public function prepare($options) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { throw new Exception\InvalidArgumentException('$options need to be an array ' . '(or instance of \\Traversable) in ' . __METHOD__); } if (empty($options['template'])) { throw new Exception\InvalidArgumentException('$options[template] is a required option in ' . __METHOD__); } $name = (string) $options['template']; unset($options['template']); if (empty($options['locale'])) { $locale = null; } else { $locale = (string) $options['locale']; unset($options['locale']); } $template = $this->getModel()->findByName($name, $locale); if (empty($template)) { throw new Exception\LogicException('"' . $name . '" named template is not found in ' . __METHOD__); } if (!empty($template->subject)) { $options['subject'] = (string) $template->subject; } if (!empty($template->fromAddress)) { $options['from'] = array($template->fromAddress => empty($template->fromName) ? $template->fromAddress : $template->fromName); } return new Sendable($this->getService(), $this->getSiteInfo(), $options, $template->bodyHtml, $template->bodyText); }
/** * Constructor * * @param array|Traversable $options */ function __construct($options = array()) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { throw new Exception\InvalidArgumentException('Invalid options provided'); } $auth = array( 'username' => $options[self::USERNAME], 'password' => $options[self::PASSWORD], 'appKey' => $options[self::APP_KEY], ); $nirvanix_options = array(); if (isset($options[self::HTTP_ADAPTER])) { $httpc = new HttpClient(); $httpc->setAdapter($options[self::HTTP_ADAPTER]); $nirvanix_options['httpClient'] = $httpc; } try { $this->_nirvanix = new NirvanixService($auth, $nirvanix_options); $this->_remoteDirectory = $options[self::REMOTE_DIRECTORY]; $this->_imfNs = $this->_nirvanix->getService('IMFS'); $this->_metadataNs = $this->_nirvanix->getService('Metadata'); } catch (\Zend\Service\Nirvanix\Exception $e) { throw new Exception\RuntimeException('Error on create: '.$e->getMessage(), $e->getCode(), $e); } }
/** * Class constructor * Available options * 'public' => public key * 'private' => private key * 'envelope' => envelope key * 'passphrase' => passphrase * 'compression' => compress value with this compression adapter * 'package' => pack envelope keys into encrypted string, simplifies decryption * * @param string|array|Traversable $options Options for this adapter * @throws Exception\ExtensionNotLoadedException */ public function __construct($options = array()) { if (!extension_loaded('openssl')) { throw new Exception\ExtensionNotLoadedException('This filter needs the openssl extension'); } if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { $options = array('public' => $options); } if (array_key_exists('passphrase', $options)) { $this->setPassphrase($options['passphrase']); unset($options['passphrase']); } if (array_key_exists('compression', $options)) { $this->setCompression($options['compression']); unset($options['compress']); } if (array_key_exists('package', $options)) { $this->setPackage($options['package']); unset($options['package']); } $this->_setKeys($options); }
/** * Constructor * * @param array|Traversable|int $options OPTIONAL */ public function __construct($options = null) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (!is_array($options)) { $options = func_get_args(); $temp = array(); if (!empty($options)) { $temp['type'] = array_shift($options); } $options = $temp; } if (is_array($options)) { if (!array_key_exists('type', $options)) { $detected = 0; $found = false; foreach ($options as $option) { if (in_array($option, $this->constants)) { $found = true; $detected += array_search($option, $this->constants); } } if ($found) { $options['type'] = $detected; } } } parent::__construct($options); }
/** * @param int|DateTime|array|Traversable $value DateTime instance or desired value based on $dateFormatChar * @param string $dateFormatChar PHP idate()-compliant format character * @param string $operator Comparison operator * @return Timestamp * @throws Exception\InvalidArgumentException */ public function __construct($value, $dateFormatChar = null, $operator = '<=') { if ($value instanceof Traversable) { $value = ArrayUtils::iteratorToArray($value); } if (is_array($value)) { $dateFormatChar = isset($value['dateFormatChar']) ? $value['dateFormatChar'] : null; $operator = isset($value['operator']) ? $value['operator'] : null; $value = isset($value['value']) ? $value['value'] : null; } if ($value instanceof DateTime) { $this->value = $value; } else { if (!is_int($value)) { throw new Exception\InvalidArgumentException(sprintf('Value must be either DateTime instance or integer; received "%s"', gettype($value))); } if (!is_string($dateFormatChar)) { throw new Exception\InvalidArgumentException(sprintf('Date format character must be supplied as string; received "%s"', gettype($dateFormatChar))); } $this->value = $value; $this->dateFormatChar = $dateFormatChar; } if ($operator === null) { $operator = '<='; } elseif (!in_array($operator, ['<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>'])) { throw new Exception\InvalidArgumentException("Unsupported comparison operator: '{$operator}'"); } $this->operator = $operator; }