public function setConfigFolder($configFolder) { if (!$configFolder) { throw new \Exception('Empty config folder path.'); } $realPath = realpath($configFolder); if ($realPath != false && is_dir($realPath) && is_readable($realPath)) { $this->_configArray = array(); $this->_configFolder = $realPath . DIRECTORY_SEPARATOR; $namespaces = $this->app['namespaces']; if (is_array($namespaces)) { Loader::registerNamespaces($namespaces); } } else { throw new \Exception('Config directory read error: ' . $configFolder); } }
public function setConfigFolder(string $configFolder) { if (!$configFolder) { throw new \Exception('Empty config folder path.'); } $_configFolder = realpath($configFolder); if ($_configFolder != false && is_dir($_configFolder) && is_readable($_configFolder)) { //clear old config data $this->_configArray = array(); $this->_configFolder = $_configFolder . DIRECTORY_SEPARATOR; $namespaces = $this->app['namespaces']; if (is_array($namespaces)) { Loader::registerNamespaces($namespaces); } } else { throw new \Exception('Config directory read error: ' . strval($configFolder)); } }
public function setConfigFolder(string $configFolder) { if (!$configFolder) { throw new \Exception('folder path cannot be empty string'); } $_configFolder = realpath($configFolder); if ($_configFolder && is_dir($_configFolder) && is_readable($_configFolder)) { //Clear old config data $this->_configArr = array(); $this->_configFolder = $_configFolder . DIRECTORY_SEPARATOR; $ns = $this->app['namespaces']; if (is_array($ns)) { Loader::registerNamespaces($ns); } } else { throw new \Exception('Config Directory read error ' . $configFolder); } }
define('CACHE_RELATIVE_PATH', '/cache'); define('FILES_RELATIVE_PATH', '/files'); define('CLASS_RELATIVE_PATH', '/classes'); define('PUBLIC_RELATIVE_PATH', '/public'); define('TEMPLATES_RELATIVE_PATH', '/templates'); define('VIEWS_PATH', sprintf('%s/%s', ROOT_PATH, trim(VIEWS_RELATIVE_PATH, '/'))); define('CACHE_PATH', sprintf('%s/%s', ROOT_PATH, trim(CACHE_RELATIVE_PATH, '/'))); define('FILES_PATH', sprintf('%s/%s', ROOT_PATH, 'public/files')); define('CLASS_PATH', sprintf('%s/%s', ROOT_PATH, trim(CLASS_RELATIVE_PATH, '/'))); define('PUBLIC_PATH', sprintf('%s/%s', ROOT_PATH, trim(PUBLIC_RELATIVE_PATH, '/'))); define('TEMPLATES_PATH', sprintf('%s/%s', ROOT_PATH, trim(TEMPLATES_RELATIVE_PATH, '/'))); try { $config = new Config\Adapter\Ini(sprintf('%s/config.ini', ROOT_PATH)); /** Autoloader */ $loader = new Loader(); $loader->registerNamespaces(array('Forms' => sprintf('%s/forms', CLASS_PATH), 'Models' => sprintf('%s/models', CLASS_PATH), 'Plugins' => sprintf('%s/plugins', CLASS_PATH), 'Exceptions' => sprintf('%s/exceptions', CLASS_PATH), 'Controllers' => sprintf('%s/controllers', CLASS_PATH))); $loader->register(); /** Services */ $services = new Di\FactoryDefault(); $services->set('db', function () use($config) { return new Db\Adapter\Pdo\Mysql(array('host' => $config->db->host, 'port' => $config->db->port, 'dbname' => $config->db->dbname, 'username' => $config->db->username, 'password' => $config->db->password)); }, true); $services->set('url', function () { $url = new Mvc\Url(); $url->setBaseUri('/'); return $url; }, true); $services->set('view', function () { //$manager = new \Phalcon\Events\Manager(); //$manager->attach('view:beforeRender', function ($event, $view) { //
<?php require '../loader/Loader.php'; $loader = new Loader(); $loader->registerNamespaces(array('Events' => getcwd()))->register(); $manager = new Events\Manager(); $a = function () { echo "A"; }; $manager->attach('test:hello', $a); $b = function (Events\Event $event) { echo "B"; }; $manager->attach('test:hello', $b); var_dump($manager->fire('test:hello', null)); var_dump($manager->getListeners('test:hello'));
<?php # author: mengxuan # time; 2016/1/17 echo '=============================================================<br/>'; echo '我是测试自动的加载的demo!<br/>'; echo '该模块主要是实现Phalcon的自动加载(事件管理除外)!<br/>'; echo '=============================================================<br/>'; require 'Loader.php'; $loader = new Loader(); $loader->registerClasses(array('Test' => 'Test.php', 'Base\\Hello' => 'base/BaseHello.php')); $loader->registerNamespaces(array('Ns\\Base' => 'base/')); $loader->registerPrefixes(array('Pre_Base' => 'base/')); $loader->registerDirs(array('base/')); $loader->register(); $test = new Test(); $hello = new Base\Hello(); $ns = new Ns\Base\Ns(); $sayhello = new Ns\Base\More\SayHello(); $pre = new Pre_Base_Prefix(); $sayPre = new Pre_Base_More_SayPrefix(); // 文件路径不区分大小写 $dir = new HelloDir(); $sayDir = new More\SayDir(); $sayDirs = new More_SayDirs();