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 }
function profilerStop($type = 'fpm') { if (isset($_SERVER['ENABLE_PROFILER']) && function_exists('xhprof_enable')) { static $profiler; static $profilerDir; $data = xhprof_disable(); $profilerDir || is_dir($profilerDir = storagePath('profiler')) or mkdir($profilerDir, 0777, true); $pathInfo = strtr($_SERVER['REQUEST_URI'], ['/' => '|']); $microTime = explode(' ', microtime()); $reportFile = $microTime[1] . '-' . substr($microTime[0], 2) . '-' . $_SERVER['REQUEST_METHOD'] . $pathInfo; $profiler or $profiler = new XHProfRuns_Default($profilerDir); $profiler->save_run($data, $type, $reportFile); } }
public function __construct(array $options = []) { parent::__construct($options); $this->multiLocale = $options['multi_locale']; $this->multiLocale and $this->availableLocales = $options['available_locales']; $this->detectClientLocale = $options['detect_client_locale']; $this->defaultLocale = $this->currentLocale = $options['default_locale']; $this->localePath = $options['locale_path']; $this->options = $options; $this->loadLocale($this->defaultLocale); $this->undefinedStringsLogFile = storagePath($options['undefined_strings_log']); is_file($this->undefinedStringsLogFile) and $this->undefinedStrings = (include $this->undefinedStringsLogFile); $this->reset(); }
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; }); }
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; }); }
public function getRemoteCoverageFiles() { return glob(storagePath('remote-coverage/cov-*')); }
public function __construct($config) { $this->workerStarted = storagePath('service-worker-started.php'); parent::__construct($config); }
<?php return ['_white_list' => ['options.lifetime', 'options.csrf_token_lifetime', 'options.cookies.name'], 'default' => 'native', 'options' => ['lifetime' => 86400, 'csrf_token_lifetime' => 3600, 'cookies' => ['name' => 'phwoolcon', 'secure' => false, 'http_only' => true], 'cookie_lazy_renew_interval' => 600], 'drivers' => ['native' => ['adapter' => 'Phwoolcon\\Session\\Adapter\\Native', 'options' => ['save_path' => storagePath('session')]], 'redis' => ['adapter' => 'Phwoolcon\\Session\\Adapter\\Redis', 'options' => ['index' => 6]], 'memcached' => ['adapter' => 'Phwoolcon\\Session\\Adapter\\Memcached', 'options' => []]]];
protected function initSwoole() { $this->choosePort(); $server = $this->swoole = new SwooleServer($this->sockFile, 0, SWOOLE_PROCESS, SWOOLE_UNIX_STREAM); $config = array_merge(['dispatch_mode' => 2, 'log_file' => storagePath('logs/service.log'), 'open_length_check' => true, 'package_max_length' => 8388608, 'package_length_type' => 'N', 'package_length_offset' => 0, 'package_body_offset' => 4], $this->config); unset($config['run_dir'], $config['linux_init_script'], $config['debug'], $config['start_on_boot']); unset($config['profiler']); $server->set($config); $enableProfiler = $this->config['profiler'] && function_exists('xhprof_enable'); $server->on('Start', [$this, 'onStart']); $server->on('Shutdown', [$this, 'onShutdown']); $server->on('ManagerStart', [$this, 'onManagerStart']); $server->on('WorkerStart', [$this, 'onWorkerStart']); $server->on('Receive', [$this, $enableProfiler ? 'profileReceive' : 'onReceive']); }