2015-01-29 01:50:29 +05:30
|
|
|
<?php
|
2015-10-15 16:31:23 +05:30
|
|
|
/**
|
|
|
|
* @var \Phalcon\Config $config
|
|
|
|
*/
|
2015-01-29 01:50:29 +05:30
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
use Phalcon\Mvc\Collection\Manager;
|
2015-01-29 01:50:29 +05:30
|
|
|
use Phalcon\Mvc\View;
|
|
|
|
use Phalcon\Mvc\Url as UrlResolver;
|
|
|
|
use Phalcon\DI\FactoryDefault;
|
|
|
|
|
|
|
|
$di = new FactoryDefault();
|
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
$di->set('view', function () {
|
|
|
|
$view = new View();
|
2015-01-29 01:50:29 +05:30
|
|
|
$view->disable();
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The URL component is used to generate all kind of urls in the application
|
|
|
|
*/
|
2015-10-15 16:31:23 +05:30
|
|
|
$di->set('url', function () use ($config) {
|
2015-01-29 01:50:29 +05:30
|
|
|
$url = new UrlResolver();
|
|
|
|
$url->setBaseUri($config->application->baseUri);
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
});
|
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
$di->set('mongo', function() use ($config) {
|
|
|
|
/** @var StdClass $mongoConfig */
|
|
|
|
$mongoConfig = $config->mongo;
|
|
|
|
$connectionString = 'mongodb://';
|
|
|
|
if ($mongoConfig->username && $mongoConfig->password) {
|
|
|
|
$connectionString .= "{$mongoConfig->username}:{$mongoConfig->password}@";
|
2015-01-29 01:50:29 +05:30
|
|
|
}
|
|
|
|
|
2015-10-15 16:31:23 +05:30
|
|
|
$connectionString .= $mongoConfig->host . ':' . $mongoConfig->port;
|
|
|
|
$mongo = new MongoClient($connectionString);
|
|
|
|
|
|
|
|
return $mongo->selectDb($mongoConfig->dbname);
|
2015-01-29 01:50:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
$di->setShared('collectionManager', function() {
|
2015-10-15 16:31:23 +05:30
|
|
|
return new Manager();
|
|
|
|
});
|