chrly/config/services.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2015-01-29 01:50:29 +05:30
<?php
/**
* @var \Phalcon\Config $config
*/
2015-01-29 01:50:29 +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();
$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
*/
$di->set('url', function () use ($config) {
2015-01-29 01:50:29 +05:30
$url = new UrlResolver();
$url->setBaseUri($config->application->baseUri);
return $url;
});
$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
}
$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() {
return new Manager();
});