示例#1
1
 public function forwardAction()
 {
     $alias = $this->params('alias');
     $instance = $this->getInstanceManager()->getInstanceFromRequest();
     try {
         $location = $this->aliasManager->findCanonicalAlias($alias, $instance);
         $this->redirect()->toUrl($location);
         $this->getResponse()->setStatusCode(301);
         return false;
     } catch (CanonicalUrlNotFoundException $e) {
     }
     try {
         $source = $this->aliasManager->findSourceByAlias($alias);
     } catch (AliasNotFoundException $e) {
         $this->getResponse()->setStatusCode(404);
         return false;
     }
     $router = $this->getServiceLocator()->get('Router');
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setUri($source);
     $routeMatch = $router->match($request);
     if ($routeMatch === null) {
         $this->getResponse()->setStatusCode(404);
         return false;
     }
     $this->getEvent()->setRouteMatch($routeMatch);
     $params = $routeMatch->getParams();
     $controller = $params['controller'];
     $return = $this->forward()->dispatch($controller, ArrayUtils::merge($params, ['forwarded' => true]));
     return $return;
 }
示例#2
1
 /**
  * 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__));
     }
 }
 public static function init()
 {
     // Load the user-defined test configuration file, if it exists; otherwise, load
     if (is_readable(__DIR__ . '/TestConfig.php')) {
         $testConfig = (include __DIR__ . '/TestConfig.php');
     } else {
         $testConfig = (include __DIR__ . '/TestConfig.php.dist');
     }
     $zf2ModulePaths = array();
     if (isset($testConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $testConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     static::$config = $config;
 }
示例#4
1
 /**
  * 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;
 }
示例#5
1
 /**
  * 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);
 }
示例#6
1
 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);
 }
 /**
  * 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 and return a NoRecordExists validator.
  *
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param null|array $options
  * @return NoRecordExists
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     if (isset($options['adapter'])) {
         return new NoRecordExists(ArrayUtils::merge($options, ['adapter' => $container->get($options['adapter'])]));
     }
     return new NoRecordExists($options);
 }
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return AdapterManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $config = $config['bsb_flysystem'];
     $serviceConfig = isset($config['adapter_manager']['config']) ? $config['adapter_manager']['config'] : [];
     $adapterMap = $this->adapterMap;
     if (isset($config['adapter_map'])) {
         $adapterMap = ArrayUtils::merge($this->adapterMap, $config['adapter_map']);
     }
     foreach ($config['adapters'] as $name => $adapterConfig) {
         if (!isset($adapterConfig['type'])) {
             throw new UnexpectedValueException(sprintf("Missing 'type' key for the adapter '%s' configuration", $name));
         }
         $type = strtolower($adapterConfig['type']);
         foreach (array_keys($adapterMap) as $serviceKind) {
             if (isset($adapterMap[$serviceKind][$type])) {
                 $serviceConfig[$serviceKind][$name] = $adapterMap[$serviceKind][$type];
                 if (isset($adapterConfig['shared'])) {
                     $serviceConfig['shared'][$name] = filter_var($adapterConfig['shared'], FILTER_VALIDATE_BOOLEAN);
                 }
                 continue 2;
             }
         }
         throw new UnexpectedValueException(sprintf("Unknown adapter type '%s'", $type));
     }
     $serviceConfig = new Config($serviceConfig);
     return new AdapterManager($serviceConfig);
 }
示例#10
0
 /**
  * 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];
     }
 }
示例#11
0
 /**
  * Set the data
  * @param array $data [description]
  */
 public function setData(array $data)
 {
     if (ArrayUtils::isHashTable($data)) {
         $data = array($data);
     }
     $this->data = $data;
 }
示例#12
0
 /**
  * @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;
 }
示例#13
0
    public function createModelFromConfigArrays(array $global, array $local)
    {
        $this->configWriter->toFile($this->globalConfigPath, $global);
        $this->configWriter->toFile($this->localConfigPath, $local);
        $mergedConfig = ArrayUtils::merge($global, $local);
        $globalConfig = new ConfigResource($mergedConfig, $this->globalConfigPath, $this->configWriter);
        $localConfig  = new ConfigResource($mergedConfig, $this->localConfigPath, $this->configWriter);


        $moduleEntity = $this->getMockBuilder('ZF\Apigility\Admin\Model\ModuleEntity')
                            ->disableOriginalConstructor()
                            ->getMock();

        $moduleEntity->expects($this->any())
                     ->method('getName')
                     ->will($this->returnValue('Foo'));

        $moduleEntity->expects($this->any())
                     ->method('getVersions')
                     ->will($this->returnValue(array(1,2)));

        $moduleModel = $this->getMockBuilder('ZF\Apigility\Admin\Model\ModuleModel')
                            ->disableOriginalConstructor()
                            ->getMock();

        $moduleModel->expects($this->any())
                    ->method('getModules')
                    ->will($this->returnValue(array('Foo' => $moduleEntity)));

        return new AuthenticationModel($globalConfig, $localConfig, $moduleModel);
    }
示例#14
0
 public static function init()
 {
     if (is_readable(__DIR__ . '/config.php')) {
         $testConfig = (include __DIR__ . '/config.php');
     } else {
         $testConfig = (include __DIR__ . '/config.php.dist');
     }
     $moduleName = pathinfo(realpath(dirname(__DIR__)), PATHINFO_BASENAME);
     if (defined('MODULE_NAME')) {
         $moduleName = MODULE_NAME;
     }
     $zf2ModulePaths = array(dirname(dirname(__DIR__)));
     if ($path = static::findParentPath('vendor')) {
         $modulePaths[] = $path;
     }
     if (($path = static::findParentPath('module')) !== $modulePaths[0]) {
         $modulePaths[] = $path;
     }
     if (isset($additionalModulePaths)) {
         $zf2ModulePaths = array_merge($modulePaths, $additionalModulePaths);
     } else {
         $zf2ModulePaths = $modulePaths;
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     static::initAutoloader();
     $baseConfig = ['module_listener_options' => ['module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)], 'modules' => [$moduleName]];
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
 }
示例#15
0
 /**
  * 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);
 }
 /**
  * Returns merged global, template-specific and given params
  *
  * @param string $template
  * @param array $params
  * @return array
  */
 private function mergeParams($template, array $params)
 {
     $globalDefaults = isset($this->defaultParams[TemplateRendererInterface::TEMPLATE_ALL]) ? $this->defaultParams[TemplateRendererInterface::TEMPLATE_ALL] : [];
     $templateDefaults = isset($this->defaultParams[$template]) ? $this->defaultParams[$template] : [];
     $defaults = ArrayUtils::merge($globalDefaults, $templateDefaults);
     return ArrayUtils::merge($defaults, $params);
 }
示例#17
0
 /**
  * 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']);
     }
 }
 public static function init()
 {
     // Load the user-defined test configuration file, if it exists; otherwise, load
     if (is_readable(__DIR__ . '/TestConfig.php')) {
         $testConfig = (include __DIR__ . '/TestConfig.php');
     } else {
         $testConfig = (include __DIR__ . '/TestConfig.php.dist');
     }
     $zf2ModulePaths = array();
     if (isset($testConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $testConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $application = \Zend\Mvc\Application::init($config);
     // build test database
     $entityManager = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
     static::$application = $application;
 }
示例#19
0
 /**
  * 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']);
 }
示例#20
0
 /**
  * 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;
 }
示例#21
0
 /**
  * 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);
 }
示例#22
0
文件: Sender.php 项目: gridguyz/core
 /**
  * @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);
 }
示例#23
0
文件: Csrf.php 项目: nuklehed/zf2
 /**
  * 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;
         }
     }
 }
示例#24
0
 /**
  * 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);
 }
示例#25
0
    /**
     * 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);
        }
    }
 public function getConfig()
 {
     $this->config = $this->getDefaultConfig(isset($this->config['RESTEssentials']) ? $this->config['RESTEssentials'] : array());
     $config = \Zend\Stdlib\ArrayUtils::merge(array('RESTEssentials' => $this->config), include __DIR__ . '/config/module.config.php');
     $config['doctrine']['driver']['Entity']['paths'][] = $this->config['EntityPath'];
     return $config;
 }
示例#27
0
 /**
  * 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);
 }
示例#28
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;
 }
示例#29
0
 /**
  * @param  FormInterface $form
  * @param  string        $redirect      Route or URL string (default: current route)
  * @param  bool          $redirectToUrl Use $redirect as a URL string (default: false)
  * @return Response
  */
 protected function handlePostRequest(FormInterface $form, $redirect, $redirectToUrl)
 {
     $container = $this->getSessionContainer();
     $request = $this->getController()->getRequest();
     $postFiles = $request->getFiles()->toArray();
     $postOther = $request->getPost()->toArray();
     $post = ArrayUtils::merge($postOther, $postFiles, true);
     // Fill form with the data first, collections may alter the form/filter structure
     $form->setData($post);
     // Change required flag to false for any previously uploaded files
     $inputFilter = $form->getInputFilter();
     $previousFiles = $container->files ?: array();
     $this->traverseInputs($inputFilter, $previousFiles, function ($input, $value) {
         if ($input instanceof FileInput) {
             $input->setRequired(false);
         }
         return $value;
     });
     // Run the form validations/filters and retrieve any errors
     $isValid = $form->isValid();
     $data = $form->getData(FormInterface::VALUES_AS_ARRAY);
     $errors = !$isValid ? $form->getMessages() : null;
     // Merge and replace previous files with new valid files
     $prevFileData = $this->getEmptyUploadData($inputFilter, $previousFiles);
     $newFileData = $this->getNonEmptyUploadData($inputFilter, $data);
     $postFiles = ArrayUtils::merge($prevFileData ?: array(), $newFileData ?: array(), true);
     $post = ArrayUtils::merge($postOther, $postFiles, true);
     // Save form data in session
     $container->setExpirationHops(1, array('post', 'errors', 'isValid'));
     $container->post = $post;
     $container->errors = $errors;
     $container->isValid = $isValid;
     $container->files = $postFiles;
     return $this->redirect($redirect, $redirectToUrl);
 }
 /**
  * @param ServiceLocatorInterface $validators
  * @return NoRecordExists
  */
 public function createService(ServiceLocatorInterface $validators)
 {
     if (isset($this->options['adapter'])) {
         return new NoRecordExists(ArrayUtils::merge($this->options, ['adapter' => $validators->getServiceLocator()->get($this->options['adapter'])]));
     }
     return new NoRecordExists($this->options);
 }