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);
 }
Beispiel #2
0
 /**
  * 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);
         });
     }
 }
Beispiel #3
0
 protected static function addPhwoolconJsOptions()
 {
     Events::attach('view:generatePhwoolconJsOptions', function (Event $event) {
         $config = static::$config;
         $options = $event->getData() ?: [];
         $options['isSsoServer'] = true;
         $event->setData($options = array_merge($options, $config['phwoolcon_js_options']));
         return $options;
     });
 }
Beispiel #4
0
 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');
 }
Beispiel #5
0
 public function __construct($config)
 {
     $this->config = $config;
     $ormOptions = $config['orm_options'];
     $ormOptions['distributed'] = $config['distributed'];
     Model::setup($ormOptions);
     if (fnGet($this->config, 'query_log')) {
         Events::attach('db:beforeQuery', function (Event $event) {
             /* @var Adapter $adapter */
             $adapter = $event->getSource();
             $binds = $adapter->getSqlVariables();
             Log::debug($adapter->getSQLStatement() . '; binds = ' . var_export($binds, 1));
         });
     }
 }
Beispiel #6
0
 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;
     });
 }
Beispiel #7
0
 public function setUp()
 {
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId();
     /* @var Di $di */
     $di = $this->di = Di::getDefault();
     Events::register($di);
     DiFix::register($di);
     Db::register($di);
     Cache::register($di);
     Log::register($di);
     Config::register($di);
     Counter::register($this->di);
     Aliases::register($di);
     I18n::register($di);
     Cookies::register($di);
     Session::register($di);
     Cache::flush();
     Config::clearCache();
     parent::setUp();
     $class = get_class($this);
     Log::debug("================== Running {$class}::{$this->getName()}() ... ==================");
     Timer::start();
 }
Beispiel #8
0
 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();
     }
 }
Beispiel #9
0
 public static function getPhwoolconJsOptions()
 {
     static::$instance or static::$instance = static::$di->getShared('view');
     $options = Events::fire('view:generatePhwoolconJsOptions', static::$instance, ['baseUrl' => url('')]) ?: [];
     return $options;
 }
Beispiel #10
0
use Phalcon\Version;
use Phwoolcon\Aliases;
use Phwoolcon\Cache;
use Phwoolcon\Config;
use Phwoolcon\Cookies;
use Phwoolcon\Db;
use Phwoolcon\DiFix;
use Phwoolcon\Events;
use Phwoolcon\I18n;
use Phwoolcon\Log;
use Phwoolcon\Queue;
use Phwoolcon\Router;
use Phwoolcon\Session;
use Phwoolcon\Util\Counter;
use Phwoolcon\View;
$_SERVER['PHWOOLCON_PHALCON_VERSION'] = Version::getId();
Events::register($di);
DiFix::register($di);
Db::register($di);
Cache::register($di);
Log::register($di);
Config::register($di);
Counter::register($di);
Aliases::register($di);
Router::register($di);
I18n::register($di);
Cookies::register($di);
Session::register($di);
View::register($di);
Queue::register($di);
$loader->registerNamespaces(Config::get('app.autoload.namespaces', []), true);
Beispiel #11
0
 /**
  * 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);
 }
Beispiel #12
0
 /**
  * Resolve service aware components
  * Each component will be reset before every request is handled
  */
 protected function prepareServiceAwareComponents()
 {
     /* @var Di\Service $service */
     foreach (static::$di->getServices() as $name => $service) {
         if (!$service->isShared()) {
             continue;
         }
         $component = static::$di->getShared($name);
         if ($component instanceof ServiceAwareInterface) {
             $this->serviceAwareComponents[$name] = $component;
         }
     }
     // Listen for further components
     Events::attach('di:afterServiceResolve', Closure::bind(function (Event $event) {
         $data = $event->getData();
         $name = $data['name'];
         $component = $data['instance'];
         if ($component instanceof ServiceAwareInterface) {
             $this->serviceAwareComponents[$name] = $component;
         }
     }, $this));
 }
Beispiel #13
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->setShared('i18n', function () {
         return new static(Config::get('i18n'));
     });
     Events::attach('view:generatePhwoolconJsOptions', function (Event $event) {
         $options = $event->getData() ?: [];
         $options['locale'] = static::getCurrentLocale();
         $event->setData($options);
         return $options;
     });
 }