Exemplo n.º 1
0
 /**
  * @return void
  */
 public function setUp()
 {
     $iniReader = new Ini();
     $config = new Config($iniReader->fromFile('../../../local/config/vufind/config.ini'));
     $this->url = $config->get('Index')->get('url') . '/' . $config->get('Index')->get('default_core');
     $this->urlAdmin = $config->get('Index')->get('url') . '/admin';
 }
Exemplo n.º 2
0
 /**
  * @param Config $specs
  * @return boolean
  */
 private function isRemoved(Config $specs)
 {
     if ($remove = $specs->get('remove')) {
         return filter_var($remove, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * @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));
             }
         }
     }
 }
Exemplo n.º 4
0
 protected function buildHydrator($product, $direction)
 {
     $this->assertOptionsValid();
     $config = $this->options->getConfig();
     $class = $this->options->getClass();
     $hydrator = new ClassMethods();
     if (!isset($config[$this->options->getClass()][$product])) {
         return $hydrator;
     }
     $tmp = new Config(array());
     if (isset($config[$class]['*'])) {
         $tmp = new Config($config[$class]['*']);
     }
     if (isset($config[$class][$product])) {
         $productConfig = new Config($config[$class][$product]);
         $tmp = $productConfig->merge($tmp);
     }
     $config = $tmp['shared'];
     if (isset($tmp[$direction])) {
         $config->merge($tmp[$direction]);
     }
     $config = $config->toArray();
     if (!empty($config['map'])) {
         $hydrator->setNamingStrategy(new ArrayMapNamingStrategy($config['map']));
     }
     if (!empty($config['strategy'])) {
         foreach ($config['strategy'] as $name => $strategyCallback) {
             $hydrator->addStrategy($name, $strategyCallback());
         }
     }
     if (!empty($config['options'])) {
         $this->options->setFromArray($config['options']);
     }
     return $hydrator;
 }
Exemplo n.º 5
0
 protected function _getConfig()
 {
     $config = new Config(include 'config/module.config.global.php');
     if (file_exists('config/module.config.local.php')) {
         $config->merge(new Config(include 'config/module.config.local.php'));
     }
     return $config['jvandemo_ogone'];
 }
Exemplo n.º 6
0
 /**
  * Обновить запись.
  * Метод PUT для RESTfull.
  */
 public function update($id, $data)
 {
     $result = new JsonModel();
     $lincutConfigPath = $_SERVER["DOCUMENT_ROOT"] . "/lincut.config.php";
     // Создаем в памяти новый конфигурационный файл с новыми настройками
     $lincutConfigNew = new Config(array(), true);
     $lincutConfigNew->lincut = array();
     $lincutConfigNew->lincut->wkhtmltopdf = array();
     $lincutConfigNew->lincut->restriction = array();
     if (array_key_exists("wkhtmltopdf_path", $data)) {
         $lincutConfigNew->lincut->wkhtmltopdf->path = $data["wkhtmltopdf_path"];
     }
     if (array_key_exists("restriction_mode", $data)) {
         $lincutConfigNew->lincut->restriction->mode = $data["restriction_mode"];
     }
     if (array_key_exists("restriction_up_time", $data)) {
         $lincutConfigNew->lincut->restriction->uptime = $data["restriction_up_time"];
     }
     if (array_key_exists("restriction_up_count", $data)) {
         $lincutConfigNew->lincut->restriction->upcount = $data["restriction_up_count"];
     }
     if (array_key_exists("saw", $data)) {
         $lincutConfigNew->lincut->saw = $data["saw"];
     }
     if (array_key_exists("waste", $data)) {
         $lincutConfigNew->lincut->waste = $data["waste"];
     }
     $dbwcad = "db/wcad";
     $lincutConfigNew->db = array();
     $lincutConfigNew->db->adapters = array();
     $lincutConfigNew->db->adapters->{$dbwcad} = array();
     if (array_key_exists("db_wcad_servername", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->servername = $data["db_wcad_servername"];
     }
     if (array_key_exists("db_wcad_database", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->database = $data["db_wcad_database"];
     }
     if (array_key_exists("db_wcad_username", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->username = $data["db_wcad_username"];
     }
     if (array_key_exists("db_wcad_password", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->password = $data["db_wcad_password"];
     }
     // Открываем существующий файл настроек, если он имеется в наличии
     $lincutConfig = array();
     if (is_file($lincutConfigPath)) {
         $lincutConfig = \Zend\Config\Factory::fromFile($lincutConfigPath);
     }
     $lincutConfig = new Config($lincutConfig, true);
     $lincutConfig->merge($lincutConfigNew);
     // Сохраняем настройки
     $writer = new \Zend\Config\Writer\PhpArray();
     $writer->toFile($lincutConfigPath, $lincutConfig);
     // Возвращаем результат операции
     $result->success = true;
     return $result;
 }
Exemplo n.º 7
0
 /**
  * Process the whole config structure with each parser in the queue.
  *
  * @param  Config $config
  * @return Config
  * @throws Exception\InvalidArgumentException
  */
 public function process(Config $config)
 {
     if ($config->isReadOnly()) {
         throw new Exception\InvalidArgumentException('Cannot process config because it is read-only');
     }
     foreach ($this as $parser) {
         /** @var $parser ProcessorInterface */
         $parser->process($config);
     }
 }
Exemplo n.º 8
0
 /**
  * @inheritDoc
  */
 public function collect($handle, $area = null)
 {
     $areas = [LayoutUpdaterInterface::AREA_GLOBAL, $area];
     $structure = new Config([], true);
     foreach ($areas as $area) {
         $config = isset($this->config[$area][$handle]) ? (array) $this->config[$area][$handle] : [];
         $structure->merge(new Config($config, true));
     }
     return $structure;
 }
Exemplo n.º 9
0
Arquivo: Url.php Projeto: aubiplus/seo
 /**
  * @param String $string
  *
  * @return String
  * @author Fabian Köstring
  */
 private function convert(string $string)
 {
     if (!$this->config->offsetExists('chars')) {
         return $string;
     }
     $chars = $this->config->get('chars')->toArray();
     $from = array_keys($chars);
     $to = array_values($chars);
     return preg_replace($from, $to, $string);
 }
Exemplo n.º 10
0
 /**
  * Process
  *
  * @param  Config $config
  * @return Config
  * @throws InvalidArgumentException
  */
 public function process(Config $config)
 {
     $data = $config->toArray();
     array_walk_recursive($data, function (&$value, $key) {
         if (preg_match('/callable\\((.*)\\)/', $value, $matches)) {
             list($class, $method) = array_map('trim', explode(',', $matches[1]));
             $value = [new $class(), $method];
         }
     });
     return new Config($data, true);
 }
Exemplo n.º 11
0
 /**
  * Merges the app config with the siteaccess config
  */
 public function init()
 {
     // Add siteaccess specific config
     $configHandler = new Config($this->serviceManager->get('config'));
     $configHandler->merge($this->addConfig());
     $this->serviceManager->setAllowOverride(true);
     $this->serviceManager->setService('config', $configHandler->toArray());
     $this->serviceManager->setAllowOverride(false);
     // not needed I think
     #$this->baseXMSServices->setService( 'siteaccess', $this );
 }
Exemplo n.º 12
0
 /**
  * @return DocumentManager
  */
 public function getDocumentManager()
 {
     $factory = new DocumentManagerFactory();
     $sm = Bootstrap::getServiceManager();
     $sm->setAllowOverride(true);
     $config = $sm->get('Config');
     $c = new Config(['eoko' => ['odm' => ['hydrator' => ['class' => 'Zend\\Stdlib\\Hydrator\\ClassMethods', 'strategies' => ['Eoko\\ODM\\Metadata\\Annotation\\DateTime' => new DateTimeFormatterStrategy()]]]]]);
     $c->merge(new Config($config));
     $sm->setService('Config', $c->toArray());
     return $factory->createService($sm);
 }
 /**
  * Get result from cache or read from php file
  *
  * @param string $file path to file and filename
  * @param string $key template file ident
  * @param ServiceLocatorInterface $sl
  */
 protected function getFileAsConfig($file, $key, $sl)
 {
     $cache = $sl->get(static::CONTENTINUM_CACHE);
     if (!($result = $cache->getItem($key))) {
         $result = new Config(include $file);
         if (is_file(CON_ROOT_PATH . '/data/opt/customer.config.php')) {
             $result->merge(new Config(include CON_ROOT_PATH . '/data/opt/customer.config.php'));
         }
         $cache->setItem($key, $result);
     }
     return $result;
 }
Exemplo n.º 14
0
 /**
  * Get circuit breaker instance by command key for given command config
  *
  * @param string $commandKey
  * @param Config $commandConfig
  * @param CommandMetrics $metrics
  * @return CircuitBreakerInterface
  */
 public function get($commandKey, Config $commandConfig, CommandMetrics $metrics)
 {
     if (!isset($this->circuitBreakersByCommand[$commandKey])) {
         $circuitBreakerConfig = $commandConfig->get('circuitBreaker');
         if ($circuitBreakerConfig->get('enabled')) {
             $this->circuitBreakersByCommand[$commandKey] = new CircuitBreaker($commandKey, $metrics, $commandConfig, $this->stateStorage);
         } else {
             $this->circuitBreakersByCommand[$commandKey] = new NoOpCircuitBreaker();
         }
     }
     return $this->circuitBreakersByCommand[$commandKey];
 }
Exemplo n.º 15
0
 /**
  *
  * @throws \Exception
  * @return boolean
  */
 public function connect()
 {
     $this->session = ssh2_connect($this->config->host, $this->config->port);
     if (false === $this->session) {
         throw new \Exception("Echec de la connexion ssh " . print_r($this->config->toArray(), true));
     }
     $auth = ssh2_auth_pubkey_file($this->session, $this->config->username, $this->config->pubkeyfile, $this->config->privkeyfile);
     if (true !== $auth) {
         throw new \Exception("Echec de l'authentification ssh " . print_r($this->config->toArray(), true));
     }
     return true;
 }
Exemplo n.º 16
0
 /**
  * Get command metrics instance by command key for given command config
  *
  * @param string $commandKey
  * @param Config $commandConfig
  * @return CommandMetrics
  */
 public function get($commandKey, Config $commandConfig)
 {
     if (!isset($this->commandMetricsByCommand[$commandKey])) {
         $metricsConfig = $commandConfig->get('metrics');
         $statisticalWindow = $metricsConfig->get('rollingStatisticalWindowInMilliseconds');
         $windowBuckets = $metricsConfig->get('rollingStatisticalWindowBuckets');
         $snapshotInterval = $metricsConfig->get('healthSnapshotIntervalInMilliseconds');
         $counter = new MetricsCounter($commandKey, $this->stateStorage, $statisticalWindow, $windowBuckets);
         $this->commandMetricsByCommand[$commandKey] = new CommandMetrics($counter, $snapshotInterval);
     }
     return $this->commandMetricsByCommand[$commandKey];
 }
Exemplo n.º 17
0
 /**
  * Gets the config for given command key
  *
  * @param string $commandKey
  * @return Config
  */
 protected function getCommandConfig($commandKey)
 {
     if (isset($this->configsPerCommandKey[$commandKey])) {
         return $this->configsPerCommandKey[$commandKey];
     }
     $config = new Config($this->config->get('default')->toArray(), true);
     if ($this->config->__isset($commandKey)) {
         $commandConfig = $this->config->get($commandKey);
         $config->merge($commandConfig);
     }
     $this->configsPerCommandKey[$commandKey] = $config;
     return $config;
 }
Exemplo n.º 18
0
 private function generateConfigFile(Config $new_config)
 {
     $config_file = 'config/autoload/local.php';
     // If there is a config file at that path, so merge the configuration to it.
     $config = array();
     if (file_exists($config_file)) {
         $config = (include $config_file);
     }
     $reader = new Config($config);
     $reader->merge($new_config);
     $writer = new \Zend\Config\Writer\PhpArray();
     $writer->toFile($config_file, $reader);
 }
Exemplo n.º 19
0
 public static function setupConfig(Container $container)
 {
     $container->add('config', function () {
         $DS = DIRECTORY_SEPARATOR;
         $confPath = ROOT . $DS . 'conf' . $DS;
         $reader = new Ini();
         $config = new Config($reader->fromFile($confPath . 'default.ini'));
         if (file_exists($confPath . 'local.ini')) {
             $config->merge(new Config($reader->fromFile($confPath . 'local.ini')));
         }
         return $config;
     }, true);
 }
Exemplo n.º 20
0
 public function getConfig()
 {
     $config = new Config(array());
     if (is_dir(__DIR__ . '/config')) {
         $iterator = new \RegexIterator(new \DirectoryIterator(__DIR__ . '/config'), '#\\.config\\.php$#i');
         foreach ($iterator as $file) {
             /** @var $file \DirectoryIterator */
             if ($file->isReadable()) {
                 $subConf = new Config(include $file->getRealPath());
                 $config->merge($subConf);
             }
         }
     }
     return $config;
 }
Exemplo n.º 21
0
 public function init(ServiceLocatorInterface $serviceLocator)
 {
     $application = $serviceLocator->get('application');
     // Add siteaccess specific config
     $configHandler = new Config($application->getConfig());
     $configHandler->merge($this->addConfig());
     //TODO: avoid config in context of the siteaccess
     $this->config = $configHandler->toArray();
     $application->getServiceManager()->setService('accumulator', new Accumulator());
     $application->getServiceManager()->setFactory('xmldb', 'BaseXMS\\BaseXFactory');
     //TODO: remove all references to baseXMSServices
     $this->baseXMSServices = $application->getServiceManager();
     // not needed I think
     #$this->baseXMSServices->setService( 'siteaccess', $this );
 }
Exemplo n.º 22
0
 /**
  * @throws \ErrorException
  *
  * @return array
  */
 public function getNavigation()
 {
     try {
         $navigationDefinition = Factory::fromFile($this->rootNavigationFile, true);
     } catch (\Exception $e) {
         $navigationDefinition = new Config([]);
     }
     foreach ($this->navigationSchemaFinder->getSchemaFiles() as $moduleNavigationFile) {
         if (!file_exists($moduleNavigationFile->getPathname())) {
             throw new ErrorException('Navigation-File does not exist: ' . $moduleNavigationFile);
         }
         $configFromFile = Factory::fromFile($moduleNavigationFile->getPathname(), true);
         $navigationDefinition->merge($configFromFile);
     }
     return $navigationDefinition->toArray();
 }
Exemplo n.º 23
0
 /**
  * Process
  * 
  * @param  Config $config
  * @return Config
  * @throws Exception\InvalidArgumentException
  */
 public function process(Config $config)
 {
     if ($config->isReadOnly()) {
         throw new Exception\InvalidArgumentException('Cannot process config because it is read-only');
     }
     /**
      * Walk through config and replace values
      */
     foreach ($config as $key => $val) {
         if ($val instanceof Config) {
             $this->process($val);
         } else {
             $config->{$key} = $this->filter->filter($val);
         }
     }
     return $config;
 }
Exemplo n.º 24
0
 /**
  * Substitute defined variables, if any found and return the new configuration object
  *
  * @param Config $config
  * @param string $prefix
  * @param string $suffix
  * @return Config
  */
 protected function substituteVars(Config $config, $prefix = '{', $suffix = '}')
 {
     $arrayConfig = $config->toArray();
     if (isset($arrayConfig['variables'])) {
         $vars = array_map(function ($x) use($prefix, $suffix) {
             return $prefix . $x . $suffix;
         }, array_keys($arrayConfig['variables']));
         $vals = array_values($arrayConfig['variables']);
         $tokens = array_combine($vars, $vals);
         $processor = new Token();
         $processor->setTokens($tokens);
         $processor->process($config);
         // Remove variables node
         unset($config->variables);
     }
     return $config;
 }
 /**
  * Get result from cache or read from php file
  *
  * @param string $file path to file and filename
  * @param string $key template file ident
  * @param ServiceLocatorInterface $sl
  */
 protected function getFileAsConfig($file, $key, $sl)
 {
     $cache = $sl->get(static::CONTENTINUM_CACHE);
     if (!($result = $cache->getItem($key))) {
         $i = 1;
         foreach ($file as $singleFile) {
             if (1 === $i) {
                 $result = new Config(include $singleFile);
             } else {
                 $result->merge(new Config(include $singleFile));
             }
             $i++;
         }
         $cache->setItem($key, $result);
     }
     return $result;
 }
Exemplo n.º 26
0
 /**
  * Get target to be used for the client's IP range + sub domain
  *
  * @param String $overrideIP   Simulate request from given
  *                             instead of detecting real IP
  * @param String $overrideHost Simulate request from given
  *                             instead of detecting from real URL
  *
  * @return Boolean Target detected or not?
  */
 public function detectTarget($overrideIP = '', $overrideHost = '')
 {
     $this->targetKey = false;
     // Key of detected target config
     $this->targetApiId = false;
     $this->targetApiKey = false;
     $targetKeys = explode(',', $this->config->get('TargetsProxy')->get('targetKeys' . $this->searchClass));
     // Check whether the current IP address matches against any of the
     // configured targets' IP / sub domain patterns
     $ipAddress = !empty($overrideIP) ? $overrideIP : $this->getClientIpV4();
     if (empty($overrideHost)) {
         $url = $this->getClientUrl();
     } else {
         $url = new \Zend\Uri\Http();
         $url->setHost($overrideHost);
     }
     $IpMatcher = new IpMatcher();
     $UrlMatcher = new UrlMatcher();
     foreach ($targetKeys as $targetKey) {
         $isMatchingIP = false;
         $isMatchingUrl = false;
         /**
          * Config
          *
          * @var \Zend\Config\Config $targetConfig
          */
         $targetConfig = $this->config->get($targetKey);
         $patternsIP = '';
         $patternsURL = '';
         // Check match of IP address if any pattern configured.
         // If match is found, set corresponding keys and continue matching
         if ($targetConfig->offsetExists('patterns_ip')) {
             $patternsIP = $targetConfig->get('patterns_ip');
             if (!empty($patternsIP)) {
                 $targetPatternsIp = explode(',', $patternsIP);
                 $isMatchingIP = $IpMatcher->isMatching($ipAddress, $targetPatternsIp);
                 if ($isMatchingIP === true) {
                     $this->_setConfigKeys($targetKey);
                 }
             }
         }
         // Check match of URL hostname if any pattern configured.
         // If match is found, set corresponding keys and exit immediately
         if ($targetConfig->offsetExists('patterns_url')) {
             $patternsURL = $targetConfig->get('patterns_url');
             if (!empty($patternsURL)) {
                 $targetPatternsUrl = explode(',', $patternsURL);
                 $isMatchingUrl = $UrlMatcher->isMatching($url->getHost(), $targetPatternsUrl);
                 if ($isMatchingUrl === true) {
                     $this->_setConfigKeys($targetKey);
                     return true;
                 }
             }
         }
     }
     return $this->targetKey != "" ? true : false;
 }
Exemplo n.º 27
0
 /**
  * Whether the request is allowed
  *
  * @return boolean
  */
 public function allowRequest()
 {
     if ($this->config->get('circuitBreaker')->get('forceOpen')) {
         return false;
     }
     if ($this->config->get('circuitBreaker')->get('forceClosed')) {
         return true;
     }
     return !$this->isOpen() || $this->allowSingleTest();
 }
 /**
  * Get result from cache or read from php file
  *
  * @param string $file path to file and filename
  * @param string $key template file ident
  * @param ServiceLocatorInterface $sl            
  */
 protected function getFileAsConfig($dir, $key, $sl)
 {
     $cache = $sl->get(static::CONTENTINUM_CACHE);
     if (!($result = $cache->getItem($key))) {
         $i = 1;
         foreach (scandir($dir) as $file) {
             if ('.' != $file && '..' != $file) {
                 if (1 === $i) {
                     $result = new Config(include $dir . DS . $file);
                 } else {
                     $result->merge(new Config(include $dir . DS . $file));
                 }
                 $i++;
             }
         }
         $cache->setItem($key, $result);
     }
     return $result;
 }
Exemplo n.º 29
0
 /**
  * @throws InvalidArgumentException from sfYaml::load
  * @throws Zend_Config_Exception
  * @param string $filename
  * @param boolean $allowModifications
  */
 public function __construct($filename, $allowModifications = false)
 {
     $this->filename = $filename;
     $this->checkIfFilenameIsFile();
     $content = SymfonyYaml::load($this->filename);
     if (is_null($content)) {
         $content = array();
     }
     parent::__construct($content, $allowModifications);
 }
Exemplo n.º 30
0
 /**
  * getMergedConfig
  * Build a merged config object for all loaded modules
  * 
  * @return Zend\Config\Config
  */
 public function getMergedConfig($readOnly = true)
 {
     if (null === $this->mergedConfig) {
         $this->setMergedConfig(new Config(array(), true));
     }
     if (true === $readOnly) {
         $this->mergedConfig->setReadOnly();
     }
     return $this->mergedConfig;
 }