本文整理汇总了PHP中Phalcon\DI类的典型用法代码示例。如果您正苦于以下问题:PHP DI类的具体用法?PHP DI怎么用?PHP DI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
});
}
示例3: set
/**
* Registers a service in the services container
*
* @param string $name
* @param mixed $definition
* @param boolean $shared
* @throws RuntimeException
* @return \Phalcon\DI\ServiceInterface
*/
public static function set($name, $definition, $shared = null)
{
if (self::$di == null) {
throw new RuntimeException('IoC container is null!');
}
self::$di->set($name, $definition, $shared);
}
示例4: 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);
}
示例5: getFlash
/**
* Return flash instance
*/
protected function getFlash()
{
$flash = new PhFlash($this->classes);
$di = new PhDI();
$di->set('session', new Helper\InMemorySession(), true);
$flash->setDI($di);
return $flash;
}
示例6: getRequestObject
/**
* Initializes the request object and returns it
*
* @author Nikolaos Dimopoulos <nikos@phalconphp.com>
* @since 2014-10-05
*
* @return PhRequest
*/
protected function getRequestObject()
{
PhDI::reset();
$di = new PhDI();
$di->set('filter', function () {
return new PhTFilter();
});
$request = new PhTRequest();
$request->setDI($di);
return $request;
}
示例7: create
/**
* @return DummyLatteTemplateAdapter
*/
public static function create()
{
$view = new PhView();
$di = new PhDi();
$di->set('tag', new PhTag());
$di->set('security', new PhSecurity());
$di->set('url', new PhUrl());
$latteFactory = new LatteFactory();
$latteFactory->setTempDir(TEMP_DIR);
$adapter = new DummyLatteTemplateAdapter($view, $di, $latteFactory);
return $adapter;
}
示例8: setUp
public function setUp()
{
parent::setUp();
$config = DI::getDefault()->get('config');
require_once $config->application->moduleDir . '/Test/forms/Fake.php';
$this->prepareFakeObject();
}
示例9: __construct
/**
* @param DI $di
*/
public function __construct(DI $di = null)
{
if (!class_exists('\\Whoops\\Run')) {
return;
}
if (!$di) {
$di = DI::getDefault();
}
// There's only ever going to be one error page...right?
$di->setShared('whoops.pretty_page_handler', function () use($di) {
return (new DebugbarHandler())->setDi($di);
});
// There's only ever going to be one error page...right?
$di->setShared('whoops.json_response_handler', function () {
$jsonHandler = new JsonResponseHandler();
$jsonHandler->onlyForAjaxRequests(true);
return $jsonHandler;
});
$di->setShared('whoops', function () use($di) {
$run = new Run();
$run->silenceErrorsInPaths(array('/phalcon-debugbar/'), E_ALL);
$run->pushHandler($di['whoops.pretty_page_handler']);
$run->pushHandler($di['whoops.json_response_handler']);
return $run;
});
$di['whoops']->register();
}
示例10: getTableName
/**
* Get table name.
*
* @return string
*/
public static function getTableName()
{
$reader = DI::getDefault()->get('annotations');
$reflector = $reader->get(get_called_class());
$annotations = $reflector->getClassAnnotations();
return $annotations->get('Source')->getArgument(0);
}
示例11: __construct
/**
* @param array $options
* @throws \Exception
*/
public function __construct($options = array())
{
if (empty($options)) {
$options = array('db' => DI::getDefault()->get('mongo'), 'roles' => 'vegas_acl_roles', 'resources' => 'vegas_acl_resources', 'resourcesAccesses' => 'vegas_acl_resources_accesses', 'accessList' => 'vegas_acl_access_list');
}
if (!is_array($options)) {
throw new Exception("Acl options must be an array");
}
if (!isset($options['db'])) {
throw new Exception("Parameter 'db' is required");
}
if (!isset($options['roles'])) {
throw new Exception("Parameter 'roles' is required");
}
if (!isset($options['resources'])) {
throw new Exception("Parameter 'resources' is required");
}
if (!isset($options['resourcesAccesses'])) {
throw new Exception("Parameter 'resourcesAccesses' is required");
}
if (!isset($options['accessList'])) {
throw new Exception("Parameter 'accessList' is required");
}
$this->options = $options;
$this->_defaultAccess = Acl::DENY;
}
示例12: send
public function send()
{
$di = \Phalcon\DI::getDefault();
$res = $di->get('response');
$req = $di->get('request');
//query string, filter, default
if (!$req->get('suppress_response_codes', null, null)) {
$res->setStatusCode($this->getCode(), $this->response)->sendHeaders();
} else {
$res->setStatusCode('200', 'OK')->sendHeaders();
}
$error = array('errorCode' => $this->getCode(), 'userMessage' => $this->getMessage(), 'devMessage' => $this->devMessage, 'more' => $this->additionalInfo, 'applicationCode' => $this->errorCode);
if (!$req->get('type') || $req->get('type') == 'json' | $req->get('type') == 'option') {
$response = new JSONResponse();
$response->send($error, true);
return;
} else {
if ($req->get('type') == 'xml') {
$response = new XMLResponse();
$response->send($error, true);
return;
} else {
if ($req->get('type') == 'csv') {
$response = new CSVResponse();
$response->send(array($error));
return;
}
}
}
error_log('HTTPException: ' . $this->getFile() . ' at ' . $this->getLine());
return true;
}
示例13: __construct
/**
* Create regex validator.
*
* @param array $params Validator parameters.
*/
public function __construct($params = [])
{
if (isset($params['message'])) {
$params['message'] = DI::getDefault()->get('i18n')->_($params['message']);
}
parent::__construct($params);
}
示例14: testSerialization
public function testSerialization()
{
$router = \Phalcon\DI::getDefault()->getShared('router');
$serialized = serialize($router);
$unserialized = unserialize($serialized);
$this->assertEquals($unserialized, $router);
}
示例15: getDi
/**
* Get DI
*
* @return DI
*/
public function getDi()
{
if (empty($this->di)) {
$this->di = DI::getDefault();
}
return $this->di;
}