Beispiel #1
0
 /**
  * Sets validator options
  *
  * @param  string|array|Traversable $options OPTIONAL
  * @return void
  */
 public function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     } elseif (!is_array($options)) {
         $options = func_get_args();
         $temp['format'] = array_shift($options);
         if (!empty($options)) {
             $temp['locale'] = array_shift($options);
         }
         $options = $temp;
     }
     if (array_key_exists('format', $options)) {
         $this->setFormat($options['format']);
     }
     if (!array_key_exists('locale', $options)) {
         if (Registry::isRegistered('Zend_Locale')) {
             $options['locale'] = Registry::get('Zend_Locale');
         }
     }
     if (array_key_exists('locale', $options)) {
         $this->setLocale($options['locale']);
     }
     parent::__construct($options);
 }
Beispiel #2
0
 /**
  * Sets validator options
  *
  * @param  null|string|Locale|array|Traversable $locale OPTIONAL
  * @return void
  */
 public function __construct($locale = null)
 {
     $options = array();
     if ($locale instanceof Traversable) {
         $locale = IteratorToArray::convert($locale);
     }
     if (is_array($locale)) {
         $options = $locale;
         if (array_key_exists('locale', $locale)) {
             $locale = $locale['locale'];
             unset($options['locale']);
         } else {
             $locale = null;
         }
     }
     if (empty($locale) && $locale !== false) {
         if (Registry::isRegistered('Zend_Locale')) {
             $locale = Registry::get('Zend_Locale');
         }
     }
     if ($locale !== null) {
         $this->setLocale($locale);
     }
     parent::__construct($options);
 }
Beispiel #3
0
 /**
  * Sets default option values for this instance
  *
  * @param  boolean $allowWhiteSpace
  * @return void
  */
 public function __construct($options = false)
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     } elseif (!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 (array_key_exists('unicodeEnabled', $options)) {
         $this->setUnicodeEnabled($options['unicodeEnabled']);
     }
     if (array_key_exists('allowWhiteSpace', $options)) {
         $this->setAllowWhiteSpace($options['allowWhiteSpace']);
     }
     if (!array_key_exists('locale', $options)) {
         $options['locale'] = null;
     }
     $this->setLocale($options['locale']);
 }
Beispiel #4
0
 /**
  * Serialize to JSON
  * 
  * @return string
  */
 public function serialize()
 {
     $variables = $this->getVariables();
     if ($variables instanceof Traversable) {
         $variables = IteratorToArray::convert($variables);
     }
     return json_encode($variables);
 }
 /**
  * Class constructor
  *
  * @param null|array|Traversable $options (Optional) Options to set
  */
 public function __construct($options = null)
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (is_array($options)) {
         $this->setOptions($options);
     }
 }
 /**
  * toString(): defined by Writer interface.
  *
  * @see    Writer::toString()
  * @param  mixed   $config
  * @return void
  */
 public function toString($config)
 {
     if ($config instanceof Traversable) {
         $config = IteratorToArray::convert($config);
     } elseif (!is_array($config)) {
         throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable config');
     }
     return $this->processConfig($config);
 }
Beispiel #7
0
 /**
  * Sets validator options
  *
  * @param  string|array|\Zend\Config\Config $compression
  * @return void
  */
 public function __construct($options = array())
 {
     // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
     $default = array('application/arj', 'application/gnutar', 'application/lha', 'application/lzx', 'application/vnd.ms-cab-compressed', 'application/x-ace-compressed', 'application/x-arc', 'application/x-archive', 'application/x-arj', 'application/x-bzip', 'application/x-bzip2', 'application/x-cab-compressed', 'application/x-compress', 'application/x-compressed', 'application/x-cpio', 'application/x-debian-package', 'application/x-eet', 'application/x-gzip', 'application/x-java-pack200', 'application/x-lha', 'application/x-lharc', 'application/x-lzh', 'application/x-lzma', 'application/x-lzx', 'application/x-rar', 'application/x-sit', 'application/x-stuffit', 'application/x-tar', 'application/zip', 'application/zoo', 'multipart/x-gzip');
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (empty($options)) {
         $options = array('mimeType' => $default);
     }
     parent::__construct($options);
 }
Beispiel #8
0
 /**
  * Sets validator options
  *
  * @param  string|array|Traversable $mimetype
  * @return void
  */
 public function __construct($options = array())
 {
     // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
     // http://www.iana.org/assignments/media-types/image/
     $default = array('application/cdf', 'application/dicom', 'application/fractals', 'application/postscript', 'application/vnd.hp-hpgl', 'application/vnd.oasis.opendocument.graphics', 'application/x-cdf', 'application/x-cmu-raster', 'application/x-ima', 'application/x-inventor', 'application/x-koan', 'application/x-portable-anymap', 'application/x-world-x-3dmf', 'image/bmp', 'image/c', 'image/cgm', 'image/fif', 'image/gif', 'image/jpeg', 'image/jpm', 'image/jpx', 'image/jp2', 'image/naplps', 'image/pjpeg', 'image/png', 'image/svg', 'image/svg+xml', 'image/tiff', 'image/vnd.adobe.photoshop', 'image/vnd.djvu', 'image/vnd.fpx', 'image/vnd.net-fpx', 'image/x-cmu-raster', 'image/x-cmx', 'image/x-coreldraw', 'image/x-cpi', 'image/x-emf', 'image/x-ico', 'image/x-icon', 'image/x-jg', 'image/x-ms-bmp', 'image/x-niff', 'image/x-pict', 'image/x-pcx', 'image/x-png', 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-greymap', 'image/x-portable-pixmap', 'image/x-quicktime', 'image/x-rgb', 'image/x-tiff', 'image/x-unknown', 'image/x-windows-bmp', 'image/x-xpmi');
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (empty($options)) {
         $options = array('mimeType' => $default);
     }
     parent::__construct($options);
 }
Beispiel #9
0
 /**
  * factory(): defined by Route interface.
  *
  * @see    Route::factory()
  * @param  array|Traversable $options
  * @return void
  */
 public static function factory($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     } elseif (!is_array($options)) {
         throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable set of options');
     }
     if (!isset($options['route'])) {
         throw new Exception\InvalidArgumentException('Missing "route" in options array');
     }
     if (!isset($options['defaults'])) {
         $options['defaults'] = array();
     }
     return new static($options['route'], $options['defaults']);
 }
Beispiel #10
0
 /**
  * Sets validator options
  *
  * @param  mixed $token
  * @return void
  */
 public function __construct($token = null)
 {
     if ($token instanceof Traversable) {
         $token = IteratorToArray::convert($token);
     }
     if (is_array($token) && array_key_exists('token', $token)) {
         if (array_key_exists('strict', $token)) {
             $this->setStrict($token['strict']);
         }
         $this->setToken($token['token']);
     } elseif (null !== $token) {
         $this->setToken($token);
     }
     parent::__construct(is_array($token) ? $token : null);
 }
 /**
  * Abstract constructor for all validators
  * A validator should accept following parameters:
  *  - nothing f.e. Validator()
  *  - one or multiple scalar values f.e. Validator($first, $second, $third)
  *  - an array f.e. Validator(array($first => 'first', $second => 'second', $third => 'third'))
  *  - an instance of Zend_Config f.e. Validator($config_instance)
  *
  * @param mixed $options
  */
 public function __construct($options = null)
 {
     // The abstract constructor allows no scalar values
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (isset($this->_messageTemplates)) {
         $this->abstractOptions['messageTemplates'] = $this->_messageTemplates;
     }
     if (isset($this->_messageVariables)) {
         $this->abstractOptions['messageVariables'] = $this->_messageVariables;
     }
     if (is_array($options)) {
         $this->setOptions($options);
     }
 }
Beispiel #12
0
 /**
  * factory(): defined by Route interface.
  *
  * @see    Route::factory()
  * @param  array|Traversable $options
  * @return void
  */
 public static function factory($options = array())
 {
     if (!is_array($options) && !$options instanceof Traversable) {
         throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable set of options');
     }
     // Convert options to array if Traversable object not implementing ArrayAccess
     if ($options instanceof Traversable && !$options instanceof ArrayAccess) {
         $options = IteratorToArray::convert($options);
     }
     if (!isset($options['scheme'])) {
         throw new Exception\InvalidArgumentException('Missing "scheme" in options array');
     }
     if (!isset($options['defaults'])) {
         $options['defaults'] = array();
     }
     return new static($options['scheme'], $options['defaults']);
 }
Beispiel #13
0
 /**
  * routeFromArray(): defined by SimpleRouteStack.
  *
  * @see    SimpleRouteStack::routeFromArray()
  * @param  array|Traversable $specs
  * @return Route
  */
 protected function routeFromArray($specs)
 {
     if ($specs instanceof Traversable) {
         $specs = IteratorToArray::convert($specs);
     } elseif (!is_array($specs)) {
         throw new Exception\InvalidArgumentException('Route definition must be an array or Traversable object');
     }
     $route = parent::routeFromArray($specs);
     if (!$route instanceof Route) {
         throw new Exception\RuntimeException('Given route does not implement HTTP route interface');
     }
     if (isset($specs['child_routes'])) {
         $options = array('route' => $route, 'may_terminate' => isset($specs['may_terminate']) && $specs['may_terminate'], 'child_routes' => $specs['child_routes'], 'route_broker' => $this->routeBroker);
         $route = $this->routeBroker->load('part', $options);
     }
     return $route;
 }
Beispiel #14
0
 /**
  * Instantiate a cache pattern
  *
  * @param  string|Pattern $patternName
  * @param  array|Traversable|Pattern\PatternOptions $options
  * @return Pattern
  * @throws Exception\RuntimeException
  */
 public static function factory($patternName, $options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (is_array($options)) {
         $options = new Pattern\PatternOptions($options);
     }
     if (!$options instanceof Pattern\PatternOptions) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects an array, Traversable object, or %s\\Pattern\\PatternOptions object; received "%s"', __METHOD__, __NAMESPACE__, is_object($options) ? get_class($options) : gettype($options)));
     }
     if ($patternName instanceof Pattern) {
         $patternName->setOptions($options);
         return $patternName;
     }
     $pattern = static::getBroker()->load($patternName);
     $pattern->setOptions($options);
     return $pattern;
 }
Beispiel #15
0
 /**
  * Nirvanix divides its service into namespaces, with each namespace
  * providing different functionality.  This is a factory method that
  * returns a preconfigured Context\Base proxy.
  *
  * @param  string  $namespace  Name of the namespace
  * @return Context\Base
  */
 public function getService($namespace, $options = array())
 {
     switch ($namespace) {
         case 'IMFS':
             $class = __NAMESPACE__ . '\\Context\\Imfs';
             break;
         default:
             $class = __NAMESPACE__ . '\\Context\\Base';
     }
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (!is_array($options)) {
         throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object of options');
     }
     $options['namespace'] = ucfirst($namespace);
     $options = array_merge($this->options, $options);
     return new $class($options);
 }
Beispiel #16
0
 /**
  * Constructor
  *
  * @param  array|Traversable $options
  * @return void
  */
 function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (!is_array($options) || empty($options)) {
         throw new Exception\InvalidArgumentException('Invalid options provided');
     }
     try {
         $this->rackspace = new RackspaceFile($options[self::USER], $options[self::API_KEY]);
     } catch (RackspaceException $e) {
         throw new Exception\RuntimeException('Error on create: ' . $e->getMessage(), $e->getCode(), $e);
     }
     if (isset($options[self::HTTP_ADAPTER])) {
         $this->rackspace->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]);
     }
     if (!empty($options[self::REMOTE_CONTAINER])) {
         $this->container = $options[self::REMOTE_CONTAINER];
     }
 }
Beispiel #17
0
 /**
  * Constructor
  *
  * @param string|array $callback Callback in a call_user_func format
  * @param mixed        $options  (Optional) Default options for this filter
  */
 public function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     } elseif (!is_array($options) || !array_key_exists('callback', $options)) {
         $options = func_get_args();
         $temp['callback'] = array_shift($options);
         if (!empty($options)) {
             $temp['options'] = array_shift($options);
         }
         $options = $temp;
     }
     if (!array_key_exists('callback', $options)) {
         throw new Exception\InvalidArgumentException('Missing callback to use');
     }
     $this->setCallback($options['callback']);
     if (array_key_exists('options', $options)) {
         $this->setOptions($options['options']);
     }
 }
Beispiel #18
0
 /**
  * Sets validator options
  *
  * @param  string|Traversable $pattern
  * @throws \Zend\Validator\Exception On missing 'pattern' parameter
  * @return void
  */
 public function __construct($pattern)
 {
     if (is_string($pattern)) {
         $this->setPattern($pattern);
         parent::__construct(array());
         return;
     }
     if ($pattern instanceof Traversable) {
         $pattern = IteratorToArray::convert($pattern);
     }
     if (!is_array($pattern)) {
         throw new Exception\InvalidArgumentException('Invalid options provided to constructor');
     }
     if (!array_key_exists('pattern', $pattern)) {
         throw new Exception\InvalidArgumentException("Missing option 'pattern'");
     }
     $this->setPattern($pattern['pattern']);
     unset($pattern['pattern']);
     parent::__construct($pattern);
 }
Beispiel #19
0
 /**
  * Class constructor.
  *
  * @param  $options  array  Options and dependency injection
  */
 public function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (!is_array($options)) {
         throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable of options');
     }
     if (isset($options['baseUrl'])) {
         $this->host = $options['baseUrl'];
     }
     if (isset($options['namespace'])) {
         $this->namespace = $options['namespace'];
     }
     if (isset($options['defaults'])) {
         $this->defaults = $options['defaults'];
     }
     if (!isset($options['httpClient'])) {
         $options['httpClient'] = new HttpClient();
     }
     $this->httpClient = $options['httpClient'];
 }
Beispiel #20
0
 /**
  * Constructor
  * Supported options are
  *     'match'   => matching pattern
  *     'replace' => replace with this
  *
  * @param  string|array $options
  * @return void
  */
 public function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     } elseif (!is_array($options)) {
         $options = func_get_args();
         $temp = array();
         if (!empty($options)) {
             $temp['match'] = array_shift($options);
         }
         if (!empty($options)) {
             $temp['replace'] = array_shift($options);
         }
         $options = $temp;
     }
     if (array_key_exists('match', $options)) {
         $this->setMatchPattern($options['match']);
     }
     if (array_key_exists('replace', $options)) {
         $this->setReplacement($options['replace']);
     }
 }
Beispiel #21
0
 /**
  * Constructor
  *
  * @param string|array|Traversable $type OPTIONAL Type of CCI to allow
  */
 public function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     } else {
         if (!is_array($options)) {
             $options = func_get_args();
             $temp['type'] = array_shift($options);
             if (!empty($options)) {
                 $temp['service'] = array_shift($options);
             }
             $options = $temp;
         }
     }
     if (!array_key_exists('type', $options)) {
         $options['type'] = self::ALL;
     }
     $this->setType($options['type']);
     unset($options['type']);
     if (array_key_exists('service', $options)) {
         $this->setService($options['service']);
         unset($options['service']);
     }
     parent::__construct($options);
 }
Beispiel #22
0
 /**
  * Set view variables en masse
  *
  * Can be an array or a Traversable + ArrayAccess object.
  * 
  * @param  array|ArrayAccess&Traversable $variables 
  * @return ViewModel
  */
 public function setVariables($variables)
 {
     // Assumption is that renderers can handle arrays or ArrayAccess objects
     if ($variables instanceof ArrayAccess && $variables instanceof Traversable) {
         $this->variables = $variables;
         return $this;
     }
     if ($variables instanceof Traversable) {
         $variables = IteratorToArray::convert($variables);
     }
     if (!is_array($variables)) {
         throw new Exception\InvalidArgumentException(sprintf('%s: expects an array, or Traversable ArrayAccess argument; received "%s"', __METHOD__, is_object($variables) ? get_class($variables) : gettype($variables)));
     }
     $this->variables = $variables;
     return $this;
 }
Beispiel #23
0
 protected function mergeTraversableConfig($config)
 {
     if ($config instanceof Traversable) {
         $config = IteratorToArray::convert($config);
     }
     if (!is_array($config)) {
         throw new Exception\InvalidArgumentException(sprintf('Config being merged must be an array, ' . 'implement the \\Traversable interface, or be an ' . 'instance of Zend\\Config\\Config. %s given.', gettype($config)));
     }
     $this->setMergedConfig(array_replace_recursive($this->mergedConfig, $config));
 }
Beispiel #24
0
 /**
  * Constructor
  *
  * $spec may be:
  * - string: name of element
  * - array: options with which to configure element
  * - Zend_Config: Zend_Config with options for configuring element
  *
  * @param  string|array|Config $spec
  * @param  array|Traversable $options
  * @return void
  * @throws ElementException if no element name after initialization
  */
 public function __construct($spec, $options = null)
 {
     if ($spec instanceof Traversable) {
         $spec = IteratorToArray::convert($spec);
     }
     if (is_string($spec)) {
         $this->setName($spec);
     } elseif (is_array($spec)) {
         $this->setOptions($spec);
     }
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (is_string($spec) && is_array($options)) {
         $this->setOptions($options);
     }
     if (null === $this->getName()) {
         throw new ElementException\UnexpectedValueException('Zend_Form_Element requires each element to have a name');
     }
     /**
      * Extensions
      */
     $this->init();
     /**
      * Register ViewHelper decorator by default
      */
     $this->loadDefaultDecorators();
 }
Beispiel #25
0
 /**
  * Constructor
  * @param array|Traversable $options
  * @return void
  */
 public function __construct($options = null)
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (is_array($options)) {
         $this->setOptions($options);
     }
     $this->type = strtolower(substr(get_class($this), strlen($this->rendererNamespace) + 1));
 }
Beispiel #26
0
 /**
  * Sets the page's reverse links to other pages
  *
  * This method expects an associative array of reverse links to other pages,
  * where each element's key is the name of the relation (e.g. alternate,
  * prev, next, help, etc), and the value is a mixed value that could somehow
  * be considered a page.
  *
  * @param  array|Traversable $relations [optional] an associative array of
  *                                      reverse links to other pages
  *
  * @return AbstractPage fluent interface, returns self
  */
 public function setRev($relations = null)
 {
     $this->rev = array();
     if (null !== $relations) {
         if ($relations instanceof Traversable) {
             $relations = IteratorToArray::convert($relations);
         }
         if (!is_array($relations)) {
             throw new Exception\InvalidArgumentException('Invalid argument: $relations must be an ' . 'array or an instance of Traversable');
         }
         foreach ($relations as $name => $relation) {
             if (is_string($name)) {
                 $this->rev[$name] = $relation;
             }
         }
     }
     return $this;
 }
Beispiel #27
0
 /**
  * Constructor
  *
  * @param  string $name
  * @param  PrefixPathMapper $loader
  * @param  array|Config $options
  * @return void
  */
 public function __construct($name, PrefixPathMapper $loader, $options = null)
 {
     $this->setName($name);
     $this->setPluginLoader($loader);
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (is_array($options)) {
         $this->setOptions($options);
     }
     // Extensions...
     $this->init();
     $this->loadDefaultDecorators();
 }
Beispiel #28
0
 /**
  * The storage factory
  * This can instantiate storage adapters and plugins.
  *
  * @param array|Traversable $cfg
  * @return Storage\Adapter
  * @throws Exception\InvalidArgumentException
  */
 public static function factory($cfg)
 {
     if ($cfg instanceof Traversable) {
         $cfg = IteratorToArray::convert($cfg);
     }
     if (!is_array($cfg)) {
         throw new Exception\InvalidArgumentException('The factory needs an associative array ' . 'or a Traversable object as an argument');
     }
     // instantiate the adapter
     if (!isset($cfg['adapter'])) {
         throw new Exception\InvalidArgumentException('Missing "adapter"');
     } elseif (is_array($cfg['adapter'])) {
         if (!isset($cfg['adapter']['name'])) {
             throw new Exception\InvalidArgumentException('Missing "adapter.name"');
         }
         $name = $cfg['adapter']['name'];
         $options = isset($cfg['adapter']['options']) ? $cfg['adapter']['options'] : array();
         $adapter = static::adapterFactory($name, $options);
     } else {
         $adapter = static::adapterFactory($cfg['adapter']);
     }
     // add plugins
     if (isset($cfg['plugins'])) {
         if (!is_array($cfg['plugins'])) {
             throw new Exception\InvalidArgumentException('Plugins needs to be an array');
         }
         foreach ($cfg['plugins'] as $k => $v) {
             if (is_string($k)) {
                 $name = $k;
                 if (!is_array($v)) {
                     throw new Exception\InvalidArgumentException("'plugins.{$k}' needs to be an array");
                 }
                 $options = $v;
             } elseif (is_array($v)) {
                 if (!isset($v['name'])) {
                     throw new Exception\InvalidArgumentException("Invalid plugins[{$k}] or missing plugins[{$k}].name");
                 }
                 $name = (string) $v['name'];
                 if (isset($v['options'])) {
                     $options = $v['options'];
                 } else {
                     $options = array();
                 }
             } else {
                 $name = $v;
                 $options = array();
             }
             $plugin = static::pluginFactory($name, $options);
             $adapter->addPlugin($plugin);
         }
     }
     // set adapter or plugin options
     if (isset($cfg['options'])) {
         if (!is_array($cfg['options']) && !$cfg['options'] instanceof Traversable) {
             throw new Exception\InvalidArgumentException('Options needs to be an array or Traversable object');
         }
         // Options at the top-level should be *merged* with existing options
         $options = $adapter->getOptions();
         foreach ($cfg['options'] as $key => $value) {
             $options->{$key} = $value;
         }
     }
     return $adapter;
 }
Beispiel #29
0
 /**
  * Sets a new adapter
  *
  * @param  array|Traversable $options Options to use
  * @throws Exception\InvalidArgumentException
  */
 public function setAdapter($options = array())
 {
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     } elseif (func_num_args() > 1) {
         $args = func_get_args();
         $options = array();
         $options['adapter'] = array_shift($args);
         if (!empty($args)) {
             $options['content'] = array_shift($args);
         }
         if (!empty($args)) {
             $options['locale'] = array_shift($args);
         }
         if (!empty($args)) {
             $opt = array_shift($args);
             $options = array_merge($opt, $options);
         }
     } elseif (!is_array($options)) {
         $options = array('adapter' => $options);
     }
     if (empty($options['adapter'])) {
         throw new Exception\InvalidArgumentException("No adapter given");
     }
     if (class_exists('Zend\\Translator\\Adapter\\' . ucfirst($options['adapter']))) {
         $options['adapter'] = 'Zend\\Translator\\Adapter\\' . ucfirst($options['adapter']);
     } elseif (!class_exists($options['adapter'])) {
         throw new Exception\InvalidArgumentException("Adapter " . $options['adapter'] . " does not exist and cannot be loaded");
     }
     if (array_key_exists('cache', $options)) {
         Adapter\AbstractAdapter::setCache($options['cache']);
     }
     $adapter = $options['adapter'];
     unset($options['adapter']);
     $this->_adapter = new $adapter($options);
     if (!$this->_adapter instanceof Adapter\AbstractAdapter) {
         throw new Exception\InvalidArgumentException("Adapter " . $adapter . " does not extend Zend\\Translator\\Adapter\\AbstractAdapter");
     }
 }
Beispiel #30
0
 /**
  * Constructor
  * @param array|Traversable $options
  * @return void
  */
 public function __construct($options = null)
 {
     $this->getDefaultOptions();
     $this->font = Barcode\Barcode::getBarcodeFont();
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (is_array($options)) {
         $this->setOptions($options);
     }
     $this->type = strtolower(substr(get_class($this), strlen($this->barcodeNamespace) + 1));
     if ($this->mandatoryChecksum) {
         $this->withChecksum = true;
         $this->withChecksumInText = true;
     }
 }