Esempio n. 1
1
 public function attachResponseService()
 {
     $this->_di->setShared('response', function () {
         $response = new \Phalcon\Http\Response();
         $response->setHeader('X-Frame-Options', 'SAMEORIGIN');
         $response->setHeader('X-Content-Type-Options', 'nosniff');
         $response->setHeader('X-XSS-Protection', '1; mode=block');
         $response->setHeader('X-Download-Options', 'noopen');
         return $response;
     });
     return $this;
 }
Esempio n. 2
0
 /**
  * Return flash instance
  */
 protected function getFlash()
 {
     $flash = new Session($this->classes);
     $di = new Di();
     $di->setShared('session', new PhalconMemorySession());
     $di->setShared('escaper', new Escaper());
     $flash->setDI($di);
     return $flash;
 }
Esempio n. 3
0
 /**
  * executed before each test
  */
 protected function _before()
 {
     $this->previousDependencyInjector = Di::getDefault();
     $di = new Di();
     $di->setShared('modelsMetadata', new Metadata\Memory());
     $di->setShared('modelsManager', new Manager());
     $di->setShared('db', function () {
         return new Mysql(['host' => TEST_DB_HOST, 'port' => TEST_DB_PORT, 'username' => TEST_DB_USER, 'password' => TEST_DB_PASSWD, 'dbname' => TEST_DB_NAME, 'charset' => TEST_DB_CHARSET]);
     });
     if ($this->previousDependencyInjector instanceof DiInterface) {
         Di::setDefault($di);
     }
 }
Esempio n. 4
0
 /**
  * executed before each test
  */
 protected function _before()
 {
     $this->previousDependencyInjector = Di::getDefault();
     $di = new Di();
     $di->setShared('modelsMetadata', new Memory());
     $di->setShared('modelsManager', new Manager());
     $di->setShared('db', function () {
         return new Mysql(['host' => 'localhost', 'port' => '3306', 'username' => 'root', 'password' => '', 'dbname' => 'incubator_tests', 'charset' => 'utf8mb4']);
     });
     if ($this->previousDependencyInjector instanceof DiInterface) {
         Di::setDefault($di);
     }
 }
Esempio n. 5
0
 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();
 }
Esempio n. 6
0
    public static function register(Di $di)
    {
        $environment = isset($_SERVER['PHWOOLCON_ENV']) ? $_SERVER['PHWOOLCON_ENV'] : 'production';
        // @codeCoverageIgnoreStart
        if (is_file($cacheFile = storagePath('cache/config-' . $environment . '.php'))) {
            static::$config = (include $cacheFile);
            Config::get('app.cache_config') or static::clearCache();
            return;
        }
        // @codeCoverageIgnoreEnd
        $defaultFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/*.php');
        $environmentFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/' . $environment . '/*.php');
        $config = new PhalconConfig(static::loadFiles($defaultFiles));
        $environmentSettings = static::loadFiles($environmentFiles);
        $environmentSettings['environment'] = $environment;
        $environmentConfig = new PhalconConfig($environmentSettings);
        $config->merge($environmentConfig);
        $di->remove('config');
        $di->setShared('config', $config);
        static::$config = $config->toArray();
        Config::get('database.default') and static::loadDb($config);
        // @codeCoverageIgnoreStart
        if (Config::get('app.cache_config')) {
            is_dir($cacheDir = dirname($cacheFile)) or mkdir($cacheDir, 0777, true);
            fileSaveArray($cacheFile, static::$config, function ($content) {
                $replacement = <<<'EOF'
$_SERVER['PHWOOLCON_ROOT_PATH'] . '
EOF;
                return str_replace("'{$_SERVER['PHWOOLCON_ROOT_PATH']}", $replacement, $content);
            });
        }
        // @codeCoverageIgnoreEnd
    }
Esempio n. 7
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->remove('payment');
     static::$instance = null;
     $di->setShared('payment', function () {
         return new static(Config::get('payment'));
     });
 }
Esempio n. 8
0
 public static function injectTo(Di $di)
 {
     $di->setShared('logger', function () use($di) {
         $logger = new Multiple();
         $config = $di->get('config')['loggers'];
         foreach ($config as $logConfig) {
             $adapter = $logConfig['adapter'];
             $options = isset($logConfig['options']) ? $logConfig['options'] : null;
             $logger->push(new $adapter($logConfig['name'], $options));
         }
         return $logger;
     });
 }
Esempio n. 9
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->remove('counter');
     static::$adapter = null;
     $di->setShared('counter', function () {
         $default = Config::get('counter.default');
         $config = Config::get('counter.drivers.' . $default);
         $class = $config['adapter'];
         $options = $config['options'];
         strpos($class, '\\') === false and $class = 'Phwoolcon\\Util\\Counter\\' . $class;
         return new $class($options);
     });
 }
Esempio n. 10
0
 public static function register(Di $di)
 {
     static::$hostname = gethostname();
     $di->remove('log');
     static::$logger = null;
     $di->setShared('log', function () {
         $filePath = storagePath('logs');
         is_dir($filePath) or mkdir($filePath, 0777, true);
         $filePath .= '/' . Config::get('app.log.file', 'phwoolcon.log');
         $logger = new File($filePath);
         $formatter = $logger->getFormatter();
         if ($formatter instanceof Line) {
             $formatter->setDateFormat('Y-m-d H:i:s');
             $formatter->setFormat('[%date%]{host}[%type%] {request} %message%');
         }
         return $logger;
     });
 }
Esempio n. 11
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->remove('cache');
     static::$cache = null;
     $di->setShared('cache', function () {
         $frontend = new Data(['lifetime' => static::TTL_ONE_DAY]);
         $default = Config::get('cache.default');
         $config = Config::get('cache.drivers.' . $default);
         $class = $config['adapter'];
         $options = $config['options'];
         strpos($class, '\\') === false and $class = 'Phalcon\\Cache\\Backend\\' . $class;
         isset($options['cacheDir']) and $options['cacheDir'] = storagePath($options['cacheDir']) . '/';
         /* @var Backend $backend */
         $backend = new $class($frontend, $options);
         return $backend;
     });
 }
Esempio n. 12
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;
     });
 }
Esempio n. 13
0
 public static function register(Di $di)
 {
     static::$di = $di;
     ini_set('session.use_cookies', 0);
     ini_set('session.cache_limiter', '');
     $di->remove('session');
     static::$session = null;
     $di->setShared('session', function () {
         $default = Config::get('session.default');
         $config = Config::get('session.drivers.' . $default);
         $class = $config['adapter'];
         $options = $config['options'];
         $options += Config::get('session.options');
         $options['cookies'] += Config::get('cookies');
         session_name($options['cookies']['name']);
         strpos($class, '\\') === false and $class = 'Phwoolcon\\Session\\Adapter\\' . $class;
         $session = new $class($options);
         // @codeCoverageIgnoreStart
         if (!$session instanceof AdapterInterface) {
             throw new SessionException('Session class should implement ' . AdapterInterface::class);
         }
         // @codeCoverageIgnoreEnd
         return $session;
     });
 }
Esempio n. 14
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->remove('router');
     $di->setShared('router', function () {
         return new static();
     });
 }
Esempio n. 15
0
 public static function injectTo(Di $di)
 {
     $di->setShared('logger', $di->get('config')['logger']);
 }
Esempio n. 16
0
 public static function register(Di $di)
 {
     static::$di = $di;
     static::$runningUnitTest = Config::runningUnitTest();
     $di->setShared('view', function () {
         return new static(Config::get('view'));
     });
 }
Esempio n. 17
0
 protected function getRouter($defaultRoutes = true)
 {
     $router = new Router($defaultRoutes);
     $di = new Di();
     $di->setShared('request', function () {
         return new Request();
     });
     $router->setDI($di);
     return $router;
 }
Esempio n. 18
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->remove('service');
     $di->setShared('service', function () {
         return new static(Config::get('service'));
     });
 }
Esempio n. 19
0
 protected function initEventsManager(Di $di)
 {
     if (!$di->has('eventsManager') || $di->getService('eventsManager')->getDefinition() == 'Phalcon\\Events\\Manager') {
         $di->setShared('eventsManager', $this->getEventsManager());
     }
     $this->setEventsManager($di->get('eventsManager'));
 }
Esempio n. 20
0
 /**
  * Set up the environment.
  *
  * @return Di
  */
 private function setupDI()
 {
     Di::reset();
     $di = new Di();
     $di->setShared('session', function () {
         return new PhalconMemorySession();
     });
     $di->setShared('request', function () {
         return new Request();
     });
     return $di;
 }
Esempio n. 21
0
 public function setShared($name, $definition)
 {
     return parent::setShared($name, $definition);
 }
Esempio n. 22
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->remove('modelsMetadata');
     $di->setShared('modelsMetadata', function () {
         return new InCache();
     });
     $di->setShared('dbManager', function () {
         return new static(Config::get('database'));
     });
     $di->setShared('db', function () {
         return static::connection();
     });
 }