/** * Test Namespaces */ public function testNamespaces() { $loader = new \Phalcon\Loader(); $this->assertException(array($loader, 'registerNamespaces'), array(array('Phalcon\\Acl'), 'random'), 'Phalcon\\Loader\\Exception'); $this->assertException(array($loader, 'registerNamespaces'), array('Phalcon\\Acl'), 'Phalcon\\Loader\\Exception'); $loader->registerNamespaces(array('Phalcon\\Acl' => 'lib/Phalcon/Acl/')); $this->assertEquals($loader->getNamespaces(), array('Phalcon\\Acl' => 'lib/Phalcon/Acl/')); $loader->registerNamespaces(array('Phalcon\\Assets' => 'lib/Phalcon/Assets/'), true); $this->assertEquals($loader->getNamespaces(), array('Phalcon\\Acl' => 'lib/Phalcon/Acl/', 'Phalcon\\Assets' => 'lib/Phalcon/Assets/')); $loader->registerNamespaces(array('Phalcon' => 'lib/Phalcon/')); $this->assertEquals($loader->getNamespaces(), array('Phalcon' => 'lib/Phalcon/')); $loader->registerNamespaces(array('Phalcon' => 'src/Phalcon/'), false); $this->assertEquals($loader->getNamespaces(), array('Phalcon' => 'src/Phalcon/')); }
protected function registerAutoloaders() { $loader = new Phalcon\Loader(); $loader->registerNamespaces(['api' => APP_DIR . 'api']); $loader->registerDirs([APP_DIR . 'model']); $loader->register(); }
/** * @param \Phalcon\DiInterface $di */ public function registerAutoloaders(\Phalcon\DiInterface $di = null) { $loader = new \Phalcon\Loader(); $controller_class = 'Modules\\' . $this->_module_class_name . '\\Controllers'; $loader->registerNamespaces(array($controller_class => $this->_module_dir . '/controllers/')); $loader->register(); }
/** * Регистрация автозагрузчика модуля */ public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = NULL) { $config = new \Phalcon\Config\Adapter\Ini(__DIR__ . '/config/config.ini'); $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Kladr\\Core\\Models' => $config->application->modelsDir, 'Kladr\\Core\\Views' => $config->application->viewsDir, 'Kladr\\Core\\Controllers' => $config->application->controllersDir, 'Kladr\\Core\\Services' => $config->application->servicesDir, 'Kladr\\Core\\Plugins' => $config->application->pluginsDir, 'Kladr\\Core\\Plugins\\Base' => $config->application->pluginsBaseDir, 'Kladr\\Core\\Plugins\\General' => $config->application->pluginsGeneralDir, 'Kladr\\Core\\Plugins\\Tools' => $config->application->pluginsToolsDir)); $loader->register(); }
/** * Регистрация автозагрузчика модуля */ public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = NULL) { $config = new \Phalcon\Config\Adapter\Ini(__DIR__ . '/config/config.ini'); $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Kladr\\Frontend\\Models' => $config->application->modelsDir, 'Kladr\\Frontend\\Views' => $config->application->viewsDir, 'Kladr\\Frontend\\Controllers' => $config->application->controllersDir, 'Kladr\\Frontend\\Plugins' => $config->application->pluginsDir, 'Kladr\\Frontend\\Library' => $config->application->libraryDir, 'Phalcon' => __DIR__ . '/vendor/Phalcon/')); $loader->register(); }
public function testApplicationModulesDefinitionClosure() { // Creates the autoloader $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Frontend\\Controllers' => __DIR__ . '/modules/frontend/controllers/', 'Backend\\Controllers' => __DIR__ . '/modules/backend/controllers/')); $loader->register(); $_GET['_url'] = '/login'; Phalcon\DI::reset(); $di = new Phalcon\DI\FactoryDefault(); $di->set('router', function () { $router = new Phalcon\Mvc\Router(false); $router->add('/index', array('controller' => 'index', 'module' => 'frontend', 'namespace' => 'Frontend\\Controllers\\')); $router->add('/login', array('controller' => 'login', 'module' => 'backend', 'namespace' => 'Backend\\Controllers\\')); return $router; }); $application = new Phalcon\Mvc\Application(); $view = new \Phalcon\Mvc\View(); $application->registerModules(array('frontend' => function ($di) use($view) { $di->set('view', function () use($view) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir(__DIR__ . '/modules/frontend/views/'); return $view; }); }, 'backend' => function ($di) use($view) { $di->set('view', function () use($view) { $view->setViewsDir(__DIR__ . '/modules/backend/views/'); return $view; }); })); $application->setDi($di); $this->assertEquals($application->handle()->getContent(), '<html>here</html>' . PHP_EOL); $loader->unregister(); }
protected function registerLoaders() { $loader = new Phalcon\Loader(); $loader->registerNamespaces(['Models' => APP_PATH . 'models', 'Tests' => APP_PATH . 'tests', 'Fixtures' => APP_PATH . 'fixtures']); $loader->register(); require_once realpath(APP_PATH . '../vendor/autoload.php'); }
/** * Initializes the loader */ public function init() { $di = $this->getDi(); $eventsManager = $this->getEventsManager(); $modules = $di->get('modules'); foreach ($modules as $module => $enabled) { if (!$enabled) { continue; } $modulesNamespaces[ucfirst($module)] = $this->_config->application->modulesDir . ucfirst($module); } $modulesNamespaces['Engine'] = $this->_config->application->engineDir; $modulesNamespaces['Library'] = $this->_config->application->librariesDir; $loader = new \Phalcon\Loader(); $loader->registerNamespaces($modulesNamespaces); if ($this->_config->application->debug && $this->_config->installed) { $eventsManager->attach('loader', function ($event, $loader, $className) use($di) { if ($event->getType() == 'afterCheckClass') { $di->get('logger')->error("Can't load class '" . $className . "'"); } }); $loader->setEventsManager($eventsManager); } $loader->register(); $di->set('loader', $loader); }
protected function loader() { //注册加载各类服务的模块(Register an autoloader),以及各种文件 $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('App\\Api' => APP_PATH . '/common/api/', 'App\\Common' => APP_PATH . '/common/', 'App\\Models' => APP_PATH . '/common/models/', 'App\\Library' => APP_PATH . '/common/library/', 'App\\Controllers' => APP_PATH . '/common/controllers/', 'App\\Backend\\Controllers' => APP_PATH . '/backend/controllers/'))->register(); include_once APP_PATH . '/common/library/functions.php'; }
/** * 注册命名空间 */ public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = NULL) { $config = \TConfig::instance()->getModule($this->moduleId); $loader = new \Phalcon\Loader(); $loader->registerDirs(isset($config['autoloadDir']) ? $config['autoloadDir'] : array()); $loader->registerNamespaces(isset($config['autoloadNamespace']) ? $config['autoloadNamespace'] : array()); $loader->register(); }
public function registerAutoloaders(\Phalcon\DiInterface $di = NULL) { $config = $di->get('config'); $loader = new \Phalcon\Loader(); $namespace = array($this->namespace . '\\Controllers' => '../' . $config->app->apps . $this->moduleName . '/' . $config->app->controllers, $this->namespace . '\\Models' => '../' . $config->app->apps . $this->moduleName . '/' . $config->app->models); $loader->registerNamespaces($namespace); $loader->register(); }
/** * register Loader */ protected function registerLoader() { $loader = new \Phalcon\Loader(); $loader->registerNamespaces($this->config->application->registerNamespaces->toArray()); $loader->registerDirs($this->config->application->registerDirs->toArray()); $loader->register(); $this->di->set('loader', $loader); }
/** * Set namespaces to tranverse through in the autoloader * * @link http://docs.phalconphp.com/en/latest/reference/loader.html * @throws Exception * @param string $file map of namespace to directories */ public function setAutoload($file, $dir) { if (!file_exists($file)) { throw new \Exception('Unable to load autoloader file'); } // Set dir to be used inside include file $namespaces = (include $file); $loader = new \Phalcon\Loader(); $loader->registerNamespaces($namespaces)->register(); }
public function run() { $di = new \Phalcon\DI\FactoryDefault(); // Config require_once APPLICATION_PATH . '/modules/Cms/Config.php'; $config = \Cms\Config::get(); $di->set('config', $config); // Registry $registry = new \Phalcon\Registry(); $di->set('registry', $registry); // Loader $loader = new \Phalcon\Loader(); $loader->registerNamespaces($config->loader->namespaces->toArray()); $loader->registerDirs([APPLICATION_PATH . "/plugins/"]); $loader->register(); require_once APPLICATION_PATH . '/../vendor/autoload.php'; // Database $db = new \Phalcon\Db\Adapter\Pdo\Mysql(["host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => $config->database->charset]); $di->set('db', $db); // View $this->initView($di); // URL $url = new \Phalcon\Mvc\Url(); $url->setBasePath($config->base_path); $url->setBaseUri($config->base_path); $di->set('url', $url); // Cache $this->initCache($di); // CMS $cmsModel = new \Cms\Model\Configuration(); $registry->cms = $cmsModel->getConfig(); // Отправляем в Registry // Application $application = new \Phalcon\Mvc\Application(); $application->registerModules($config->modules->toArray()); // Events Manager, Dispatcher $this->initEventManager($di); // Session $session = new \Phalcon\Session\Adapter\Files(); $session->start(); $di->set('session', $session); $acl = new \Application\Acl\DefaultAcl(); $di->set('acl', $acl); // JS Assets $this->initAssetsManager($di); // Flash helper $flash = new \Phalcon\Flash\Session(['error' => 'ui red inverted segment', 'success' => 'ui green inverted segment', 'notice' => 'ui blue inverted segment', 'warning' => 'ui orange inverted segment']); $di->set('flash', $flash); $di->set('helper', new \Application\Mvc\Helper()); // Routing $this->initRouting($application, $di); $application->setDI($di); // Main dispatching process $this->dispatch($di); }
public static function init($dirs = array(), $namespaces = array()) { $commonDirs = array(); $commonDirs[] = dirname(__FILE__); $commonDirs[] = realpath(dirname(dirname(__FILE__)) . '/_library'); $commonNamespaces = array(); $loader = new \Phalcon\Loader(); $loader->registerDirs(array_merge($commonDirs, $dirs)); $loader->registerNamespaces(array_merge($commonNamespaces, $namespaces)); $loader->register(); }
/** * Registers an autoloader related to the module * * @param \Phalcon\DiInterface $dependencyInjector */ public function registerAutoloaders($di) { $namespaces = []; foreach ($this->_loaders as $load) { $load = ucfirst($load); $namespace = $this->_moduleName . '\\' . $load; $directory = $this->getModuleDirectory() . '/' . $load; $namespaces[$namespace] = $directory; } $loader = new \Phalcon\Loader(); $loader->registerNamespaces($namespaces); $loader->register(); }
/** * Constructor */ public function __construct() { if (empty($this->_configPath)) { $class = new \ReflectionClass($this); throw new \Engine\Exception('Application has no config path: ' . $class->getFileName()); } $loader = new \Phalcon\Loader(); $loader->registerNamespaces(['Engine' => ROOT_PATH . '/engine']); $loader->register(); // create default di $di = new \Phalcon\DI\FactoryDefault(); // get config $this->_config = (include_once ROOT_PATH . $this->_configPath); // Store config in the Di container $di->setShared('config', $this->_config); parent::__construct($di); }
private function setServices() { $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Common' => __DIR__ . '/../components/', 'Common\\Controllers' => __DIR__ . '/../controllers/', 'Common\\Models' => __DIR__ . '/../models/')); $loader->register(); $config = new \Common\Config(); $di = new \Phalcon\DI\FactoryDefault(); $di->set('router', new \Common\Router()); $di->set('url', new \Phalcon\Mvc\Url()); $di->set('db', new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name))); $di->set('session', function () { $session = new \Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); $di->set('modelsMetadata', new \Phalcon\Mvc\Model\Metadata\Files(array('metaDataDir' => __DIR__ . '/../cache/models/'))); $this->setDI($di); $this->registerModules(['frontend' => ['className' => 'Frontend\\Module', 'path' => '../apps/frontend/components/Module.php'], 'backend' => ['className' => 'Backend\\Module', 'path' => '../apps/backend/components/Module.php']]); }
/** * Register loader */ protected function registerLoader() { $config =& $this->configuration; $loader = new \Phalcon\Loader(); if (isset($config['application']['registerNamespaces'])) { $loadNamespaces = $config['application']['registerNamespaces']; } else { $loadNamespaces = array(); } foreach ($config['application']['modules'] as $module => $enabled) { $moduleName = ucfirst($module); $loadNamespaces[$moduleName . '\\Model'] = APPLICATION_PATH . '/modules/' . $module . '/models/'; $loadNamespaces[$moduleName . '\\Service'] = APPLICATION_PATH . '/modules/' . $module . '/services/'; } if (isset($config['application']['registerDirs'])) { $loader->registerDirs($config['application']['registerDirs']); } $loader->registerNamespaces($loadNamespaces)->register(); }
TODO: \Phalcon shell: - bootstrap? - healcheck? => check \Phalcon is loaded, check Mongo is loaded - Layouts - add CSS / JS based on controller / action - if Dev, if file.LESS newer than file.css, compile LESS - headlink / headscript, with optional merger / minifier */ define('BASE_DIR', dirname(__DIR__)); define('APP_DIR', BASE_DIR . '/app'); try { $config = new \Phalcon\Config\Adapter\Ini(APP_DIR . '/config/config.ini'); //Register an autoloader $loader = new \Phalcon\Loader(); $loader->registerNamespaces(["Watchlist\\Controllers" => BASE_DIR . '/' . $config->application->controllersDir, "Watchlist\\Views" => BASE_DIR . '/' . $config->application->viewsDir, "Watchlist\\Models" => BASE_DIR . '/' . $config->application->modelsDir, "Watchlist" => BASE_DIR . '/' . $config->application->appLibDir, "Phalcore" => BASE_DIR . '/' . $config->application->librariesDir . "phalcore/"])->register(); //Create a DI $config["di"] = new \Phalcon\DI\FactoryDefault(); $config["di"]->set('session', function () { $session = new \Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); //Setup the view component $config["di"]->set('view', function () use($config) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir(BASE_DIR . '/' . $config->application->viewsDir); return $view; }); $config["di"]->set('dispatcher', function () { $dispatcher = new \Phalcon\Mvc\Dispatcher();
/** * Execute Phalcon Developer Tools * * @param string $path The path to the Phalcon Developer Tools * @param string $ip Optional IP address for securing Developer Tools * @return void * @throws \Exception if Phalcon extension is not installed * @throws \Exception if Phalcon version is not compatible Developer Tools * @throws \Phalcon\Exception if Application config could not be loaded */ public static function main($path, $ip = null) { if (!extension_loaded('phalcon')) { throw new \Exception('Phalcon extension is not installed, follow these instructions to install it: http://phalconphp.com/documentation/install'); } if ($ip !== null) { self::$ip = $ip; } if (!defined('TEMPLATE_PATH')) { define('TEMPLATE_PATH', $path . '/templates'); } chdir('..'); // Read configuration $configPaths = array('config', 'app/config', 'apps/frontend/config'); $readed = false; foreach ($configPaths as $configPath) { $cpath = $configPath . '/config.ini'; if (file_exists($cpath)) { $config = new \Phalcon\Config\Adapter\Ini($cpath); $readed = true; break; } else { $cpath = $configPath . '/config.php'; if (file_exists($cpath)) { $config = (require $cpath); $readed = true; break; } } } if ($readed === false) { throw new \Phalcon\Exception('Configuration file could not be loaded!'); } $loader = new \Phalcon\Loader(); $loader->registerDirs(array($path . '/scripts/', $path . '/scripts/Phalcon/Web/Tools/controllers/')); $loader->registerNamespaces(array('Phalcon' => $path . '/scripts/')); $loader->register(); if (Version::getId() < Script::COMPATIBLE_VERSION) { throw new \Exception('Your Phalcon version is not compatible with Developer Tools, download the latest at: http://phalconphp.com/download'); } try { $di = new FactoryDefault(); $di->set('view', function () use($path) { $view = new View(); $view->setViewsDir($path . '/scripts/Phalcon/Web/Tools/views/'); return $view; }); $di->set('config', $config); $di->set('url', function () use($config) { $url = new \Phalcon\Mvc\Url(); $url->setBaseUri($config->application->baseUri); return $url; }); $di->set('flash', function () { return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info')); }); $di->set('db', function () use($config) { if (isset($config->database->adapter)) { $adapter = $config->database->adapter; } else { $adapter = 'Mysql'; } if (is_object($config->database)) { $configArray = $config->database->toArray(); } else { $configArray = $config->database; } $className = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter; unset($configArray['adapter']); return new $className($configArray); }); self::$di = $di; $app = new \Phalcon\Mvc\Application(); $app->setDi($di); echo $app->handle()->getContent(); } catch (\Phalcon\Exception $e) { echo get_class($e), ': ', $e->getMessage(), "<br>"; echo nl2br($e->getTraceAsString()); } catch (\PDOException $e) { echo get_class($e), ': ', $e->getMessage(), "<br>"; echo nl2br($e->getTraceAsString()); } }
/** * Register a specific autoloader for the module * * @package base-app * @version 2.0 * * @param mixed $di dependency Injector * * @return void */ public function registerAutoloaders(\Phalcon\DiInterface $di = null) { $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Baseapp\\Documentation\\Controllers' => __DIR__ . '/controllers/')); $loader->register(); }
/** * Register a specific autoloader for the module * * @package base-app * @version 2.0 * * @param mixed $di dependency Injector * * @return void */ public function registerAutoloaders(\Phalcon\DiInterface $di = null) { $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Baseapp\\Cli\\Tasks' => __DIR__ . '/tasks/')); $loader->register(); }
<?php $loader = new \Phalcon\Loader(); /** * We're a registering a set of directories taken from the configuration file */ $loader->registerNamespaces(array('Vokuro\\Models' => $config->application->modelsDir, 'Vokuro\\Controllers' => $config->application->controllersDir, 'Vokuro\\Forms' => $config->application->formsDir, 'Vokuro' => $config->application->libraryDir)); $loader->register(); // Use composer autoloader to load vendor classes require_once __DIR__ . '/../../vendor/autoload.php';
<?php $loader = new \Phalcon\Loader(); $loader->registerDirs(array(__DIR__ . '/../tasks', __DIR__ . '/../services', __DIR__ . '/../models')); $loader->registerNamespaces(array('Phalcon' => '/../incubator/Library/Phalcon/')); $loader->register();
<?php $loader = new Phalcon\Loader(); $loader->registerNamespaces(['App' => __DIR__ . '/../../app/library/App']); $loader->register(); require_once TESTS_PATH . '../vendor/autoload.php'; $di = new \PhalconRest\Di\FactoryDefault(); /** * Config */ $di->setShared('config', function () { $configFile = (require TESTS_PATH . '_config/global.php'); return new Config($configFile); }); return new \PhalconRest\Api($di);
public function registerAutoloaders(DiInterface $dependencyInjector = null) { $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Admin\\Controller' => APPLICATION_PATH . '/modules/admin/controllers/', 'Admin\\Model' => APPLICATION_PATH . '/modules/admin/models/', 'Admin\\Form' => APPLICATION_PATH . '/modules/admin/forms/')); $loader->register(); }
<?php /** * Phanbook : Delightfully simple forum software * * Licensed under The GNU License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @link http://phanbook.com Phanbook Project * @since 1.0.0 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */ $loader = new Phalcon\Loader(); /** * We're a registering a set of directories taken from the configuration file */ $loader->registerNamespaces(['Phanbook' => ROOT_DIR . 'core/common/library/', 'Phanbook\\Tools' => ROOT_DIR . 'core/common/tools/', 'Phanbook\\Models' => ROOT_DIR . 'core/common/models/', 'Phanbook\\Factory' => ROOT_DIR . 'core/common/factory', 'Phanbook\\Plugins' => ROOT_DIR . 'core/common/plugins/', 'Phanbook\\Validators' => ROOT_DIR . 'core/common/validators/', 'Phanbook\\Forms' => ROOT_DIR . 'core/common/forms/']); $loader->register();
<?php /** * Phanbook : Delightfully simple forum software * * Licensed under The GNU License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @link http://phanbook.com Phanbook Project * @since 1.0.0 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */ $loader = new Phalcon\Loader(); /** * We're a registering a set of directories taken from the configuration file */ $loader->registerNamespaces(array('Phanbook\\Controllers' => ROOT_DIR . 'apps/controllers/', 'Phanbook\\Models' => ROOT_DIR . 'common/models/', 'Phanbook\\Validators' => ROOT_DIR . 'common/validators/', 'Phanbook\\Tools' => ROOT_DIR . 'common/tools/', 'Phanbook\\Forms' => ROOT_DIR . 'apps/forms/', 'Phanbook\\Plugins' => ROOT_DIR . 'common/plugins/', 'Phanbook' => ROOT_DIR . 'common/library/')); $loader->register();
<?php # initalize backend application services $config = (require APP_PATH . '/config/config.php'); $loader = new \Phalcon\Loader(); $loader->registerNamespaces(['PhalconCart' => APP_PATH . '/app/'])->register(); $service = new \PhalconCart\Core\Initializer\BackendService(); $service->register($config); $service->attachRouter(require APP_PATH . '/config/routes/backend.php'); return $service;