Esempio n. 1
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);
         });
     }
 }
Esempio n. 2
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;
     });
 }
Esempio n. 3
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');
 }
Esempio n. 4
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));
         });
     }
 }
Esempio n. 5
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;
     });
 }
Esempio n. 6
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));
 }
Esempio n. 7
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;
     });
 }