Beispiel #1
0
 /**
  * @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();
 }
Beispiel #2
0
 /**
  * Регистрация автозагрузчика модуля
  */
 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();
 }
Beispiel #3
0
 /**
  * Регистрация автозагрузчика модуля
  */
 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();
 }
Beispiel #4
0
 /**
  * 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);
 }
 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();
 }
Beispiel #6
0
 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');
 }
Beispiel #7
0
 protected function registerAutoloaders()
 {
     $loader = new Phalcon\Loader();
     $loader->registerNamespaces(['api' => APP_DIR . 'api']);
     $loader->registerDirs([APP_DIR . 'model']);
     $loader->register();
 }
Beispiel #8
0
 /**
  * 注册命名空间
  */
 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();
 }
 /**
  * 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);
 }
Beispiel #10
0
 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();
 }
Beispiel #11
0
 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);
 }
Beispiel #12
0
 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();
 }
Beispiel #13
0
 /**
  * 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();
 }
Beispiel #14
0
 public function onWorkerStart()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array(ROOT_PATH . '/application/controller/', ROOT_PATH . '/application/model/'));
     $loader->register();
     $this->di = new \Phalcon\Di\FactoryDefault();
     //Registering the view component
     $this->di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(ROOT_PATH . '/application/views/');
         return $view;
     });
 }
Beispiel #15
0
 /**
  * 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);
 }
Beispiel #16
0
 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']]);
 }
Beispiel #17
0
 /**
  * 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();
 }
 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();
 }
 public function registerAutoloaders()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Frontend\\Controller' => APPLICATION_PATH . '/modules/frontend/controllers/', 'Frontend\\Model' => APPLICATION_PATH . '/modules/frontend/models/'));
     $loader->register();
 }
Beispiel #20
0
 public function registerAutoloaders()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Modules\\Frontend\\Controllers' => __DIR__ . '/controllers/', 'Modules\\Frontend\\Models' => __DIR__ . '/models/', 'Modules\\Frontend\\Forms' => __DIR__ . '/forms/', 'Modules\\Frontend\\Elements' => __DIR__ . '/elements/', 'Modules\\Library' => __DIR__ . '/../library/'));
     $loader->register();
 }
Beispiel #21
0
 public function registerAutoloaders()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Multiple\\Backend\\Controllers' => '../apps/backend/controllers/', 'Multiple\\Backend\\Models' => '../apps/backend/models/', 'Multiple\\Backend\\Plugins' => '../apps/backend/plugins/'));
     $loader->register();
 }
Beispiel #22
0
 public function registerAutoloaders(\Phalcon\DiInterface $dependencyInjector = null)
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces([__NAMESPACE__ => __DIR__ . DS . 'src' . DS . 'Review']);
     $loader->register();
 }
Beispiel #23
0
function init_app_autoload()
{
    $loader = new \Phalcon\Loader();
    $loader->registerNamespaces(array('App\\Controllers' => CONTROLLERS_PATH, 'App\\Models' => MODELS_PATH, 'App\\Service' => SERVICE_PATH, 'App\\Library' => LIBRARY_PATH, 'App\\Config' => CONFIG_PATH, 'App\\Tasks' => TASKS_PATH));
    $loader->register();
}
Beispiel #24
0
 function phalcon()
 {
     static $application = null;
     if (is_null($application)) {
         $loader = new \Phalcon\Loader();
         $loader->registerDirs(array(APPLICATION_PATH . DS . 'phalcon/controllers/', APPLICATION_PATH . DS . 'phalcon/models/'));
         $loader->register();
         $di = new \Phalcon\DI();
         //Registering a router
         $di->set('router', 'Phalcon\\Mvc\\Router');
         //Registering a dispatcher
         $di->set('dispatcher', 'Phalcon\\Mvc\\Dispatcher');
         //Registering a Http\Response
         $di->set('response', 'Phalcon\\Http\\Response');
         //Registering a Http\Request
         $di->set('request', 'Phalcon\\Http\\Request');
         //Registering the view component
         $di->set('view', function () {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir(APPLICATION_PATH . DS . 'phalcon/views/');
             return $view;
         });
         $params = \Thin\Bootstrap::$bag['config']->getDatabase();
         $di->set('db', function () use($params) {
             return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $params->getHost(), "username" => $params->getUsername(), "password" => $params->getPassword(), "dbname" => $params->getDbname()));
         });
         //Registering the Models-Metadata
         $di->set('modelsMetadata', 'Phalcon\\Mvc\\Model\\Metadata\\Memory');
         //Registering the Models Manager
         $di->set('modelsManager', 'Phalcon\\Mvc\\Model\\Manager');
         $application = new \Phalcon\Mvc\Application();
         $application->setDI($di);
     }
     return $application;
 }
Beispiel #25
0
 /**
  * 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());
     }
 }
Beispiel #26
0
 public function registerAutoloaders()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Multiple\\Frontend\\Controllers' => '../apps/modules/frontend/controllers/', 'Multiple\\Frontend\\Models' => '../apps/modules/frontend/models/'));
     $loader->register();
 }
Beispiel #27
0
 /**
  * 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();
 }
Beispiel #28
0
 public function registerAutoloaders()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Modules\\Frontend\\Controllers' => __DIR__ . '/controllers/', 'Modules\\Frontend\\Models' => __DIR__ . '/models/'));
     $loader->register();
 }
Beispiel #29
0
<?php

error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
ini_set('display_errors', 1);
require dirname(__FILE__) . '/../app/bootstrap.php';
define('VERSION', '1.0.0');
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(FA_INCLUDE_MODULES . '/cli/tasks'));
$loader->register();
// Create a console application
$console = new \Phalcon\CLI\Console();
$console->setDI($di);
// Process the console arguments
$arguments = array();
foreach ($argv as $k => $arg) {
    if ($k == 1) {
        $task_parts = explode(':', $arg);
        $arguments['task'] = $task_parts[0];
        $arguments['action'] = isset($task_parts[1]) ? $task_parts[1] : 'index';
    } elseif ($k > 1) {
        $arguments['params'][] = $arg;
    }
}
// define global constants for the current task and action
define('CURRENT_TASK', $arguments['task']);
define('CURRENT_ACTION', $arguments['action']);
try {
    // handle incoming arguments
    $console->handle($arguments);
} catch (\Phalcon\Exception $e) {
    echo $e->getMessage();
 public function registerAutoloaders()
 {
     $loader = new \Phalcon\Loader();
     $loader->registerNamespaces(array('Modules\\Admin\\Controllers' => __DIR__ . '/controllers/', 'Modules\\Admin\\Models' => __DIR__ . '/models/', 'Library\\Mail' => __DIR__ . '/../librarys/PHPMailer/'));
     $loader->register();
 }