private function parseDefinitionArgument($argument) { if (Text::startsWith($argument, '!')) { return ['type' => 'parameter', 'value' => Arr::path($this->config->toArray(), substr($argument, 1))]; } elseif (Text::startsWith($argument, '@')) { return ['type' => 'service', 'name' => substr($argument, 1)]; } else { return ['type' => 'parameter', 'value' => $argument]; } }
/** * Prepares component * * @param \Phalcon\Config $database Database config * * @throws \Phalcon\Db\Exception */ public static function setup($database) { if (!isset($database->adapter)) { throw new DbException('Unspecified database Adapter in your configuration!'); } $adapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $database->adapter; if (!class_exists($adapter)) { throw new DbException('Invalid database Adapter!'); } $configArray = $database->toArray(); unset($configArray['adapter']); self::$_connection = new $adapter($configArray); self::$_databaseConfig = $database; if ($database->adapter == 'Mysql') { self::$_connection->query('SET FOREIGN_KEY_CHECKS=0'); } if (Migrations::isConsole()) { $profiler = new Profiler(); $eventsManager = new EventsManager(); $eventsManager->attach('db', function ($event, $connection) use($profiler) { if ($event->getType() == 'beforeQuery') { $profiler->startProfile($connection->getSQLStatement()); } if ($event->getType() == 'afterQuery') { $profiler->stopProfile(); } }); self::$_connection->setEventsManager($eventsManager); } }
/** * Implement configurations * * @param \Phalcon\Config $config $config * @throws \Sonar\Exceptions\QueueServiceException */ public function __construct(\Phalcon\Config $config) { if ($this->beanstalkMapper === null) { try { $this->beanstalkMapper = new BeanstalkMapper($config->toArray()); } catch (BeanstalkMapperException $e) { throw new QueueServiceException($e->getMessage()); } } }
protected function compareConfig(array $actual, Config $expected) { $this->assertEquals($actual, $expected->toArray()); foreach ($actual as $key => $value) { $this->assertTrue(isset($expected->{$key})); if (is_array($value)) { $this->compareConfig($value, $expected->{$key}); } } }
/** * @param \Phalcon\Config|array $config */ public function build($config) { $routes = $config instanceof \Phalcon\Config ? $config->toArray() : $config; foreach ($routes as $name => $value) { $names = explode('_', $name); $value['url'] = isset($value['url']) ? $value['url'] : '/' . str_replace('_', '/', $name); // normalized url $length = strlen($value['url']); if ($value['url'][$length - 1] === '/' && $length > 1 && $this->_removeExtraSlashes) { $value['url'] = rtrim($value['url'], '/'); } $value['controller'] = isset($value['controller']) ? $value['controller'] : $names[0]; if (isset($value['action'])) { } elseif (isset($names[1])) { $value['action'] = $names[1]; } else { $value['action'] = 'index'; } $this->add($value['url'], $value)->setName($name)->via($value['method']); } }
public function diConfig() { $di = $this->getDI(); $cachePrefix = $this->getAppName(); $cacheFile = $this->getConfigPath() . "/_cache.{$cachePrefix}.config.php"; if ($cache = $this->readCache($cacheFile)) { return new Config($cache); } $config = new Config(); //merge all loaded module configs $moduleManager = $di->getModuleManager(); if (!$moduleManager || !($modules = $moduleManager->getModules())) { throw new Exception\RuntimeException(sprintf('Config need at least one module loaded')); } foreach ($modules as $moduleName => $module) { $moduleConfig = $moduleManager->getModuleConfig($moduleName); if ($moduleConfig instanceof Config) { $config->merge($moduleConfig); } else { $config->merge(new Config($moduleConfig)); } } //merge config default $config->merge(new Config(include $this->getConfigPath() . "/config.default.php")); //merge config local if (false === file_exists($this->getConfigPath() . "/config.local.php")) { return $config; } $config->merge(new Config(include $this->getConfigPath() . "/config.local.php")); if (!$config->debug) { $this->writeCache($cacheFile, $config->toArray()); } return $config; }
/** * @param \Phalcon\Config $database * @throws DbException */ public static function connSetup($database) { if (!isset($database->adapter)) { throw new DbException('Unspecified database Adapter in your configuration!'); } $adapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $database->adapter; if (!class_exists($adapter)) { throw new DbException('Invalid database Adapter!'); } $configArray = $database->toArray(); unset($configArray['adapter']); self::$_connection = new $adapter($configArray); if ($database->adapter == 'Mysql') { self::$_connection->query('SET FOREIGN_KEY_CHECKS=0'); } if (!self::$_connection->tableExists('phalcon_migrations')) { self::$_connection->execute('CREATE TABLE `phalcon_migrations` (`version` VARCHAR(14) NOT NULL, `start_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `end_time` TIMESTAMP NOT NULL DEFAULT "0000-00-00 00:00:00" ) DEFAULT CHARSET = utf8;'); } }
protected static function loadDb(PhalconConfig $config) { $dbConfig = new PhalconConfig(Model\Config::all()); $config->merge($dbConfig); static::$config = $config->toArray(); }
public function toArray() { return parent::toArray(); }
/** * Initializes the ACL Variable * * @param array $options */ public function initPermission($options = []) { $permFile = (require ROOT_PATH . '/conf/permission.php'); $this->di->setShared('permission', function () use($permFile) { $perm = new PhConfig($permFile); return $perm->toArray(); }); }