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(); }
/** * @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; }
/** * 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); }); } }
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; }); }
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; } }); }
/** * @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); }
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 }
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; }); }
public static function staticReset() { static::$router === null and static::$router = static::$di->getShared('router'); static::$router->reset(); }
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; }
public static function __callStatic($name, $arguments) { static::$session or static::$session = static::$di->getShared('session'); return call_user_func_array([static::$session, $name], $arguments); }
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']); }
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); }
$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());
public function getShared($name, $parameters = null) { return parent::getShared($name, $parameters); }
public static function reset($keyName) { static::$adapter === null and static::$adapter = static::$di->getShared('counter'); return static::$adapter->reset($keyName); }
public static function set($key, $value, $ttl = null) { static::$cache === null and static::$cache = static::$di->getShared('cache'); static::$cache->save($key, $value, $ttl); }