예제 #1
0
 /**
  * Defined by Zend\Validator\ValidatorInterface
  *
  * Returns true if all values validate true
  *
  * @param  mixed $value
  * @param  mixed $context Additional context
  * @return bool
  * @throws RuntimeException
  */
 public function isValid($value, $context = null)
 {
     $this->setValue($value);
     if ($value instanceof Traversable) {
         $value = ArrayUtils::iteratorToArray($value);
     }
     if (is_array($value)) {
         $values = $value;
     } elseif (is_string($value)) {
         $delimiter = $this->getValueDelimiter();
         // Skip explode if delimiter is null,
         // used when value is expected to be either an
         // array when multiple values and a string for
         // single values (ie. MultiCheckbox form behavior)
         $values = null !== $delimiter ? explode($this->valueDelimiter, $value) : array($value);
     } else {
         $values = array($value);
     }
     $validator = $this->getValidator();
     if (!$validator) {
         throw new RuntimeException(sprintf('%s expects a validator to be set; none given', __METHOD__));
     }
     foreach ($values as $value) {
         // provide context to validators isValid method
         if (!$validator->isValid($value, $context)) {
             $this->abstractOptions['messages'][] = $validator->getMessages();
             if ($this->isBreakOnFirstFailure()) {
                 return false;
             }
         }
     }
     return count($this->abstractOptions['messages']) == 0;
 }
예제 #2
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     if ($config instanceof Traversable) {
         $config = ArrayUtils::iteratorToArray($config);
     }
     return new TwitterInfoService($config['twitter']['cache_path']);
 }
예제 #3
0
 public function __construct($options = null)
 {
     $this->_config = new Config\Oauth2Config();
     if ($options !== null) {
         if ($options instanceof Traversable) {
             $options = ArrayUtils::iteratorToArray($options);
         }
         $this->_config->setOptions($options);
     }
 }
예제 #4
0
 public function __construct($options = null)
 {
     // The abstract constructor allows no scalar values
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (is_array($options)) {
         $this->setOptions($options);
     }
 }
예제 #5
0
 public function getIndexLocation()
 {
     // выборка конфигурации из конфигурационных данных модуля
     $config = $this->getServiceLocator()->get('config');
     if ($config instanceof Traversable) {
         $config = ArrayUtils::iteratorToArray($config);
     }
     if (!empty($config['module_config']['search_index'])) {
         return $config['module_config']['search_index'];
     } else {
         return FALSE;
     }
 }
 public function getFileUploadLocation()
 {
     // Fetch Configuration from Module Config
     $config = $this->getServiceLocator()->get('config');
     if ($config instanceof Traversable) {
         $config = ArrayUtils::iteratorToArray($config);
     }
     if (!empty($config['module_config']['image_upload_location'])) {
         return $config['module_config']['image_upload_location'];
     } else {
         return FALSE;
     }
 }
예제 #7
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     if ($config instanceof Traversable) {
         $config = ArrayUtils::iteratorToArray($config);
     }
     $config = $config['phpug']['notification']['transport'];
     $transport = $serviceLocator->get($config['class']);
     if (method_exists($transport, 'setOptions')) {
         $transportOptions = new $config['optionclass']($config['options']);
         $transport->setOptions($transportOptions);
     }
     return $transport;
 }
예제 #8
0
 public function __construct($options = null)
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (isset($options['data'])) {
         $this->setData($options['data']);
     }
     if (!array_key_exists('field', $options)) {
         throw new Exception\InvalidArgumentException("Missing option 'field'");
     }
     $this->setField($options['field']);
     parent::__construct($options);
 }
예제 #9
0
 /**
  * {@inheritDoc}
  */
 public function setValue($value)
 {
     if ($this->isMultiple()) {
         if ($value instanceof \Traversable) {
             $value = ArrayUtils::iteratorToArray($value);
         } elseif (!$value) {
             return parent::setValue([]);
         } elseif (!is_array($value)) {
             $value = (array) $value;
         }
         return parent::setValue(array_map(Locale::class . '::canonicalize', $value));
     }
     return parent::setValue(Locale::canonicalize($value));
 }
예제 #10
0
 /**
  * Constructor for the integer validator
  *
  * @param string|Zend_Locale $locale
  */
 public function __construct($options = [])
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (array_key_exists('locale', $options)) {
         $this->setLocale($options['locale']);
     } else {
         if (Zend_Registry::isRegistered('Zend_Locale')) {
             $locale = Zend_Registry::get('Zend_Locale');
             $this->setLocale($locale);
         }
     }
     parent::__construct($options);
 }
예제 #11
0
파일: Api.php 프로젝트: carnage/mailchimp
 /**
  * Set configuration parameters for this Api caller
  *
  * @param  array|Traversable $options
  * @return Api
  * @throws \Exception
  */
 public function setOptions($options = array())
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (!is_array($options)) {
         throw new \Exception('Config parameter is not valid');
     }
     /** Config Key Normalization */
     foreach ($options as $k => $v) {
         $this->config[str_replace(array('-', '_', ' ', '.'), '', strtolower($k))] = $v;
         // replace w/ normalized
     }
     return $this;
 }
예제 #12
0
 /**
  * @param array $options
  * @param array $extends
  */
 public function __construct($options = array(), $extends = array())
 {
     // The abstract constructor allows no scalar values
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (!empty($extends)) {
         if ($extends instanceof Traversable) {
             $extends = ArrayUtils::iteratorToArray($extends);
         }
         $this->extends = array_intersect_key($options, $extends);
     }
     if (is_array($options)) {
         $this->setOptions($options);
     }
 }
예제 #13
0
파일: Number.php 프로젝트: coolms/common
 /**
  * {@inheritDoc}
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (isset($options['max'])) {
         $this->setMax($options['max']);
     }
     if (isset($options['min'])) {
         $this->setMin($options['min']);
     }
     if (isset($options['step'])) {
         $this->setStep($options['step']);
     }
 }
예제 #14
0
 public function setOptions($options)
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     } elseif (!is_array($options)) {
         throw new InvalidArgumentException('The options parameter must be an array or a Traversable');
     }
     if (isset($options['queryMap'])) {
         $this->setQueryMap($options['queryMap']);
     }
     if (isset($options["namespaces"])) {
         $this->setNamespaces($options["namespaces"]);
     }
     if (isset($options["xpath"])) {
         $this->setXPath($options["xpath"]);
     }
     return $this;
 }
예제 #15
0
파일: Module.php 프로젝트: jonsource/zf2wp
 public function getServiceConfig()
 {
     return array('factories' => array('wpdbManager' => function ($sm) {
         $config = $sm->get('config');
         if ($config instanceof Traversable) {
             $config = ArrayUtils::iteratorToArray($config);
         }
         /* process wp settings for wp native calls */
         if (isset($config['wp_config']['wp_debug'])) {
             define('WP_DEBUG', $config['wp_config']['wp_debug']);
         } else {
             define('WP_DEBUG', false);
         }
         $wpdbm = new Service\WpdbManager();
         $wpdbm->setServiceManager($sm);
         $wpdbm->setDatabase($config['wp_config']);
         return $wpdbm;
     }));
 }
예제 #16
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $log = new Logger('default');
     $config = $serviceLocator->get('config');
     if ($config instanceof Traversable) {
         $config = ArrayUtils::iteratorToArray($config);
     }
     foreach ($config['php.ug.log'] as $writer) {
         switch (strtolower($writer['handler'])) {
             case 'rotatingfile':
                 $handler = new Handler\RotatingFileHandler($writer['location'], $writer['maxFiles'], $writer['level']);
                 break;
             default:
                 $handler = new Handler\StreamHandler($writer['location'], $writer['level']);
                 break;
         }
         $log->pushHandler($handler);
     }
     return $log;
 }
    /**
     * Constructor for the PhoneNumber validator
     *
     * Options
     * - country | string | field or value
     * - allowed_types | array | array of allowed types
     * - allow_possible | boolean | allow possible matches aka non-strict
     *
     * @param array|Traversable $options
     */
    public function __construct($options = array())
    {
        if ($options instanceof Traversable) {
            $options = ArrayUtils::iteratorToArray($options);
        }

        if (array_key_exists('country', $options)) {
            $this->setCountry($options['country']);
        }

        if (array_key_exists('allowed_types', $options)) {
            $this->allowedTypes($options['allowed_types']);
        }

        if (array_key_exists('allow_possible', $options)) {
            $this->allowPossible($options['allow_possible']);
        }

        parent::__construct($options);
    }
예제 #18
0
 /**
  * Obtain a minifier instance.
  *
  * @param array|Traversable $cfg
  * @return MinifyInterface
  */
 public static function factory($cfg = array())
 {
     $options = array('tool' => 'unify', 'options' => array());
     if ($cfg instanceof Traversable) {
         $cfg = ArrayUtils::iteratorToArray($cfg);
     }
     if (!is_array($cfg)) {
         throw new Exception\InvalidArgument('The factory needs an associative array or a Traversable object as an argument');
     }
     $cfg = Stdlib\ArrayUtils::arrayMergeRecursiveRight($options, $cfg);
     if (class_exists($cfg['tool'])) {
         $class = $cfg['tool'];
     } else {
         $class = '\\Athem\\Code';
         if (isset($cfg['code'])) {
             $class .= '\\' . ucfirst($cfg['code']) . '\\Compiler';
         }
         $class .= '\\' . ucfirst($cfg['tool']);
     }
     return isset($cfg['compiler']) ? new $class(self::factory($cfg['compiler']), $cfg['options']) : new $class($cfg['options']);
 }
예제 #19
0
 /**
  * Factory for Zend_Navigation_Page classes
  *
  * A specific type to construct can be specified by specifying the key
  * 'type' in $options. If type is 'uri' or 'mvc', the type will be resolved
  * to Zend_Navigation_Page_Uri or Zend_Navigation_Page_Mvc. Any other value
  * for 'type' will be considered the full name of the class to construct.
  * A valid custom page class must extend Zend_Navigation_Page.
  *
  * If 'type' is not given, the type of page to construct will be determined
  * by the following rules:
  * - If $options contains either of the keys 'action', 'controller',
  *   or 'route', a Zend_Navigation_Page_Mvc page will be created.
  * - If $options contains the key 'uri', a Zend_Navigation_Page_Uri page
  *   will be created.
  *
  * @param  array|Traversable $options  options used for creating page
  * @return AbstractPage  a page instance
  * @throws Exception\InvalidArgumentException if $options is not
  *                                            array/Traversable
  * @throws Exception\InvalidArgumentException if 'type' is specified
  *                                            but class not found
  * @throws Exception\InvalidArgumentException if something goes wrong
  *                                            during instantiation of
  *                                            the page
  * @throws Exception\InvalidArgumentException if 'type' is given, and
  *                                            the specified type does
  *                                            not extend this class
  * @throws Exception\InvalidArgumentException if unable to determine
  *                                            which class to instantiate
  */
 public static function factory($options)
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (!is_array($options)) {
         throw new Exception\InvalidArgumentException('Invalid argument: $options must be an array or Traversable');
     }
     if (isset($options['type'])) {
         $type = $options['type'];
         if (is_string($type) && !empty($type)) {
             switch (strtolower($type)) {
                 case 'mvc':
                     $type = 'Zend\\Navigation\\Page\\Mvc';
                     break;
                 case 'uri':
                     $type = 'Zend\\Navigation\\Page\\Uri';
                     break;
             }
             if (!class_exists($type, true)) {
                 throw new Exception\InvalidArgumentException('Cannot find class ' . $type);
             }
             $page = new $type($options);
             if (!$page instanceof self) {
                 throw new Exception\InvalidArgumentException(sprintf('Invalid argument: Detected type "%s", which ' . 'is not an instance of Zend\\Navigation\\Page', $type));
             }
             return $page;
         }
     }
     $hasUri = isset($options['uri']);
     $hasMvc = isset($options['action']) || isset($options['controller']) || isset($options['route']);
     if ($hasMvc) {
         return new Mvc($options);
     } elseif ($hasUri) {
         return new Uri($options);
     } else {
         throw new Exception\InvalidArgumentException('Invalid argument: Unable to determine class to instantiate');
     }
 }
예제 #20
0
 /**
  * factory(): defined by RouteInterface interface.
  *
  * @see    \Zend\Mvc\Router\RouteInterface::factory()
  * @param  array|Traversable $options
  * @return XelaxAdmin
  * @throws Exception\InvalidArgumentException
  */
 public static function factory($options = array())
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     } elseif (!is_array($options)) {
         throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable set of options');
     }
     if (!isset($options['controller_options_name'])) {
         throw new Exception\InvalidArgumentException('Missing "controller_options_name" in options array');
     }
     return new static($options['controller_options_name']);
 }
예제 #21
0
    /**
     * Constructor
     * 
     * @param  array $options 
     * @return void
     */
    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 uknown options
                    break;
            }
        }
    }
예제 #22
0
파일: Element.php 프로젝트: SYallin/wpframe
 /**
  * Set options for an element. Accepted options are:
  * - label: label to associate with the element
  * - label_attributes: attributes to use when the label is rendered
  * - label_options: label specific options
  *
  * @param  array|Traversable $options
  * @return Element|ElementInterface
  * @throws Exception\InvalidArgumentException
  */
 public function setOptions($options)
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     } elseif (!is_array($options)) {
         throw new Exception\InvalidArgumentException('The options parameter must be an array or a Traversable');
     }
     if (isset($options['label'])) {
         $this->setLabel($options['label']);
     }
     if (isset($options['label_attributes'])) {
         $this->setLabelAttributes($options['label_attributes']);
     }
     if (isset($options['label_options'])) {
         $this->setLabelOptions($options['label_options']);
     }
     $this->options = $options;
     return $this;
 }
예제 #23
0
 /**
  * Set view variables en masse
  *
  * Can be an array or a Traversable + ArrayAccess object.
  *
  * @param  array|ArrayAccess|Traversable $variables
  * @param  bool $overwrite Whether or not to overwrite the internal container with $variables
  * @throws \InvalidArgumentException
  * @return self
  */
 public function setVariables($variables, $overwrite = false)
 {
     if (!is_array($variables) && !$variables instanceof Traversable) {
         throw \InvalidArgumentException(sprintf('%s: expects an array, or Traversable argument; received "%s"', __METHOD__, is_object($variables) ? get_class($variables) : gettype($variables)));
     }
     if ($overwrite) {
         if (is_object($variables) && !$variables instanceof ArrayAccess) {
             $variables = ArrayUtils::iteratorToArray($variables);
         }
         $this->variables = $variables;
         return $this;
     }
     foreach ($variables as $key => $value) {
         $this->setVariable($key, $value);
     }
     return $this;
 }
예제 #24
0
 /**
  * routeFromArray(): defined by SimpleRouteStack.
  *
  * @see    SimpleRouteStack::routeFromArray()
  * @param  string|array|Traversable $specs
  * @return RouteInterface
  * @throws Exception\InvalidArgumentException When route definition is not an array nor traversable
  * @throws Exception\InvalidArgumentException When chain routes are not an array nor traversable
  * @throws Exception\RuntimeException         When a generated routes does not implement the HTTP route interface
  */
 protected function routeFromArray($specs)
 {
     if (is_string($specs)) {
         if (null === ($route = $this->getPrototype($specs))) {
             throw new Exception\RuntimeException(sprintf('Could not find prototype with name %s', $specs));
         }
         return $route;
     } elseif ($specs instanceof Traversable) {
         $specs = ArrayUtils::iteratorToArray($specs);
     } elseif (!is_array($specs)) {
         throw new Exception\InvalidArgumentException('Route definition must be an array or Traversable object');
     }
     if (isset($specs['controller_routes'])) {
         $ctrlRoutes = $specs['controller_routes'];
         if ($ctrlRoutes instanceof Traversable) {
             $ctrlRoutes = ArrayUtils::iteratorToArray($ctrlRoutes);
         } elseif (!is_array($ctrlRoutes)) {
             throw new Exception\InvalidArgumentException('Controller routes must be an array or Traversable object');
         }
         if (!isset($ctrlRoutes['model_route']) || !is_array($ctrlRoutes['model_route']) && !$ctrlRoutes['model_route'] instanceof Traversable) {
             throw new Exception\InvalidArgumentException('Controller routes must have a \'model_route\' key as an array or Traversable object');
         } elseif ($ctrlRoutes['model_route'] instanceof Traversable) {
             $ctrlRoutes['model_route'] = ArrayUtils::iteratorToArray($ctrlRoutes['model_route']);
         }
         if (!isset($ctrlRoutes['controllers']) || !is_array($ctrlRoutes['controllers']) && !$ctrlRoutes['controllers'] instanceof Traversable) {
             throw new Exception\InvalidArgumentException('Controller routes must have a \'controllers\' key as an array or Traversable object');
         } elseif ($ctrlRoutes['model_route'] instanceof Traversable) {
             $ctrlRoutes['controllers'] = ArrayUtils::iteratorToArray($ctrlRoutes['controllers']);
         }
         $modelRoute = $ctrlRoutes['model_route'];
         $controllers = $ctrlRoutes['controllers'];
         foreach ($controllers as $ctrlName) {
             $route = $modelRoute;
             $route['options']['defaults']['controller'] = $ctrlName;
             $route['options']['route'] = str_replace(':controller', $ctrlName, $route['options']['route']);
             $specs['child_routes'][$ctrlName] = $route;
         }
         unset($specs['controller_routes']);
     }
     if (isset($specs['chain_routes'])) {
         if (!is_array($specs['chain_routes'])) {
             throw new Exception\InvalidArgumentException('Chain routes must be an array or Traversable object');
         }
         $chainRoutes = array_merge([$specs], $specs['chain_routes']);
         unset($chainRoutes[0]['chain_routes']);
         if (isset($specs['child_routes'])) {
             unset($chainRoutes[0]['child_routes']);
         }
         $options = ['routes' => $chainRoutes, 'route_plugins' => $this->routePluginManager, 'prototypes' => $this->prototypes];
         $route = $this->routePluginManager->get('chain', $options);
     } else {
         $route = SimpleRouteStack::routeFromArray($specs);
     }
     if (!$route instanceof RouteInterface) {
         throw new Exception\RuntimeException('Given route does not implement HTTP route interface');
     }
     if (isset($specs['child_routes'])) {
         $options = ['route' => $route, 'may_terminate' => isset($specs['may_terminate']) && $specs['may_terminate'], 'child_routes' => $specs['child_routes'], 'route_plugins' => $this->routePluginManager, 'prototypes' => $this->prototypes];
         $priority = isset($route->priority) ? $route->priority : null;
         $route = $this->routePluginManager->get('part', $options);
         $route->priority = $priority;
     }
     return $route;
 }