public function testGet() { $url = new Url(); $url->setBaseUri('http://www.test.com'); $this->assertEquals('http://www.test.com', $url->get('')); $this->assertEquals('http://www.test.com/', $url->get('/')); $this->assertEquals('http://www.test.com/path', $url->get('/path')); $url->setBaseUri('http://www.test.com/?_url=/'); $this->assertEquals('http://www.test.com/?_url=/path¶ms=one', $url->get('path', array('params' => 'one'))); }
private function setUrl() { $url = new Url(); if (!$this->application->debug) { $url->setBaseUri($this->application->production->baseUri); $url->setStaticBaseUri($this->application->production->staticBaseUri); } else { $url->setBaseUri($this->application->development->baseUri); $url->setStaticBaseUri($this->application->development->staticBaseUri); } return $url; }
public function registerServices(DiInterface $di) { global $config; $di->setShared('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->backend->baseUri); return $url; }); $di->setShared('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers"); return $dispatcher; }); $di->setShared('view', function () use($config) { $view = new View(); $view->setViewsDir($config->backend->viewsDir); $view->setLayoutsDir('layouts/'); $view->setPartialsDir('partials/'); $view->registerEngines(array('.phtml' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }); }
function setDi() { $di = new FactoryDefault(); $di['router'] = function () use($di) { $router = new Router(); $router->setDefaultModule('mobimall'); return $router; }; $di['url'] = function () { $url = new UrlResolver(); $url->setBaseUri('/'); return $url; }; $di['session'] = function () { $session = new SessionAdapter(); // $session->start(); return $session; }; $loader = new Loader(); $loader->registerNamespaces(array('Mall\\Mdu' => __DIR__ . '/../apps/mdu')); $sysConfig = (include __DIR__ . '/../config/sysconfig.php'); $di['sysconfig'] = function () use($sysConfig) { return $sysConfig; }; $loader->register(); return $di; }
/** * Registers the module-only services * * @param \Phalcon\DiInterface $di */ public function registerServices($di) { /** * Read application wide and module only configurations */ $appConfig = $di->get('config'); $moduleConfig = (include __DIR__ . '/config/config.php'); $di->set('moduleConfig', $moduleConfig); /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($appConfig) { $url = new UrlResolver(); $url->setBaseUri($appConfig->application->baseUri); return $url; }); /** * Module specific dispatcher */ $di->set('dispatcher', function () use($di) { $dispatcher = new Dispatcher(); $dispatcher->setEventsManager($di->getShared('eventsManager')); $dispatcher->setDefaultNamespace('App\\Modules\\Oauth\\'); return $dispatcher; }); /** * Module specific database connection */ $di->set('db', function () use($appConfig) { return new DbAdapter(['host' => $moduleConfig->database->host, 'username' => $moduleConfig->database->username, 'password' => $moduleConfig->database->password, 'dbname' => $moduleConfig->database->name]); }); }
/** * Register the services here to make them general * or register in the ModuleDefinition to make them module-specific */ public function registerServices(DiInterface $di) { //Read configuration $config = (include __DIR__ . "/config/config.php"); // The URL component is used to generate all kind of urls in the application $di->set('url', function () use($config) { $url = new Url(); $url->setBaseUri($config->application->baseUri); return $url; }); //Registering a dispatcher $di->set('dispatcher', function () { //Create/Get an EventManager $eventsManager = new EventsManager(); //Attach a listener $eventsManager->attach('dispatch', function ($event, $dispatcher, $exception) { //controller or action doesn't exist if ($event->getType() == 'beforeException') { switch ($exception->getCode()) { case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND: case Dispatcher::EXCEPTION_ACTION_NOT_FOUND: $dispatcher->forward(['module' => 'backend', 'controller' => 'errors', 'action' => 'notFound']); return false; } } }); $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Phanbook\\Backend\\Controllers"); $dispatcher->setEventsManager($eventsManager); return $dispatcher; }); /** * Setting up the view component */ $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]); $view->registerEngines(['.volt' => 'volt']); // Create an event manager $eventsManager = new EventsManager(); // Attach a listener for type 'view' $eventsManager->attach('view', function ($event, $view) { if ($event->getType() == 'notFoundView') { throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')'); } }); // Bind the eventsManager to the view component $view->setEventsManager($eventsManager); return $view; }); $configMenu = (include __DIR__ . "/config/config.menu.php"); $di->setShared('menuStruct', function () use($configMenu) { // if structure received from db table instead getting from $config // we need to store it to cache for reducing db connections $struct = $configMenu->get('menuStruct')->toArray(); return $struct; }); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $url = new UrlResolver(); $url->setBaseUri($di->get('config')->application->baseUri); return $url; }, true); }
public function attachUrlResolver($baseUri = '/') { $this->_di->setShared('url', function () use($baseUri) { $url = new \Phalcon\Mvc\Url(); $url->setBaseUri($baseUri); return $url; }); return $this; }
/** * Register services used by the backend application * * @param $di */ public function registerServices($di) { $config = $this->config(); /** * register the dispatcher */ $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); /*$eventManager = new Manager(); $eventManager->attach('dispatch', new \Acl('backend')); $dispatcher->setEventsManager($eventManager);*/ $dispatcher->setDefaultNamespace('app\\backend\\controllers'); return $dispatcher; }); /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }, true); $di->setShared('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(['.volt' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(['compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_']); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']); return $view; }); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { return new MysqlAdapter($config->database->toArray()); }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); }
public function onBoot() { // TODO: Implement onBoot() method. $this->getDI()->setShared('url', function () { $protocol = stripos(server('SERVER_PROTOCOL'), 'https') === true ? 'https://' : 'http://'; $hostname = server('HTTP_HOST'); $url = new Url(); $url->setStaticBaseUri(env('static_url', "{$protocol}{$hostname}/")); $url->setBaseUri(env('base_url', '/')); return $url; }); }
/** * Registers services related to the module * * @param DiInterface $di */ public function registerServices(DiInterface $di) { /** * Read configuration */ $config = (include APP_PATH . "/apps/backend/config/config.php"); /** * Setting up the view component */ $di['view'] = function () use($config) { $view = new View(); $view->setViewsDir(__DIR__ . '/views/'); $view->registerEngines(array('.volt' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => __DIR__ . '/cache/', 'compiledSeparator' => '_')); $compiler = $volt->getCompiler(); // format number $compiler->addFilter('number', function ($resolvedArgs) { return 'Helpers::number(' . $resolvedArgs . ');'; }); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }; /** * Database connection is created based in the parameters defined in the configuration file */ $di['db'] = function () use($config) { $config = $config->database->toArray(); $dbAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config['adapter']; unset($config['adapter']); return new $dbAdapter($config); }; /** * Logger service */ $di->set('logger', function ($filename = null, $format = null) use($config) { $format = $format ?: $config->get('logger')->format; $filename = trim($filename ?: $config->get('logger')->filename, '\\/'); $path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR; $formatter = new FormatterLine($format, $config->get('logger')->date); $logger = new FileLogger($path . $filename); $logger->setFormatter($formatter); $logger->setLogLevel($config->get('logger')->logLevel); return $logger; }); $di->set('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri("/backend/"); return $url; }); }
/** * Initializes the response object and returns it * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-05 * * @return PhTResponse */ protected function getResponseObject() { PhDI::reset(); $di = new PhDI(); $di->set('url', function () { $url = new PhUrl(); $url->setBaseUri('/'); return $url; }); $response = new PhTResponse(); $response->setDI($di); return $response; }
/** * @param Router|null $router * @param Url|null $url */ public function __construct(Router $router = null, Url $url = null) { $di = new DI(); $di->setShared('request', new PhalconRequest()); if ($router instanceof PhalconRouterInterface) { $this->router = $router; } elseif ($router === null) { $this->router = new Router(); $this->router->clear(); } else { throw new Exception\RuntimeException('Router has to be an instance of RouterInterface'); } $this->router->setDI($di); $di->setShared('router', $this->router); if ($url instanceof UrlInterface) { $this->url = $url; } elseif ($url === null) { $this->url = new Url(); $this->url->setBaseUri('/'); } else { throw new Exception\RuntimeException('Url has to be an instance of UrlInterface'); } $this->url->setDI($di); }
/** * Set url service when module start * @param Di $di * @param Config $config * @param string $name Module name * @return \Phalex\Events\Listener\Application */ private function setUrlService(Di $di, Config $config, $name) { $base = $static = '/'; if (isset($config['url'])) { $default = isset($config['url']['default']) ? $config['url']['default'] : '/'; if (isset($config['url'][$name])) { $base = isset($config['url'][$name]['uri']) ? $config['url'][$name]['uri'] : $default; $static = isset($config['url'][$name]['static']) ? $config['url'][$name]['static'] : $default; } } $url = new UrlService(); $url->setBaseUri($base); $url->setStaticBaseUri($static); $di->set('url', $url, true); return $this; }
/** * This method is called before a test is executed. */ protected function setUp() { $this->checkExtension('phalcon'); // Reset the DI container Di::reset(); // Instantiate a new DI container $di = new Di(); // Set the URL $di->set('url', function () { $url = new Url(); $url->setBaseUri('/'); return $url; }); $di->set('escaper', function () { return new Escaper(); }); $this->di = $di; }
/** * Registers the module-only services * * @param \Phalcon\DiInterface $di */ public function registerServices($di) { /** * Read application wide and module only configurations */ $appConfig = $di->get('config'); $moduleConfig = (include __DIR__ . '/config/config.php'); $di->set('moduleConfig', $moduleConfig); /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($appConfig) { $url = new UrlResolver(); $url->setBaseUri($appConfig->application->baseUri); return $url; }); /** * Module specific dispatcher */ $di->set('dispatcher', function () use($di) { $dispatcher = new Dispatcher(); $dispatcher->setEventsManager($di->getShared('eventsManager')); $dispatcher->setDefaultNamespace('App\\Modules\\Frontend\\'); return $dispatcher; }); $di->setShared('request', function () use($appConfig) { return new \Phalcon\Http\Request(); }); /** * Include config per environment */ include __DIR__ . '/config/config_' . $appConfig->application->environment . '.php'; $database = $di->getConfig()->application->site . $di->get('request')->getQuery("country_code"); /** * Simple database connection to localhost */ $di->setShared('mongo', function ($config, $database) { $mongo = new \Mongo(); return $mongo->selectDb($config->{$database}->dbname); }, true); $di->setShared('collectionManager', function () { return new \Phalcon\Mvc\Collection\Manager(); }, true); }
/** * Registers the module-only services * * @param \Phalcon\DiInterface $di */ public function registerServices($di) { /** * Read application wide and module only configurations */ $appConfig = $di->get('config'); $moduleConfig = (include __DIR__ . '/config/config.php'); $di->set('moduleConfig', $moduleConfig); /** * Setting up the view component */ $di->set('view', function () { $view = new View(); $view->setViewsDir(__DIR__ . '/../../../public/src/app/modules/leads/views/')->setLayoutsDir('../../../layouts/')->setPartialsDir('../../../partials/')->setTemplateAfter('main')->registerEngines(['.html' => 'Phalcon\\Mvc\\View\\Engine\\Php']); return $view; }); /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($appConfig) { $url = new UrlResolver(); $url->setBaseUri($appConfig->application->baseUri); return $url; }); /** * Module specific dispatcher */ $di->set('dispatcher', function () use($di) { $dispatcher = new Dispatcher(); $dispatcher->setEventsManager($di->getShared('eventsManager')); $dispatcher->setDefaultNamespace('App\\Modules\\Leads\\'); return $dispatcher; }); /** * Module specific database connection */ $di->set('db', function () use($appConfig) { return new DbAdapter(['host' => $moduleConfig->database->host, 'username' => $moduleConfig->database->username, 'password' => $moduleConfig->database->password, 'dbname' => $moduleConfig->database->name]); }); }
/** * Register the services here to make them general or register in the ModuleDefinition to make them module-specific */ public function registerServices(\Phalcon\DiInterface $di) { /** * Read configuration */ $config = (include __DIR__ . "/config/config.php"); /** * Setting up the view component */ // The URL component is used to generate all kind of urls in the application $di->set('url', function () { $url = new Url(); $url->setBaseUri('/'); return $url; }); /** * Setting up the view component */ $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->view->viewsDir); $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]); $view->registerEngines(['.volt' => function () use($view, $config) { $volt = new Volt($view); $volt->setOptions(['compiledPath' => $config->application->view->compiledPath, 'compiledSeparator' => $config->application->view->compiledSeparator, 'compiledExtension' => $config->application->view->compiledExtension, 'compileAlways' => true]); return $volt; }]); // Create an event manager $eventsManager = new EventsManager(); // Attach a listener for type 'view' $eventsManager->attach('view', function ($event, $view) { if ($event->getType() == 'notFoundView') { throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')'); } }); // Bind the eventsManager to the view component $view->setEventsManager($eventsManager); return $view; }); }
/** * Sets the test up by loading the DI container and other stuff * * @author Nikos Dimopoulos <*****@*****.**> * @since 2012-09-30 * @param \Phalcon\DiInterface $di * @param \Phalcon\Config $config * @return void */ protected function setUp(DiInterface $di = null, Config $config = null) { $this->checkExtension('phalcon'); if (!is_null($config)) { $this->config = $config; } if (is_null($di)) { // Reset the DI container DI::reset(); // Instantiate a new DI container $di = new FactoryDefault(); // Set the URL $di->set('url', function () { $url = new Url(); $url->setBaseUri('/'); return $url; }); $di->set('escaper', function () { return new \Phalcon\Escaper(); }); } $this->di = $di; }
public function setBaseUri($baseUri) { return parent::setBaseUri($baseUri); }
use Phalcon\Di\FactoryDefault; use Phalcon\Mvc\Url as UrlProvider; use Phalcon\Db\Adapter\Pdo\Postgresql as DbAdapter; try { // Register an autoloader $loader = new Loader(); $loader->registerDirs(array('../app/controllers/', '../app/models/'))->register(); // Setup the database service $di->set('db', function () { return new DbAdapter(array("host" => "pellefant-01.db.elephantsql.com", "username" => "yxlluzxv", "password" => "XlspU6IwYJrlKnn9drdaRfpRv2PjyFR5", "dbname" => "yxlluzxv")); }); // Create a DI $di = new FactoryDefault(); // Setup the view component $di->set('view', function () { $view = new View(); $view->setViewsDir('../app/views/'); return $view; }); // Setup a base URI so that all generated URIs include the "tutorial" folder $di->set('url', function () { $url = new UrlProvider(); $url->setBaseUri(''); return $url; }); // Handle the request $application = new Application($di); echo $application->handle()->getContent(); } catch (\Exception $e) { echo "Exception: ", $e->getMessage(); }
use Phalcon\DI\FactoryDefault; use Phalcon\Session\Adapter\Files as SessionAdapter; /** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); /** * Registering a router */ $di['router'] = function () { $router = new Router(); $router->setDefaultModule("frontend"); $router->setDefaultNamespace("@@namespace@@\\Frontend\\Controllers"); return $router; }; /** * The URL component is used to generate all kind of urls in the application */ $di['url'] = function () { $url = new UrlResolver(); $url->setBaseUri('/@@name@@/'); return $url; }; /** * Start the session the first time some component request the session service */ $di['session'] = function () { $session = new SessionAdapter(); $session->start(); return $session; };
/** * Initializes the baseUrl * * @param array $options */ protected function initUrl($options = array()) { $config = $this->_di->get('config'); /** * The URL component is used to generate all kind of urls in the * application */ $this->_di->set('url', function () use($config) { $url = new PhUrl(); $url->setBaseUri($config->app->baseUri); return $url; }); }
try { // Register an autoloader $loader = new Loader(); $loader->registerDirs(['../app/controllers/', '../app/models/'])->register(); // Create a DI $di = new FactoryDefault(); // Set the database service $di['db'] = function () { return new DbAdapter(["host" => "localhost", "username" => "root", "password" => "pass", "dbname" => "jdi-cars"]); }; // Setting up the view component $di['view'] = function () { $view = new View(); $view->setViewsDir('../app/views/'); return $view; }; $di['url'] = function () { $url = new Url(); $url->setBaseUri('/'); return $url; }; // Setup the tag helpers $di['tag'] = function () { return new Tag(); }; // Handle the request $application = new Application($di); echo $application->handle()->getContent(); } catch (Exception $e) { echo "Exception: ", $e->getMessage(); }
/** * @param RegisterService $registerService */ public function register(RegisterService $registerService) { $url = new UrlResolver(); $url->setBaseUri('/'); $registerService->getDependencyInjection()->set('url', $url); }
/** * 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(sprintf("Phalcon extension isn't installed, follow these instructions to install it: %s", Script::DOC_INSTALL_URL)); } if ($ip !== null) { self::$ip = $ip; } if (!defined('TEMPLATE_PATH')) { define('TEMPLATE_PATH', $path . '/templates'); } $basePath = dirname(getcwd()); // Dirs for search config file $configDirs = array($basePath . '/config/', $basePath . '/app/config/', $basePath . '/apps/frontend/config/', $basePath . '/apps/backend/config/'); $readed = false; foreach ($configDirs as $configPath) { if (file_exists($configPath . 'config.ini')) { $config = new ConfigIni($configPath . 'config.ini'); $readed = true; break; } else { if (file_exists($configPath . 'config.php')) { $config = (include $configPath . 'config.php'); if (is_array($config)) { $config = new Config($config); } $readed = true; break; } } } if ($readed === false) { throw new Exception(sprintf('Configuration file could not be loaded! Scanned dirs: %s', implode(', ', $configDirs))); } $loader = new 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(sprintf("Your Phalcon version isn't compatible with Developer Tools, download the latest at: %s", Script::DOC_DOWNLOAD_URL)); } 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 Url(); $url->setBaseUri($config->application->baseUri); return $url; }); $di->set('flash', function () { return new Flash(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning')); }); $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 Application(); $app->setDi($di); echo $app->handle()->getContent(); } catch (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()); } }
$crypt->setKey($config->security->cryptKey); return $crypt; }); /** * Access Control List */ $di->set('acl', function () use($di) { $configDir = $di->getConfig()->path->configDir; $aclData = (require "{$configDir}/acl.php"); $acl = new Acl($aclData); return $acl; }); /** * */ $di->setShared('url', function () use($di) { $config = $di->get('config'); $isCurrentlyHttps = $config->server->https; $shouldHttps = $config->security->https; $usingHsts = $config->security->hsts > 0; $proto = $isCurrentlyHttps || $shouldHttps || $usingHsts ? 'https' : 'http'; if ($config->server->domain == '') { $domain = $config->site->domains[0]; } else { $domain = $config->server->domain; } $uri = $config->app->baseUri; $url = new Url(); $url->setBaseUri("{$proto}://{$domain}{$uri}"); return $url; });
);*/ //Github API mock $di->set('github', function () use($config) { $api = m::mock("api"); $api->shouldReceive("show")->with("simple-helpers", "php-file-mover", 8)->andReturn(json_decode(file_get_contents(__DIR__ . "/../_data/8"), true)); $client = m::mock("Github"); $client->shouldReceive("api")->with('pull_request')->andReturn($api); return $client; }, true); /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($config) { $url = new UrlResolver(); if (!$config->application->debug) { $url->setBaseUri($config->application->production->baseUri); $url->setStaticBaseUri($config->application->production->staticBaseUri); } else { $url->setBaseUri($config->application->development->baseUri); $url->setStaticBaseUri($config->application->development->staticBaseUri); } return $url; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { $connection = new DatabaseConnection($config->database->toArray()); $debug = $config->application->debug; if ($debug) { $eventsManager = new EventsManager();
<?php use Phalcon\DI\FactoryDefault; use Phalcon\Mvc\View; use Phalcon\Mvc\Url as UrlResolver; use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; use Phalcon\Mvc\View\Engine\Volt as VoltEngine; use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter; use Phalcon\Session\Adapter\Files as SessionAdapter; $di = new FactoryDefault(); $di->set('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }, true); $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(array('.volt' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_', 'compileAlways' => true)); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }, true); $di->set('db', function () use($config) { return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname, "charset" => $config->database->charset)); }); $di->set('modelsMetadata', function () { return new MetaDataAdapter(); });
/** * Registers the module-only services * * @param \Phalcon\DiInterface $di */ public function registerServices($di) { /** * Read application wide and module only configurations */ $appConfig = $di->get('config'); $moduleConfig = (include __DIR__ . '/config/config.php'); $di->setShared('moduleConfig', $moduleConfig); /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($appConfig) { $url = new UrlResolver(); $url->setBaseUri($appConfig->application->baseUri); return $url; }); }