示例#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();
 }
示例#2
0
文件: app.php 项目: nisnaker/tu
 protected function registerAutoloaders()
 {
     $loader = new Phalcon\Loader();
     $loader->registerNamespaces(['api' => APP_DIR . 'api']);
     $loader->registerDirs([APP_DIR . 'model']);
     $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();
 }
示例#4
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();
 }
示例#5
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);
 }
示例#6
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();
 }
示例#7
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');
 }
示例#8
0
 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';
 }
示例#9
0
文件: Module.php 项目: noikiy/public
 /**
  * 注册命名空间
  */
 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();
 }
示例#10
0
 /**
  * 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);
 }
示例#11
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();
 }
示例#12
0
文件: index.php 项目: netstu/vd_ask
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function _registerServices()
 {
     $config = (include __DIR__ . "/../apps/config/config.php");
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array($config->application->libraryDir, $config->application->pluginDir))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/cats/index", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'index'));
         $router->add("/cat/:params", array('module' => 'frontend', 'controller' => 'categories', 'action' => 'cat', 'params' => 1));
         $router->add("/ask/:params", array('module' => 'frontend', 'controller' => 'ask', 'action' => 'ask', 'params' => 1));
         $router->add("/admin/:controller/:action/:params", array('module' => 'backend', 'controller' => 1, 'action' => 2, 'params' => 3));
         return $router;
     });
     $di->set('db', function () use($config) {
         $mysql = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
         $mysql->query("set names 'utf8'");
         return $mysql;
     });
     $di->set('volt', function ($view, $di) use($config) {
         $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
         $volt->setOptions(array('compiledPath' => $config->volt->path, 'compiledExtension' => $config->volt->extension, 'compiledSeparator' => $config->volt->separator, 'stat' => (bool) $config->volt->stat));
         return $volt;
     });
     //Set the views cache service
     $di->set('viewCache', function () {
         //Cache data for one day by default
         $frontCache = new Phalcon\Cache\Frontend\Output(array("lifetime" => 86400));
         //Memcached connection settings
         $cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => "../apps/caches/"));
         return $cache;
     });
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise
      */
     $di->set('modelsMetadata', function () use($config) {
         if (isset($config->models->metadata)) {
             $metaDataConfig = $config->models->metadata;
             $metadataAdapter = 'Phalcon\\Mvc\\Model\\Metadata\\' . $metaDataConfig->adapter;
             return new $metadataAdapter();
         } else {
             return new Phalcon\Mvc\Model\Metadata\Memory();
         }
     });
     //Start the session the first time some component request the session service
     $di->set('session', function () {
         $session = new Phalcon\Session\Adapter\Files();
         $session->start();
         return $session;
     });
     $this->setDI($di);
 }
示例#13
0
文件: Micro.php 项目: w3yyb/phalphp
 /**
  * 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();
 }
示例#14
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);
 }
示例#15
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();
 }
示例#16
0
 public static function init()
 {
     try {
         $loader = new \Phalcon\Loader();
         $loader->registerDirs([__DIR__ . DS . 'controllers' . DS, __DIR__ . DS . 'views' . DS, __DIR__ . DS . 'models' . DS, __DIR__ . DS . 'lib' . DS])->registerNamespaces(['Phalway' => __DIR__])->register();
         context()->set('phalwayLoader', $loader);
         $di = new \Phalcon\DI\FactoryDefault();
         return new \Phalcon\Mvc\Application($di);
     } catch (\Phalcon\Exception $e) {
         dd($e);
     }
 }
示例#17
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;
     });
 }
示例#18
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();
 }
示例#19
0
 public static function initAutoloaders()
 {
     $loader = new \Phalcon\Loader();
     //注册公共命名空间
     $loader->registerNamespaces(array('Application\\Common\\Controller' => '../application/common/controller/', 'Application\\Common\\Model' => '../application/common/model/'))->register();
     //注册公共插件、公共类库,公共函数库
     $loader->registerDirs(array(LIB_PATH, PLUGINS_PATH, FUNCTIONS_PATH))->register();
 }
示例#20
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);
 }
示例#21
0
 /**
  * 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();
 }
示例#22
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']]);
 }
示例#23
0
文件: index.php 项目: abuelezz/mvc
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 protected function _registerServices()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     /**
      * We're a registering a set of directories taken from the configuration file
      */
     $loader->registerDirs(array(__DIR__ . '/../apps/library/'))->register();
     //Registering a router
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add("/login", array('module' => 'backend', 'controller' => 'login', 'action' => 'index'));
         $router->add("/admin/products/:action", array('module' => 'backend', 'controller' => 'products', 'action' => 1));
         $router->add("/products/:action", array('module' => 'frontend', 'controller' => 'products', 'action' => 1));
         return $router;
     });
     $this->setDI($di);
 }
示例#24
0
<?php

use Phalcon\DI\FactoryDefault\CLI as CliDI, Phalcon\CLI\Console as ConsoleApp;
define('VERSION', '1.0.0');
// Using the CLI factory default services container
$di = new CliDI();
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));
/**
 * Register the autoloader and tell it to register the tasks directory
 */
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(APPLICATION_PATH . '/tasks', APPLICATION_PATH . '/models', APPLICATION_PATH . '/classes'));
$loader->register();
// Load the configuration file (if any)
if (is_readable(APPLICATION_PATH . '/config/config.php')) {
    $config = (include APPLICATION_PATH . '/config/config.php');
    $di->set('config', $config);
}
// Create a console application
$console = new ConsoleApp();
$console->setDI($di);
//Setup the database service
$di->set('db', function () use($config) {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
});
/**
 * Process the console arguments
 */
$arguments = array();
foreach ($argv as $k => $arg) {
示例#25
0
文件: cli.php 项目: einstein95/FAOpen
<?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();
示例#26
0
文件: index.php 项目: chyro/Lifestyle
/*
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 () {
示例#27
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());
     }
 }
示例#28
0
<?php

/**
 * Created by PhpStorm.
 * User: ashmjn
 * Date: 19/09/2015
 * Time: 6:30 PM
 */
$loader = new \Phalcon\Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(array(APP_PATH . $config->application->controllersDir, APP_PATH . $config->application->pluginsDir, APP_PATH . $config->application->libraryDir, APP_PATH . $config->application->modelsDir, APP_PATH . $config->application->formsDir))->register();
示例#29
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();
 }
示例#30
-1
 protected function _registerServices()
 {
     $di = new \Phalcon\DI\FactoryDefault();
     $loader = new \Phalcon\Loader();
     $loader->registerDirs(array(FOLDER_PROJECT . '/apps/library/', FOLDER_PROJECT . '/apps/backend/models', FOLDER_PROJECT . '/apps/frontend/models'))->register();
     //usando autoloader do composer para carregar as depêndencias instaladas via composer
     require_once FOLDER_PROJECT . 'vendor/autoload.php';
     $di->set('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->setDefaultModule("frontend");
         $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2));
         $router->add('/:controller/:action', array('module' => 'backend', 'controller' => 1, 'action' => 2));
         $router->add("/admin", array('module' => 'backend', 'controller' => 'index', 'action' => 'index'));
         $router->add("/editor", array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
         $router->add("/index/:action", array('controller' => 'index', 'action' => 1));
         return $router;
     });
     $di->set("libMail", function () {
         return new Multiple\Library\Mail();
     });
     /**
      * Caso exista o arquivo de configuração config.ini coleta os dados existentes nele e
      * conecta com o banco de dados
      */
     if (file_exists('../apps/config/config.ini')) {
         $config = new \Phalcon\Config\Adapter\Ini('../apps/config/config.ini');
         //Seta a conexão com o banco de dados
         $di->set('db', function () use($config) {
             $dbclass = 'Phalcon\\Db\\Adapter\\Pdo\\' . $config->database->adapter;
             return new $dbclass(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, "charset" => 'utf8'));
         });
     }
     $this->setDI($di);
 }