123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- define('APP_PATH', realpath('..'));
- try {
- // Load the config
- $config = include APP_PATH . "/app/config/config.php";
- // Register an autoloader
- $loader = new \Phalcon\Loader();
- $loader->registerDirs(array(
- $config->application->controllersDir,
- $config->application->modelsDir
- ))->register();
- // Create a DI
- $di = new Phalcon\DI\FactoryDefault();
- // Setting up the router
- $di->set('router', require APP_PATH . '/app/config/routes.php');
- //MetaData
- $di->set('modelsMetadata', function(){
- if (function_exists('apc_store')) {
- return new Phalcon\Mvc\Model\MetaData\Apc();
- } else {
- return new Phalcon\Mvc\Model\MetaData\Files(array(
- 'metaDataDir' => APP_PATH . "/app/compiled-templates/"
- ));
- }
- });
- // Setting up the view component (seems to be required even when not used)
- $di->set('view', function() use ($config) {
- $view = new \Phalcon\Mvc\View();
- $view->setViewsDir($config->application->viewsDir);
- $view->registerEngines(array(
- ".volt" => function($view, $di) {
- $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
- $volt->setOptions(array(
- "compiledPath" => APP_PATH . "/app/compiled-templates/",
- "compiledExtension" => ".compiled",
- "compiledSeparator" => '_',
- ));
- return $volt;
- }
- ));
- return $view;
- });
- // Setting up the database connection
- $di->set('db', function() use ($config) {
- $database = $config->database;
- return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
- 'host' => $database->host,
- 'username' => $database->username,
- 'password' => $database->password,
- 'dbname' => $database->name,
- 'options' => array(
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
- )
- ));
- });
- // Setting up the mongodb connection
- $di->set('mongo', function() use ($config) {
- $mongodbConfig = $config->mongodb;
-
- $mongo = new \MongoClient($mongodbConfig->url);
- return $mongo->{$mongodbConfig->db};
- });
-
- //Registering the collectionManager service
- $di->set('collectionManager', function() {
- // Setting a default EventsManager
- $modelsManager = new Phalcon\Mvc\Collection\Manager();
- $modelsManager->setEventsManager(new Phalcon\Events\Manager());
- return $modelsManager;
- }, true);
- // Handle the request
- $application = new \Phalcon\Mvc\Application();
- $application->setDI($di);
- echo $application->handle()->getContent();
- } catch(\Phalcon\Exception $e) {
- echo "PhalconException: ", $e->getMessage();
- }
|