public function fire() { $clearAll = true; if ($this->input->getOption('config-only')) { $clearAll = false; Config::clearCache(); $this->info('Config cache cleared.'); } if ($this->input->getOption('meta-only')) { $clearAll = false; Db::clearMetadata(); $this->info('Model metadata cleared.'); } if ($this->input->getOption('locale-only')) { $clearAll = false; I18n::clearCache(); $this->info('Locale cache cleared.'); } if ($this->input->getOption('assets-only')) { $clearAll = false; View::clearAssetsCache(); $this->info('Assets cache cleared.'); } if ($clearAll) { Cache::flush(); Config::clearCache(); $this->info('Cache cleared.'); } Events::fire('cache:after_clear', $this); }
public function testDetachEvent() { Events::detachAll($eventType = 'test:fireAndCatchEvent'); Events::attach($eventType, $handler = function (Event $event) { /* @var static $obj */ $obj = $event->getSource(); $obj->eventChangeValue = true; }); $this->eventChangeValue = false; Events::detach($eventType, $handler); Events::fire($eventType, $this); $this->assertFalse($this->eventChangeValue, 'Event not detached'); }
public static function dispatch($uri = null) { try { static::$router === null and static::$router = static::$di->getShared('router'); $router = static::$router; // @codeCoverageIgnoreStart if (!$uri && $router->_sitePathLength && $router->_uriSource == self::URI_SOURCE_GET_URL) { list($uri) = explode('?', $_SERVER['REQUEST_URI']); $uri = str_replace(basename($_SERVER['SCRIPT_FILENAME']), '', $uri); if (substr($uri, 0, $router->_sitePathLength) == $router->_sitePathPrefix) { $uri = substr($uri, $router->_sitePathLength); } } // @codeCoverageIgnoreEnd Events::fire('router:before_dispatch', $router, ['uri' => $uri]); $router->handle($uri); $route = $router->getMatchedRoute() or static::throw404Exception(); static::$disableSession or Session::start(); static::$disableCsrfCheck or static::checkCsrfToken(); if (($controllerClass = $router->getControllerName()) instanceof Closure) { $response = $controllerClass(); if (!$response instanceof Response) { /* @var Response $realResponse */ $realResponse = static::$di->getShared('response'); $realResponse->setContent($response); $response = $realResponse; } } else { /* @var Controller $controller */ $controller = new $controllerClass(); method_exists($controller, 'initialize') and $controller->initialize(); method_exists($controller, $method = $router->getActionName()) or static::throw404Exception(); $controller->{$method}(); $response = $controller->response; } Events::fire('router:after_dispatch', $router, ['response' => $response]); Session::end(); return $response; } catch (HttpException $e) { Log::exception($e); return static::$runningUnitTest ? $e : $e->toResponse(); } }
public static function getPhwoolconJsOptions() { static::$instance or static::$instance = static::$di->getShared('view'); $options = Events::fire('view:generatePhwoolconJsOptions', static::$instance, ['baseUrl' => url('')]) ?: []; return $options; }
/** * Take order actions such as cancel, confirm, complete, fail, and so on * You can extend your custom action by modifying property $this->fsmActions and $this->fsmTransitions * * @param string $method * @param array $arguments */ protected function takeAction($method, $arguments) { $action = lcfirst($method); $options = $this->fsmActions[$method]; $comment = empty($arguments[0]) ? __($options['default_comment']) : $arguments[0]; if (!$this->getFsm()->canDoAction($action)) { throw new OrderException(__($options['error_message'], ['status' => $this->getStatus()]), $options['error_code']); } /** * Fire before action events * * @see OrderFsmTrait::beforeCancel(); Event type: "order:before_cancel" * @see OrderFsmTrait::beforeComplete(); Event type: "order:before_complete" * @see OrderFsmTrait::beforeConfirm(); Event type: "order:before_confirm" * @see OrderFsmTrait::beforeConfirmCancel(); Event type: "order:before_confirm_cancel" * @see OrderFsmTrait::beforeConfirmFail(); Event type: "order:before_confirm_fail" * @see OrderFsmTrait::beforeFail(); Event type: "order:before_fail" */ Events::fire('order:before_' . $action, $this); method_exists($this, $beforeMethod = 'before' . $method) and $this->{$beforeMethod}(); $status = $this->getFsm()->doAction($action); $this->updateStatus($status, $comment)->refreshFsmHistory(); /** * Fire after action events * * @see OrderFsmTrait::afterCancel(); Event type: "order:after_cancel" * @see OrderFsmTrait::afterComplete(); Event type: "order:after_complete" * @see OrderFsmTrait::afterConfirm(); Event type: "order:after_confirm" * @see OrderFsmTrait::afterConfirmCancel(); Event type: "order:after_confirm_cancel" * @see OrderFsmTrait::afterConfirmFail(); Event type: "order:after_confirm_fail" * @see OrderFsmTrait::afterFail(); Event type: "order:after_fail" */ method_exists($this, $afterMethod = 'after' . $method) and $this->{$afterMethod}(); Events::fire('order:after_' . $action, $this); }