本文整理汇总了PHP中di函数的典型用法代码示例。如果您正苦于以下问题:PHP di函数的具体用法?PHP di怎么用?PHP di使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了di函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: report
/**
* Processes the error, fatal and exceptions
*/
protected function report()
{
# - let monolog handle the logging in the errors,
# unless you want it to, you can refer to method
# handleExceptionError()
MonologErrorHandler::register(di()->get('log'));
# - register all the the loggers we have
register_shutdown_function([$this, 'handleFatalError']);
set_error_handler([$this, 'handleError']);
set_exception_handler([$this, 'handleExceptionError']);
}
示例2: __construct
public function __construct()
{
$this->request = di()->get('request');
$this->session = di()->get('session');
$this->response = di()->get('response');
$this->security = di()->get('security');
}
示例3: __get
public function __get($name)
{
if (di()->has($name) === false) {
throw new InvalidArgumentException("Dependency Injection [{$name}] not found");
}
return di()->get($name);
}
示例4: boot
/**
* Loads all services.
*
* return void
*/
public function boot()
{
$providers_loaded = array_map(function ($provider) {
# check if module function exists
if (method_exists($provider, 'module')) {
di('module')->setModule($provider->getAlias(), function ($di) use($provider) {
call_user_func_array([$provider, 'module'], [$di]);
});
}
# callRegister should return an empty or an object or array
# then we could manually update the register
if ($register = $provider->callRegister()) {
di()->set($provider->getAlias(), $register, $provider->getShared());
}
return $provider;
}, $this->providers);
# this happens when some application services relies on other service,
# iterate the loaded providers and call the boot() function
foreach ($providers_loaded as $provider) {
$boot = $provider->boot();
if ($boot && !di()->has($provider->getAlias())) {
di()->set($provider->getAlias(), $boot, $provider->getShared());
}
}
}
示例5: testHandle
public function testHandle()
{
$app = $this->setUp();
$resolver = di('resolver');
$resolver->set('dispatch:controller', function () {
return '\\Engine\\Tests\\Application\\Sample';
});
$resolver->set('dispatch:forward', function ($controller, $module) {
return '\\Engine\\Tests\\Application\\Another';
});
$sources = ['/blog/add' => ['action' => 'add', 'response' => 'test'], '/blog/view' => ['action' => 'view', 'exception' => 'Phalcon\\Mvc\\Dispatcher\\Exception'], '/blog/forward' => ['action' => 'forward', 'response' => 'my_action']];
$router = di('router');
foreach ($sources as $uri => $source) {
$router->add($uri, "Blog::Index::{$source['action']}");
try {
$app->handle($uri);
$response = di('dispatcher')->getReturnedValue();
$this->assertEquals($source['response'], $response);
} catch (\Exception $e) {
if (isset($source['exception'])) {
$this->assertInstanceOf($source['exception'], $e);
} else {
echo $e->getMessage();
dd($e->getTraceAsString());
}
}
}
}
示例6: initialize
public function initialize()
{
# - the code below is hard-coded, you can add it by fetching your
# database table and loop into it and change the 'guest' to something
# that you've stored.
di()->get('acl')->addRole(new PhalconRole('guest'));
}
示例7: tearDown
public function tearDown()
{
$compiled_file = 'storage/slayer/compiled.php';
if (file_exists($compiled_file)) {
di()->get('flysystem')->delete($compiled_file);
}
}
示例8: boot
public function boot()
{
$app = di()->get('application');
$event_manager = new EventsManager();
$event_manager->attach('application', new ApplicationEventListener());
$app->setEventsManager($event_manager);
}
示例9: boot
public function boot()
{
$dispatcher = di()->get('dispatcher');
$event_manager = new EventsManager();
$event_manager->attach('dispatch', new DispatcherEventListener());
$dispatcher->setEventsManager($event_manager);
}
示例10: _validateMessage
/**
* validate message
*/
protected function _validateMessage($message)
{
if (!$message) {
di('log')->record("message not found at " . date('Y-m-d H:i:s'));
exit;
}
// 已處理過的 message 將不再處理
if ($message->getIsUsed()) {
di('log')->record("message {$id} is used");
exit;
}
// 回應的 chat_id 必須在白名單之內
$chatId = $message->getChatId();
$allowIds = conf('bot.allow_chat_ids');
if (!in_array($chatId, $allowIds)) {
di('log')->record("message can not allow send to {$chatId} ({$message->getName()})");
// debug -> 如果不在予許的名單內, 發送警告訊息
if (isTraining()) {
$userId = $message->getUserId();
$text = '您不在白名單之內 by BOT';
BotHelper::sendMessage($userId, $text);
}
exit;
}
}
示例11: render
public function render($path, $params = [])
{
$path = str_replace($this->getView()->getViewsDir(), '', $path);
$path = str_replace('.blade.php', '', $path);
$blade = new Blade($this->getView()->getViewsDir(), storage_path('views') . '/');
di()->get('view')->setContent($blade->make($path, $params)->render());
}
示例12: checkViewPath
/**
*
* @return bool
*/
public function checkViewPath($path)
{
$full_path = di()->get('view')->getViewsDir() . $path;
$result = glob($full_path . '.*');
if (!$result) {
throw new ViewFileNotFoundException('Views file path(' . $full_path . ') not found.');
}
}
示例13: handle
public function handle($e)
{
$content = di()->get('view')->take('errors.whoops', ['e' => $e]);
$response = di('response');
$response->setContent($content);
$response->setStatusCode(self::STATUS_CODE);
return $response->send();
}
示例14: onBoot
public function onBoot()
{
// TODO: Implement onBoot() method.
$this->getDI()->set(ViewContract::class, View::class);
$this->getDI()->setShared('view', function () {
return di(ViewContract::class);
});
}
示例15: register
/**
* {@inheridoc}.
*/
public function register()
{
$manager = $this->manager();
di()->set('flysystem_manager', function () use($manager) {
return $manager;
}, true);
return $manager->getFilesystem(config()->app->flysystem);
}