本文整理汇总了PHP中Phalcon\DI::setShared方法的典型用法代码示例。如果您正苦于以下问题:PHP DI::setShared方法的具体用法?PHP DI::setShared怎么用?PHP DI::setShared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DI
的用法示例。
在下文中一共展示了DI::setShared方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Set up test vars
*
* @return void
* @author Dan Cox
*/
public function setUp()
{
$di = new DI();
$di->setShared('output', new Output());
$di->setShared('input', new Input());
$this->helpers = new Helpers($di);
}
示例2: setUp
public function setUp()
{
$this->di = \Phalcon\DI::getDefault();
$this->di->setShared('environment', function () {
return \Vegas\Constants::TEST_ENV;
});
$this->di->setShared('view', function () {
return 'fake-view';
});
}
示例3: registerServices
/**
* @param DI $di
*/
public function registerServices($di)
{
//Registering a dispatcher
$di->setShared('dispatcher', function () use($di) {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Admin");
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('dispatch', new AdminSecurity($di));
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
$auto_admin = new \AutoAdmin\Module();
$auto_admin->registerServices($di);
$di->setShared('admin_views_dir', function () {
return ADMINROOT . '/views/';
});
$di->setShared('session', function () {
$session = new Session();
$session->start();
return $session;
});
$di->setShared('config', function () use($di) {
$configFront = (require COREROOT . '/app/config/config.php');
$configBack = (require ADMINROOT . '/config/config.php');
$configFront->merge($configBack);
return $configFront;
});
}
示例4: setUp
/**
* Initialize testing object
*
* @uses Auth
* @uses \ReflectionClass
*/
public function setUp()
{
$this->di = new FactoryDefault();
$this->di->reset();
// Setup DI
$this->di = new DI();
$this->di->setShared('session', function () {
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
$this->di->set('tag', function () {
$tag = new \Phalcon\Tag();
return $tag;
});
$this->di->set('escaper', function () {
$escaper = new \Phalcon\Escaper();
return $escaper;
});
DI::setDefault($this->di);
$this->reflection = new \ReflectionClass('ULogin\\Auth');
$this->auth = new Auth();
}
示例5: __construct
/**
* @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);
}
示例6: _initEngine
/**
* Init engine.
*
* @param DI $di Dependency Injection.
*
* @return void
*/
protected function _initEngine($di)
{
$di->setShared('transactions', function () {
$manager = new TxManager();
return $manager->setDbService("dbMaster");
});
}
示例7: registerServices
/**
* Registration services for specific module
* @param \Phalcon\DI $di
* @access public
* @return mixed
*/
public function registerServices($di)
{
// Dispatch register
$di->set('dispatcher', function () use($di) {
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('dispatch:beforeException', new \Plugins\Dispatcher\NotFoundPlugin());
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace('Modules\\' . self::MODULE . '\\Controllers');
return $dispatcher;
}, true);
// Registration of component representations (Views)
$di->set('view', function () {
$view = new View();
$view->setViewsDir($this->_config['application']['viewsBack'])->setMainView('auth-layout')->setPartialsDir('partials');
return $view;
});
require_once APP_PATH . '/Modules/' . self::MODULE . '/config/services.php';
// call profiler
if ($this->_config->database->profiler === true) {
new \Plugins\Debugger\Develop($di);
}
if (APPLICATION_ENV == 'development') {
// share Fabfuel topbar
$profiler = new \Fabfuel\Prophiler\Profiler();
$di->setShared('profiler', $profiler);
$pluginManager = new \Fabfuel\Prophiler\Plugin\Manager\Phalcon($profiler);
$pluginManager->register();
// add toolbar in your basic BaseController
}
return;
}
示例8: _initSession
/**
* Init session.
*
* @param DI $di Dependency Injection.
* @param Config $config Config object.
*
* @return SessionAdapter
*/
protected function _initSession($di, $config)
{
$session = new \Phalcon\Session\Adapter\Redis(['path' => "tcp://127.0.0.1:6379?weight=1", 'persistent' => false, 'lifetime' => 3600, 'prefix' => '_haraapp_']);
$session->start();
$di->setShared('session', $session);
return $session;
}
示例9: buildContainer
private function buildContainer()
{
$container = new Container();
$container->setShared('service_container', $container);
$container->setShared('config', $this->config);
foreach ($this->getServices() as $name => $definition) {
$container->setShared($name, $definition);
}
return $container;
}
示例10: _initEngine
/**
* Init engine.
*
* @param DI $di Dependency Injection.
*
* @return void
*/
protected function _initEngine($di)
{
foreach ($di->get('registry')->modules as $module) {
// Initialize module api.
$di->setShared(strtolower($module), function () use($module, $di) {
return new ApiInjector($module, $di);
});
}
$di->setShared('transactions', function () {
return new TxManager();
});
$di->setShared('assets', new AssetsManager($di));
$di->setShared('widgets', new Catalog());
}
示例11: registerConfigurations
/**
* Register configurations
* @param Phalcon\DI $di
*/
private function registerConfigurations($di)
{
$di->setShared('config', function () {
return new \Phalcon\Config\Adapter\Ini(self::CONFIG_FILE);
});
}
示例12: _initSession
/**
* Init session.
*
* @param DI $di Dependency Injection.
* @param Config $config Config object.
*
* @return SessionAdapter
*/
protected function _initSession($di, $config)
{
$session = new PhSessionFiles();
$session->start();
$di->setShared('session', $session);
return $session;
}