本文整理汇总了PHP中Zend\Config\Factory类的典型用法代码示例。如果您正苦于以下问题:PHP Factory类的具体用法?PHP Factory怎么用?PHP Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* 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);
}
}
}
示例2: loadDbConfig
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;
}
示例3: processCommandTask
/**
* 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;
}
示例4: __construct
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);
});
}
示例5: setUp
/**
* 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')));
}
示例6: testGetAdapterWithConfig
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));
*
*/
}
示例7: getSlimInstance
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;
}
示例8: __construct
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);
}
示例9: update
/**
* Обновить запись.
* Метод 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;
}
示例10: __construct
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');
}
示例11: loadDefinitions
/**
* @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);
}
}
示例12: load
/**
*
* @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();
}
示例13: setUp
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();
}
示例14: createService
/**
* 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;
}
示例15: execute
/**
* 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);
});
}
}