php Zend-Config-Factory类(方法)实例源码

下面列出了php Zend-Config-Factory 类(方法)源码代码实例,从而了解它的用法。

作者:michaelyin    项目:Modern-Toolki   
/**
  * Overwrite execute to override the default config file.
  *
  * If an alternative configuration file is provided we override the 'config'
  * element in the Dependency Injection Container with a new instance. This
  * new instance uses the phpdoc.tpl.xml as base configuration and applies
  * the given configuration on top of it.
  *
  * Also, upon providing a custom configuration file, is the current working
  * directory set to the directory containing the configuration file so that
  * all relative paths for directory and file selections (and more) is based
  * on that location.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config_file = $input->getOption('config');
     if ($config_file && $config_file !== 'none') {
         $config_file = realpath($config_file);
         // all relative paths mentioned in the configuration file should
         // be relative to the configuration file.
         // This means that if we provide an alternate configuration file
         // that we need to go to that directory first so that paths can be
         // calculated from there.
         chdir(dirname($config_file));
     }
     if ($config_file) {
         $container = $this->getContainer();
         $container['config'] = $container->share(function () use($config_file) {
             $files = array(__DIR__ . '/../../../data/phpdoc.tpl.xml');
             if ($config_file !== 'none') {
                 $files[] = $config_file;
             }
             return \Zend\Config\Factory::fromFiles($files, true);
         });
         if (isset($container['config']->logging)) {
             $level = (string) $container['config']->logging->level;
             // null means the default is used
             $logPath = isset($container['config']->logging->paths->default) ? (string) $container['config']->logging->paths->default : null;
             // null means the default is used
             $debugPath = isset($container['config']->logging->paths->errors) ? (string) $container['config']->logging->paths->errors : null;
             $container->configureLogger($container['monolog'], $level, $logPath, $debugPath);
         }
     }
 }

作者:seyfe    项目:zend2-tutorial.m   
private function loadDbConfig()
 {
     $dbConfigLocal = \Zend\Config\Factory::fromFile(__DIR__ . '/../../../../../config/autoload/local.php')['db'];
     $dbConfigGlobal = \Zend\Config\Factory::fromFile(__DIR__ . '/../../../../../config/autoload/global.php')['db'];
     $dbConfig = array_merge($dbConfigLocal, $dbConfigGlobal);
     return $dbConfig;
 }

作者:pgiacomett    项目:zf2rapi   
/**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // load autoload configuration from project
     $config = ConfigFactory::fromFiles(glob($this->params->projectConfigDir . '/autoload/{,*.}{global,development,local}.php', GLOB_BRACE));
     // check for db config
     if (empty($config) || !isset($config['db'])) {
         $this->console->writeFailLine('task_crud_check_db_connection_no_config');
         return 1;
     }
     // create db adapter instance
     try {
         $dbAdapter = new Adapter($config['db']);
     } catch (InvalidArgumentException $e) {
         $this->console->writeFailLine('task_crud_check_db_connection_config_inconsistent');
         return 1;
     }
     // connect to database
     try {
         $connection = $dbAdapter->getDriver()->getConnection()->connect();
     } catch (RuntimeException $e) {
         $this->console->writeFailLine('task_crud_check_db_connection_failed');
         return 1;
     }
     $this->params->dbAdapter = $dbAdapter;
     return 0;
 }

作者:fsvxavie    项目:citywar   
public function __construct()
 {
     /* Acesso o arquivo de configuração global */
     $this->globalConfig = \Zend\Config\Factory::fromFile(GLOBAL_CONFIG_PATH . 'global.php');
     $this->getViewModel();
     $this->globalRoute = $this->getSessionAdapter('globalRoute');
     $this->module = $this->sessionAdapter->moduleName;
     $this->controller = $this->sessionAdapter->controllerName;
     $this->action = $this->sessionAdapter->actionName;
     //$this->image = $this->globalConfig['image'];
     $this->assign('linkDefault', LINK_DEFAULT);
     $this->assign('linkModule', LINK_DEFAULT . $this->module . '/');
     $this->assign('linkController', LINK_DEFAULT . $this->module . '/' . strtolower($this->controller));
     $this->assign('linkAction', LINK_DEFAULT . $this->module . '/' . strtolower($this->controller) . '/' . strtolower($this->action));
     $this->assign('urlDefault', URL_DEFAULT);
     $this->assign('urlUpload', URL_UPLOAD);
     $this->assign('urlStatic', URL_STATIC);
     $this->assign('publicPath', PUBLIC_PATH);
     $this->assign('baseModule', $this->module);
     $this->assign('baseController', $this->controller);
     $this->assign('baseAction', $this->action);
     $this->assign('langDefault', $this->sessionAdapter->language);
     /* Tratamento das variáveis padrões de modulo, controlador e action */
     $eventManager = $this->getEventManager();
     $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_DISPATCH, function (\Zend\Mvc\MvcEvent $e) {
         $this->processHelpers($e);
     });
 }

作者:razvansividr    项目:pnlzf2-   
/**
  * Prepares the environment before running a test
  *
  */
 protected function setUp()
 {
     $cwd = __DIR__;
     // read navigation config
     $this->_files = $cwd . '/_files';
     $config = ConfigFactory::fromFile($this->_files . '/navigation.xml', true);
     // setup containers from config
     $this->_nav1 = new Navigation($config->get('nav_test1'));
     $this->_nav2 = new Navigation($config->get('nav_test2'));
     // setup view
     $view = new PhpRenderer();
     $view->resolver()->addPath($cwd . '/_files/mvc/views');
     // create helper
     $this->_helper = new $this->_helperName();
     $this->_helper->setView($view);
     // set nav1 in helper as default
     $this->_helper->setContainer($this->_nav1);
     // setup service manager
     $smConfig = array('modules' => array(), 'module_listener_options' => array('config_cache_enabled' => false, 'cache_dir' => 'data/cache', 'module_paths' => array(), 'extra_config' => array('service_manager' => array('factories' => array('Config' => function () use($config) {
         return array('navigation' => array('default' => $config->get('nav_test1')));
     })))));
     $sm = $this->serviceManager = new ServiceManager(new ServiceManagerConfig());
     $sm->setService('ApplicationConfig', $smConfig);
     $sm->get('ModuleManager')->loadModules();
     $sm->get('Application')->bootstrap();
     $sm->setFactory('Navigation', 'Zend\\Navigation\\Service\\DefaultNavigationFactory');
     $sm->setService('nav1', $this->_nav1);
     $sm->setService('nav2', $this->_nav2);
     $app = $this->serviceManager->get('Application');
     $app->getMvcEvent()->setRouteMatch(new RouteMatch(array('controller' => 'post', 'action' => 'view', 'id' => '1337')));
 }

作者:robertodormepoc    项目:zf   
public function testGetAdapterWithConfig()
 {
     $httptest = new HttpClientTest();
     // Nirvanix adapter
     $nirvanixConfig = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/nirvanix.ini'), true);
     $nirvanixConfig = $nirvanixConfig->toArray();
     $nirvanixConfig[Nirvanix::HTTP_ADAPTER] = $httptest;
     $doc = new \DOMDocument('1.0', 'utf-8');
     $root = $doc->createElement('Response');
     $responseCode = $doc->createElement('ResponseCode', 0);
     $sessionTok = $doc->createElement('SessionToken', '54592180-7060-4D4B-BC74-2566F4B2F943');
     $root->appendChild($responseCode);
     $root->appendChild($sessionTok);
     $doc->appendChild($root);
     $body = $doc->saveXML();
     $resp = HttpResponse::fromString("HTTP/1.1 200 OK\nContent-type: text/xml;charset=UTF-8\nDate: 0\n\n" . $body);
     $httptest->setResponse($resp);
     $nirvanixAdapter = Factory::getAdapter($nirvanixConfig);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\Nirvanix', get_class($nirvanixAdapter));
     // S3 adapter
     $s3Config = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/s3.ini'), true);
     $s3Adapter = Factory::getAdapter($s3Config);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\S3', get_class($s3Adapter));
     // file system adapter
     $fileSystemConfig = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/filesystem.ini'), true);
     $fileSystemAdapter = Factory::getAdapter($fileSystemConfig);
     $this->assertEquals('Zend\\Cloud\\StorageService\\Adapter\\FileSystem', get_class($fileSystemAdapter));
     // Azure adapter
     /*
             $azureConfig    = ConfigFactory::fromFile(realpath(dirname(__FILE__) . '/_files/config/windowsazure.ini'), true);
             $azureConfig    = $azureConfig->toArray();
             $azureContainer = $azureConfig[WindowsAzure::CONTAINER];
             $azureConfig[WindowsAzure::HTTP_ADAPTER] = $httptest;
             $q = "?";
     
             $doc = new \DOMDocument('1.0', 'utf-8');
             $root = $doc->createElement('EnumerationResults');
             $acctName = $doc->createAttribute('AccountName');
             $acctName->value = 'http://myaccount.blob.core.windows.net';
             $root->appendChild($acctName);
             $maxResults     = $doc->createElement('MaxResults', 1);
             $containers     = $doc->createElement('Containers');
             $container      = $doc->createElement('Container');
             $containerName  = $doc->createElement('Name', $azureContainer);
             $container->appendChild($containerName);
             $containers->appendChild($container);
             $root->appendChild($maxResults);
             $root->appendChild($containers);
             $doc->appendChild($root);
             $body = $doc->saveXML();
     
             $resp = HttpResponse::fromString("HTTP/1.1 200 OK\nContent-type: text/xml;charset=UTF-8\nx-ms-request-id: 0\n\n".$body);
     
             $httptest->setResponse($resp);
             $azureAdapter = Factory::getAdapter($azureConfig);
             $this->assertEquals('Zend\Cloud\StorageService\Adapter\WindowsAzure', get_class($azureAdapter));
     *
     */
 }

作者:graphstor    项目:graph-kit-ph   
public function getSlimInstance()
 {
     $configPaths = sprintf('%s/config/{,*.}{global,%s,secret}.php', APPLICATION_PATH, SLIM_MODE);
     $config = ConfigFactory::fromFiles(glob($configPaths, GLOB_BRACE));
     $app = new Slim($config);
     // TODO: Include app.php file
     return $app;
 }

作者:citywar    项目:city-vie   
public function __construct($moduleName, $controllerName = null, $actionName = null)
 {
     $this->moduleName = $moduleName;
     $this->controllerName = $controllerName;
     $this->actionName = $actionName;
     $themeConfigPath = MODULES_PATH . ucfirst($moduleName) . DS . 'config' . DS . 'theme.config.ini';
     $this->loadConfig = \Zend\Config\Factory::fromFile($themeConfigPath);
 }

作者:khusamov-dum    项目:dum   
/**
  * Обновить запись.
  * Метод 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;
 }

作者:slh9    项目:CEE   
public function __construct()
 {
     $config = Factory::fromFile('config/config.php', true);
     $db_info = $config->get($config->get('ACTIVE_DB'));
     $this->dbhost = $db_info->get('host');
     $this->dbuser = $db_info->get('user');
     $this->dbpass = $db_info->get('password');
     $this->dbname = $db_info->get('name');
 }

作者:spryke    项目:Transfe   
/**
  * @return array
  */
 private function loadDefinitions()
 {
     $xmlTransferDefinitions = $this->finder->getXmlTransferDefinitionFiles();
     foreach ($xmlTransferDefinitions as $xmlTransferDefinition) {
         $bundle = $this->getBundleFromPathName($xmlTransferDefinition->getFilename());
         $containingBundle = $this->getContainingBundleFromPathName($xmlTransferDefinition->getPathname());
         $definition = Factory::fromFile($xmlTransferDefinition->getPathname(), true)->toArray();
         $this->addDefinition($definition, $bundle, $containingBundle);
     }
 }

作者:alex-oleshkevic    项目:zf-extra   
/**
  * 
  * @param string $filename
  * @return array
  */
 public static function load($filename)
 {
     $config = new ZendConfig(Factory::fromFile($filename), true);
     $variables = isset($config[self::VARIABLES_KEY]) ? $config[self::VARIABLES_KEY]->toArray() : array();
     $processorChain = new ProcessorChain();
     $processorChain->add(new Constant(false, 'const(', ')'));
     $processorChain->add(new Env('env(', ')'));
     $processorChain->add(new CallableProperty($variables));
     $processorChain->add(new Interpolator($variables));
     return $processorChain->process($config)->toArray();
 }

作者:rajanlami    项目:IntTes   
protected function setUp()
 {
     $this->select = new Sql\Select();
     $this->select->from('test');
     $this->testCollection = range(1, 101);
     $this->paginator = new Paginator\Paginator(new Paginator\Adapter\ArrayAdapter($this->testCollection));
     $this->config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true);
     $this->cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
     Paginator\Paginator::setCache($this->cache);
     $this->_restorePaginatorDefaults();
 }

作者:foxou3    项目:tayo-commo   
/**
  * Creates service.
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return \Zend\ModuleManager\ModuleManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $applicationConfig = $serviceLocator->get('ApplicationConfig');
     $moduleManager = parent::createService($serviceLocator);
     if (empty($applicationConfig['tayo_module_file']) === false) {
         $extraModules = Factory::fromFile($applicationConfig['tayo_module_file']);
         $modules = $moduleManager->getModules();
         $moduleManager->setModules(array_merge($modules, $extraModules));
     }
     return $moduleManager;
 }

作者:nosenaok    项目:phpDocumentor   
/**
  * Overwrite execute to override the default config file.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config_file = $input->getOption('config');
     if ($config_file) {
         $this->container['config'] = $this->container->share(function () use($config_file) {
             $files = array(__DIR__ . '/../../../data/phpdoc.tpl.xml');
             if ($config_file !== 'none') {
                 $files[] = $config_file;
             }
             return \Zend\Config\Factory::fromFiles($files, true);
         });
     }
 }

作者:slh9    项目:CEE   
private static function _validateJWT($jwt)
 {
     try {
         $config = Factory::fromFile('config/config.php', true);
         $secretKey = base64_decode($config->get('JWT')->get('key'));
         $signingAlgorithm = $config->get('JWT')->get('algorithm');
         $token = JWT::decode($jwt, $secretKey, array($signingAlgorithm));
         /* perhaps checks required to see if token->data even exists*/
         self::$uid = $token->data->uid;
         self::$tid = $token->data->tid;
         return $token->data->scope;
     } catch (Exception $e) {
         throw $e;
     }
 }

作者:navti    项目:xerxes-pazpar   
protected function setUp()
 {
     if (!extension_loaded('pdo_sqlite')) {
         $this->markTestSkipped('Pdo_Sqlite extension is not loaded');
     }
     $this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array('dbname' => __DIR__ . '/_files/test.sqlite'));
     $this->_query = $this->_adapter->select()->from('test');
     $this->_testCollection = range(1, 101);
     $this->_paginator = Paginator\Paginator::factory($this->_testCollection);
     $this->_config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true);
     $this->_cache = CacheFactory::factory(array('adapter' => array('name' => 'filesystem', 'options' => array('ttl' => 3600, 'cache_dir' => $this->_getTmpDir())), 'plugins' => array(array('name' => 'serializer', 'options' => array('serializer' => 'php_serialize')))));
     $this->_cache->clear(CacheAdapter::MATCH_ALL);
     Paginator\Paginator::setCache($this->_cache);
     $this->_restorePaginatorDefaults();
 }

作者:navassouz    项目:zf   
public function testConfigurationCanConfigureCompiledDefinition()
 {
     $config = ConfigFactory::fromFile(__DIR__ . '/_files/sample.php', true);
     $config = new Configuration($config->di);
     $di = new Di();
     $di->configure($config);
     $definition = $di->definitions()->getDefinitionByType('Zend\\Di\\Definition\\ArrayDefinition');
     $this->assertInstanceOf('Zend\\Di\\Definition\\ArrayDefinition', $definition);
     $this->assertTrue($di->definitions()->hasClass('My\\DbAdapter'));
     $this->assertTrue($di->definitions()->hasClass('My\\EntityA'));
     $this->assertTrue($di->definitions()->hasClass('My\\Mapper'));
     $this->assertTrue($di->definitions()->hasClass('My\\RepositoryA'));
     $this->assertTrue($di->definitions()->hasClass('My\\RepositoryB'));
     $this->assertFalse($di->definitions()->hasClass('My\\Foo'));
 }

作者:bradley-hol    项目:zf   
protected function setUp()
 {
     if (!extension_loaded('pdo_sqlite')) {
         $this->markTestSkipped('Pdo_Sqlite extension is not loaded');
     }
     $this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array('dbname' => __DIR__ . '/_files/test.sqlite'));
     $this->_query = $this->_adapter->select()->from('test');
     $this->_testCollection = range(1, 101);
     $this->_paginator = Paginator\Paginator::factory($this->_testCollection);
     $this->_config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true);
     $this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
     $this->_cache->clear(CacheAdapter::MATCH_ALL);
     Paginator\Paginator::setCache($this->_cache);
     $this->_restorePaginatorDefaults();
 }

作者:spryke    项目:Transfe   
/**
  * @param array $options
  *
  * @return bool
  */
 public function validate(array $options)
 {
     $files = $this->finder->getXmlTransferDefinitionFiles();
     $result = true;
     foreach ($files as $key => $file) {
         if ($options['bundle'] && strpos($file, '/Shared/' . $options['bundle'] . '/Transfer/') === false) {
             continue;
         }
         $definition = Factory::fromFile($file->getPathname(), true)->toArray();
         $definition = $this->normalize($definition);
         $bundle = $this->getBundleFromPathName($file->getFilename());
         $result = $result & $this->validateDefinition($bundle, $definition, $options);
     }
     return (bool) $result;
 }


问题


面经


文章

微信
公众号

扫码关注公众号