本文整理汇总了PHP中Phalcon\Di::getShared方法的典型用法代码示例。如果您正苦于以下问题:PHP Di::getShared方法的具体用法?PHP Di::getShared怎么用?PHP Di::getShared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Di
的用法示例。
在下文中一共展示了Di::getShared方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public static function register(Di $di)
{
static::$di = $di;
static::$config = Config::get('auth');
$di->setShared('auth', function () {
$di = static::$di;
$config = static::$config;
$class = $config['adapter'];
$options = $config['options'];
strpos($class, '\\') === false and $class = 'Phwoolcon\\Auth\\Adapter\\' . $class;
if ($di->has($class)) {
$class = $di->getRaw($class);
}
if (!class_exists($class)) {
throw new Exception('Admin auth adapter class should implement ' . AdapterInterface::class);
}
/* @var Security $hasher */
$hasher = static::$di->getShared('security');
$hasher->setDefaultHash($options['security']['default_hash']);
$hasher->setWorkFactor($options['security']['work_factor']);
$adapter = new $class($options, $hasher, $di);
if (!$adapter instanceof AdapterInterface) {
throw new Exception('Auth adapter class should implement ' . AdapterInterface::class);
}
return $adapter;
});
static::addPhwoolconJsOptions();
}
示例2: run
/**
* @param array|Payload $payload
* @return Payload
* @throws GeneralException
*/
public static function run($payload)
{
static::$instance === null and static::$instance = static::$di->getShared('payment');
$payload instanceof Payload or $payload = Payload::create($payload);
$paymentMethod = static::$instance->getPaymentMethod($payload->getGateway(), $payload->getMethod());
$payload->setResult($paymentMethod->process($payload));
return $payload;
}
示例3: register
/**
* Fix over clever di service resolver in phalcon 2.1.x:
* let definition = \Closure::bind(definition, dependencyInjector)
* which leads to php warning "Cannot bind an instance to a static closure"
*
* @param Di $di
* @codeCoverageIgnore
*/
public static function register(Di $di)
{
if ($_SERVER['PHWOOLCON_PHALCON_VERSION'] > '2010000') {
$di->setInternalEventsManager($di->getShared('eventsManager'));
Events::attach('di:beforeServiceResolve', function (Event $event) {
/* @var Di $di */
$di = $event->getSource();
$data = $event->getData();
$name = $data['name'];
$parameters = $data['parameters'];
if (!isset($di->_services[$name])) {
return false;
}
/* @var Di\Service $service */
$service = $di->_services[$name];
if (!$service->isShared()) {
return false;
}
if (!($definition = $service->getDefinition()) instanceof Closure) {
return false;
}
return $parameters ? call_user_func_array($definition, $parameters) : call_user_func($definition);
});
}
}
示例4: injectTo
public static function injectTo(Di $di)
{
/** @var Dispatcher $dispatcher */
$dispatcher = $di->getShared('dispatcher');
$dispatcher->getEventsManager()->attach('dispatch:beforeException', function (Event $event, Dispatcher $dispatcher, \Exception $e) {
/** @var \Phalcon\Logger\AdapterInterface $logger */
$logger = $dispatcher->getDI()->get('logger');
$logger->error($e->getMessage());
if ($dispatcher instanceof Mvc\Dispatcher) {
if ($e instanceof Mvc\Dispatcher\Exception) {
$action = 'notFound';
} else {
$action = 'fatal';
if ($dispatcher->getDI()->has('response')) {
/** @var \Phalcon\Http\Response $response */
$response = $dispatcher->getDI()->get('response');
$response->setStatusCode(500, "Internal Server Error");
}
}
$dispatcher->setNamespaceName($dispatcher->getDefaultNamespace());
$dispatcher->forward(['controller' => 'error', 'action' => $action]);
}
return false;
});
}
示例5: injectTo
public static function injectTo(Di $di)
{
/** @var Dispatcher $dispatcher */
$dispatcher = $di->getShared('dispatcher');
$dispatcher->getEventsManager()->attach('dispatch:beforeException', function (Event $event, Dispatcher $dispatcher, \Throwable $e) {
if ($dispatcher instanceof Mvc\Dispatcher) {
$dispatcher->setNamespaceName($dispatcher->getDefaultNamespace());
$dispatcher->forward(['controller' => 'error', 'action' => 'index', 'params' => ['exception' => $e]]);
return false;
}
});
}
示例6: profileReceive
/**
* @param SwooleServer $server
* @param $fd
* @param $fromId
* @param $data
* @codeCoverageIgnore
*/
public function profileReceive(SwooleServer $server, $fd, $fromId, $data)
{
xhprof_enable(0, ['ignored_functions' => ['call_user_func', 'call_user_func_array']]);
$this->onReceive($server, $fd, $fromId, $data);
$microTime = explode(' ', microtime());
/* @var Router $router */
$router = static::$di->getShared('router');
$pathInfo = strtr($router->getRewriteUri(), ['/' => '|']);
$reportFile = $microTime[1] . '-' . substr($microTime[0], 2) . '-' . $_SERVER['REQUEST_METHOD'] . $pathInfo;
$this->profiler or $this->profiler = new XHProfRuns_Default($this->profilerDir);
$this->profiler->save_run(xhprof_disable(), 'service', $reportFile);
}
示例7: reconnect
public static function reconnect($name = null)
{
static::$instance === null and static::$instance = static::$di->getShared('dbManager');
$db = static::$instance;
$db->disconnect($name = $name ?: $db->config['default']);
if (isset($db->connections[$name])) {
$db->connections[$name]->connect();
return $db->connections[$name];
}
// @codeCoverageIgnoreStart
return static::connection($name);
// @codeCoverageIgnoreEnd
}
示例8: register
public static function register(Di $di)
{
static::$di = $di;
$di->set('Phalcon\\Http\\Cookie', 'Phwoolcon\\Http\\Cookie');
static::$cookies = static::$di->getShared('cookies');
static::$cookies->reset();
static::$options = $options = Config::get('cookies');
static::$cookies->useEncryption($encrypt = $options['encrypt']);
$encrypt and static::$di->getShared('crypt')->setKey($options['encrypt_key'])->setPadding(Crypt::PADDING_ZERO);
/* @var \Phalcon\Http\Response $response */
if ($response = $di->getShared('response')) {
$response->setCookies(static::$cookies);
}
Events::attach('view:generatePhwoolconJsOptions', function (Event $event) {
$options = $event->getData() ?: [];
$options['cookies'] = ['domain' => static::$options['domain'], 'path' => static::$options['path']];
$event->setData($options);
return $options;
});
}
示例9: staticReset
public static function staticReset()
{
static::$router === null and static::$router = static::$di->getShared('router');
static::$router->reset();
}
示例10: useMultiLocale
public static function useMultiLocale($flag = null)
{
static::$instance or static::$instance = static::$di->getShared('i18n');
$flag === null or static::$instance->multiLocale = (bool) $flag;
return static::$instance->multiLocale;
}
示例11: __callStatic
public static function __callStatic($name, $arguments)
{
static::$session or static::$session = static::$di->getShared('session');
return call_user_func_array([static::$session, $name], $arguments);
}
示例12: noHeader
public static function noHeader($flag = null)
{
static::$instance or static::$instance = static::$di->getShared('view');
$flag === null or static::$instance->_options['no_header'] = (bool) $flag;
return !empty(static::$instance->_options['no_header']);
}
示例13: fire
public static function fire($eventType, $source, $data = null, $cancelable = true)
{
static::$event or static::$event = static::$di->getShared('eventsManager');
return static::$event->fire($eventType, $source, $data, $cancelable);
}
示例14: function
$di->set('response', 'Phalcon\\Http\\Response');
//Registering the view component
$di->set('view', function () {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../apps/views/');
return $view;
});
$di->set('db', function () {
return new Database(array("host" => "localhost", "username" => "root", "password" => "", "dbname" => "invo"));
});
//Registering the Models-Metadata
$di->set('modelsMetadata', 'Phalcon\\Mvc\\Model\\Metadata\\Memory');
//Registering the Models Manager
$di->set('modelsManager', 'Phalcon\\Mvc\\Model\\Manager');
try {
$router = $di->getShared('router');
$router->handle();
$view = $di->getShared('view');
$dispatcher = $di->getShared('dispatcher');
$dispatcher->setControllerName($router->getControllerName());
$dispatcher->setActionName($router->getActionName());
$dispatcher->setParams($router->getParams());
//Start the view
$view->start();
//Dispatch the request
$dispatcher->dispatch();
$view->render($dispatcher->getControllerName(), $dispatcher->getActionName(), $dispatcher->getParams());
$view->finish();
$response = $di->getShared('response');
//Pass the output of the view to the response
$response->setContent($view->getContent());
示例15: getShared
public function getShared($name, $parameters = null)
{
return parent::getShared($name, $parameters);
}