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; }
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; }
/** * 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); }
/** * 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); }
/** * Module ini function that import the current domain files or it's alias * * @param ModuleManager $moduleManager */ public function init(ModuleManager $moduleManager) { $events = $moduleManager->getEventManager(); $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, function (EventInterface $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); $domain = DomainService::getDomain(); $domainDir = null; if (!isset($config[$domain])) { if (isset($config['losdomain']['domain_dir'])) { $domainDir = $config['losdomain']['domain_dir']; $domainConfig = DomainOptions::importDomain($domainDir, $domain); $config = ArrayUtils::merge($config, $domainConfig); $configListener->setMergedConfig($config); } } if ($domainDir !== null && isset($config[$domain]) && array_key_exists('alias', $config[$domain])) { $alias = $config[$domain]['alias']; $aliasConfig = DomainOptions::importDomain($domainDir, $alias); $config[$domain] = $aliasConfig[$alias]; $config = ArrayUtils::merge($config, $aliasConfig); unset($config[$alias]); $configListener->setMergedConfig($config); } }); }
/** * Create service * * @param ServiceLocatorInterface $validators * @return mixed */ public function createService(ServiceLocatorInterface $validators) { if (isset($this->options['entity_class'])) { return new ObjectExists(ArrayUtils::merge($this->options, array('object_repository' => $validators->getServiceLocator()->get('Doctrine\\ORM\\EntityManager')->getRepository($this->options['entity_class'])))); } return new ObjectExists($this->options); }
/** * * @param \Zend\EventManager\Event $event */ public function onConfigMerge(ModuleEvent $event) { $config = $event->getConfigListener()->getMergedConfig(false); foreach ($config['sds']['doctrineExtensions']['manifest'] as $name => $manifestConfig) { if (!isset($manifestConfig['initalized']) || !$manifestConfig['initalized']) { $manifest = new Manifest($manifestConfig); $manifestConfig = $manifest->toArray(); $config['sds']['doctrineExtensions']['manifest'][$name] = $manifestConfig; //alias documentManager //add delegators $documentManagerConfig = $config; foreach (explode('.', $manifestConfig['document_manager']) as $key) { $documentManagerConfig = $documentManagerConfig[$key]; } $delegatorConfig = ['delegators' => [$manifestConfig['document_manager'] => ['doctrineExtensions.' . $name . '.documentManagerDelegatorFactory'], $documentManagerConfig['eventmanager'] => ['doctrineExtensions.' . $name . '.eventManagerDelegatorFactory'], $documentManagerConfig['configuration'] => ['doctrineExtensions.' . $name . '.configurationDelegatorFactory']]]; $config['service_manager'] = ArrayUtils::merge($config['service_manager'], $delegatorConfig); } } if (!isset($config['sds']['doctrineExtensions']['manifest']['default']) || !isset($config['sds']['doctrineExtensions']['manifest']['default']['extension_configs']['extension.dojo'])) { //remove dojo_src.default route if doctrineExtensions.dojo.default is not configured unset($config['router']['routes']['dojo.default']); } if (!isset($config['sds']['doctrineExtensions']['manifest']['default']) || !isset($config['sds']['doctrineExtensions']['manifest']['default']['extension_configs']['extension.rest'])) { //remove rest.default route if doctrineExtensions.rest.default is not configured unset($config['router']['routes']['rest.default']); } $event->getConfigListener()->setMergedConfig($config); }
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; }
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); }
/** * Start session * * if No session currently exists, attempt to start it. Calls * {@link isValid()} once session_start() is called, and raises an * exception if validation fails. * * @param bool $preserveStorage If set to true, current session storage will not be overwritten by the * contents of $_SESSION. * @return void * @throws Exception\RuntimeException */ public function start($preserveStorage = false) { if ($this->sessionExists()) { return; } $saveHandler = $this->getSaveHandler(); if ($saveHandler instanceof SaveHandler\SaveHandlerInterface) { // register the session handler with ext/session $this->registerSaveHandler($saveHandler); } $oldSessionData = array(); if (null !== $_SESSION) { $oldSessionData = $_SESSION; } if (session_status() === PHP_SESSION_NONE) { session_start(); } if ($oldSessionData instanceof \Traversable || is_array($oldSessionData) && 0 === count($oldSessionData)) { $_SESSION = ArrayUtils::merge($oldSessionData, $_SESSION, true); } $storage = $this->getStorage(); // Since session is starting, we need to potentially repopulate our // session storage if ($storage instanceof Storage\SessionStorage && $_SESSION !== $storage) { if (!$preserveStorage) { $storage->fromArray($_SESSION); } $_SESSION = $storage; } elseif ($storage instanceof Storage\StorageInitializationInterface) { $storage->init($_SESSION); } if (!$this->isValid()) { throw new Exception\RuntimeException('Session validation failed'); } }
/** * @inheritdoc */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $config = $container->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']); if (!in_array($type, array_keys($adapterMap['factories']), false)) { throw new UnexpectedValueException(sprintf("Unknown adapter type '%s'", $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); } } } } return new AdapterManager($container, $serviceConfig); }
/** * @see \Zend\Filter\FilterInterface::filter() * @param mixed $value * @return mixed Original value, if not a string, or an array of key/value pairs */ public function filter($value) { if (!is_string($value)) { return $value; } // check if the value provided resembles a query string $pairs = explode('&', $value); foreach ($pairs as $pair) { list($k, $v) = explode('=', $pair); // Check if we have a normal key-value pair if (!preg_match("/^(.*?)((\\[(.*?)\\])+)\$/m", $k, $m)) { $data[$k] = $v; continue; } // Array values $parts = explode('][', rtrim(ltrim($m[2], '['), ']')); $json = '{"' . implode('":{"', $parts) . '": ' . json_encode($v) . str_pad('', count($parts), '}'); if (isset($data[$m[1]])) { $data[$m[1]] = ArrayUtils::merge($data[$m[1]], $this->jsonFilter->filter($json)); continue; } $data[$m[1]] = $this->jsonFilter->filter($json); } return $data; }
public static function init() { // Load the user-defined test configuration file, if it exists; otherwise, load if (is_readable(__DIR__ . '/application.config.php')) { $testConfig = (include __DIR__ . '/application.config.php'); } else { $testConfig = (include __DIR__ . '/application.config.php.dist'); } chdir(__DIR__ . '/..'); $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(); $entityManager = $serviceManager->get('doctrine.entitymanager.orm_default'); $eventManager = $entityManager->getEventManager(); $eventManager->addEventSubscriber(new \Aaa\EntityEvents\PrePersistListener(null)); static::$eventManager = $eventManager; static::$serviceManager = $serviceManager; static::$config = $config; // static::createSchemaFromEntities(); }
/** * @param ModuleEvent $e * @throws InvalidArgumentException */ public function extendRoutes(ModuleEvent $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); // Allow extension of routes with overriding capability if (isset($config['router']['inheritance']) && is_array($config['router']['inheritance'])) { foreach ($config['router']['inheritance'] as $newRoute => $routeConfig) { // Not going to override any existing routes if (isset($config['router']['routes'][$newRoute])) { throw new InvalidArgumentException('Cannot extend route to existing route id.'); } // parent route must be provided if (!isset($routeConfig['extends'])) { throw new InvalidArgumentException('Parent route must be defined.'); } // parent route must exist if (!isset($config['router']['routes'][$routeConfig['extends']])) { throw new InvalidArgumentException('Parent route does not exist.'); } // If there is any configuration provided, it must be iterable if (isset($routeConfig['configuration']) && !is_array($routeConfig['configuration'])) { throw new InvalidArgumentException('Route overrides must be iterable.'); } // Copying the parent config and merging in the overrides $newRouteConfig = $config['router']['routes'][$routeConfig['extends']]; $newRouteConfig = ArrayUtils::merge($newRouteConfig, $routeConfig['configuration']); $config['router']['routes'][$newRoute] = $newRouteConfig; } // Removing this node so this isn't re-executed unset($config['router']['inheritance']); } // Pass the changed configuration back to the listener: $configListener->setMergedConfig($config); }
/** * Constructor * * Merges internal arrays with those passed via configuration, and also * defines: * * - factory for the service 'SharedEventManager'. * - initializer for EventManagerAwareInterface implementations * * @param array $config */ public function __construct(array $config = []) { $this->config['factories']['ServiceManager'] = function ($container) { return $container; }; $this->config['factories']['SharedEventManager'] = function () { return new SharedEventManager(); }; $this->config['initializers'] = ArrayUtils::merge($this->config['initializers'], ['EventManagerAwareInitializer' => function ($first, $second) { if ($first instanceof ContainerInterface) { $container = $first; $instance = $second; } else { $container = $second; $instance = $first; } if (!$instance instanceof EventManagerAwareInterface) { return; } $eventManager = $instance->getEventManager(); // If the instance has an EM WITH an SEM composed, do nothing. if ($eventManager instanceof EventManagerInterface && $eventManager->getSharedManager() instanceof SharedEventManagerInterface) { return; } $instance->setEventManager($container->get('EventManager')); }]); // In zend-servicemanager v2, incoming configuration is not merged // with existing; it replaces. So we need to detect that and merge. if (method_exists($this, 'getAllowOverride')) { $config = ArrayUtils::merge($this->config, $config); } parent::__construct($config); }
/** * Initialize bootstrap */ public static function init() { //No max execution time set_time_limit(0); static::initAutoloader(); //Load the user-defined test configuration file, if it exists; if (is_readable($sConfigPath = self::getTestDir() . '/TestConfig.php')) { $aTestConfig = (include $sConfigPath); } elseif (is_readable($sConfigDistPath = self::getTestDir() . '/TestConfig.php.dist')) { $aTestConfig = (include $sConfigDistPath); } else { throw new \LogicException('Config file ("' . $sConfigPath . '" or "' . $sConfigDistPath . '") does not exist'); } $aZf2ModulePaths = array(); if (isset($aTestConfig['module_listener_options']['module_paths'])) { foreach ($aTestConfig['module_listener_options']['module_paths'] as $sModulePath) { if ($sPath = static::findParentPath($sModulePath)) { $aZf2ModulePaths[] = $sPath; } } } //Add default configuration file if (file_exists($sDefaultConfigurationPath = __DIR__ . DIRECTORY_SEPARATOR . '../../default-configuration.php')) { if (isset($aTestConfig['module_listener_options']['config_glob_paths'])) { array_unshift($aTestConfig['module_listener_options']['config_glob_paths'], realpath($sDefaultConfigurationPath)); } else { $aTestConfig['module_listener_options']['config_glob_paths'] = array($sDefaultConfigurationPath); } } else { throw new \LogicException('Default configuration file ("' . $sDefaultConfigurationPath . '") does not exist'); } //Use ModuleManager to load this module and it's dependencies self::setApplicationConfig(\Zend\Stdlib\ArrayUtils::merge(array('module_listener_options' => array('module_paths' => array_merge($aZf2ModulePaths, explode(PATH_SEPARATOR, getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : ''))))), $aTestConfig)); }
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; }
public function __construct(array $configFiles) { // Load configuration from autoload path foreach ($configFiles as $file) { $this->config = ArrayUtils::merge($this->config, include $file); } }
/** * @param Config $helpers * @throws BadMethodCallException */ private function generateViewHelpers(Config $helpers) { foreach ($this->helperConfig as $helper => $config) { if (!$helpers->get($helper)) { continue; } $helperProxy = false; if (isset($config['proxy']) && $this->viewHelperManager->has($config['proxy'])) { $helperProxy = $this->viewHelperManager->get($config['proxy']); } $viewHelper = $this->viewHelperManager->get($helper); $instructions = $helpers[$helper]->toArray(); $sortedInstructions = $this->sort($instructions); foreach ($sortedInstructions as $id => $instruction) { if ($this->isRemoved($instruction)) { continue; } $mergedInstruction = ArrayUtils::merge($config, (array) $instruction); if ($this->isDebug() && isset($mergedInstruction['debug'])) { $mergedInstruction[$mergedInstruction['debug']]['data-layout-id'] = $id; } $method = isset($mergedInstruction['method']) ? $mergedInstruction['method'] : '__invoke'; $args = $this->filterArgs($mergedInstruction); if (method_exists($viewHelper, $method)) { $this->invokeArgs($viewHelper, $method, $args); } elseif (false !== $helperProxy && method_exists($helperProxy, $method)) { $this->invokeArgs($helperProxy, $method, $args); } else { throw new BadMethodCallException(sprintf('Call to undefined helper method %s::%s()', get_class($viewHelper), $method)); } } } }
public static function init() { $test_config = (include is_readable('TestConfig.php') ? 'TestConfig.php' : 'TestConfig.php.dist'); $test_config['module_listener_options']['config_cache_enabled'] = false; $test_config['module_listener_options']['module_map_cache_enabled'] = false; $zf2ModulePaths = array(); if (isset($test_config['module_listener_options']['module_paths'])) { $modulePaths = $test_config['module_listener_options']['module_paths']; foreach ($modulePaths as $modulePath) { $path = static::findParentPath($modulePath); if (false !== $path) { $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, $test_config); $serviceManager = new ServiceManager(new ServiceManagerConfig()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); static::$serviceManager = $serviceManager; static::$config = $config; }
/** * 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); }
/** * {@inheritDoc} * @return self */ public static function init($configuration = array()) { $defaults = array('module_listener_options' => array(), 'modules' => array(), 'service_manager' => array()); $configuration = ArrayUtils::merge($defaults, $configuration); $configuration['modules'][] = 'ZeffMu'; return parent::init($configuration); }
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; }
/** * @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); }
/** * @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 \ZF\Console\Route $route * @param ConsoleWriter $consoleWriter * @return Environment */ protected function loadEnvironment(Route $route, ConsoleWriter $consoleWriter) { $configPath = $route->getMatchedParam('config-file', getcwd() . DIRECTORY_SEPARATOR . 'processing.config.php'); $additionalConfig = $route->getMatchedParam('config', json_encode([])); $additionalConfig = json_decode($additionalConfig, true); if (is_null($additionalConfig)) { $consoleWriter->writeError("Provided config is not a valid json string"); $consoleWriter->writeError(json_last_error_msg()); return self::MESSAGE_PROCESSING_FAILED; } if (file_exists($configPath)) { $config = (include $configPath); $consoleWriter->writeInfo('Config loaded from ' . $configPath); } elseif (file_exists($configPath . '.dist')) { $config = (include $configPath . '.dist'); $consoleWriter->writeInfo('Config loaded from ' . $configPath); } else { $consoleWriter->writeInfo('No config file specified.'); if (empty($additionalConfig)) { $consoleWriter->writeInfo('Falling back to default config'); } else { $consoleWriter->writeInfo('Using config from argument'); } return $additionalConfig; } $config = ArrayUtils::merge($config, $additionalConfig); $env = Environment::setUp($config); $env->getEventStore()->getActionEventDispatcher()->attachListenerAggregate(new PersistedEventsConsoleWriter($consoleWriter)); return $env; }
/** * 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 ContainerInterface $container * @param string $requestedName * @param null|array $options * @return NoObjectExists */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { if (isset($options['entity_class'])) { $objectRepository = $container->get(EntityManager::class)->getRepository($options['entity_class']); $options = ArrayUtils::merge($options, ['object_repository' => $objectRepository]); } return new NoObjectExists($options); }
/** * Return and merge controller configuration for this module from the default location of * ./config/service/controller.config{,.*}php. * * @return array|\Traversable */ public function getControllerConfig() { $config = array(); foreach (glob($this->getDir() . '/config/service/controller.config{,.*}.php', GLOB_BRACE) as $configFile) { $config = ArrayUtils::merge($config, include $configFile); } return $config; }
/** * Merge configs from multiple config files * * @param array $sources * @return array */ public function merge(array $sources) { $config = []; foreach ($sources as $filename) { $config = ArrayUtils::merge($config, $this->getConfig($filename)); } return $config; }