/** * factory queue object by config * * @param $config * @return Queue * @throws Exception */ public static function factory($config) { if (is_string($config)) { $c = ConfigHandler::get('queue'); if (!isset($c[$config])) { throw new Exception("Config '{$config}' not found!"); } $config = $c[$config]; } $name = $config['name'] ? $config['name'] : 'default'; if (!isset(self::$_instances[$name])) { if (!$config['adapter']) { throw new Exception("Adapter not found in config"); } $adapter = $config['adapter']; if (is_string($adapter)) { if (!isset(self::$_adaptersList[$adapter])) { throw new Exception("Adapter '{$adapter}' has not supported"); } $adapter = isset(self::$_adaptersList[$adapter]) ? self::$_adaptersList[$adapter] : $adapter; $adapter = new $adapter($config); } self::$_instances[$name] = new Queue($name, $adapter); } return self::$_instances[$name]; }
/** * initConfig * @param $config */ public function __construct($config = array()) { // Need to destroy any existing sessions started with session.auto_start if (session_id()) { session_unset(); session_destroy(); } // Disable transparent sid support ini_set('session.use_trans_sid', '0'); // Only allow the session ID to come from cookies and nothing else. ini_set('session.use_only_cookies', '1'); // Load config if (empty($config)) { $config = (array) ConfigHandler::get('session'); // Read config from session key in config file } $this->_config = array_merge($this->_config, $config); $this->_setOptions(); $this->_setCookieParams(); $this->_getSessionHandler(); if (isset($handlerClass)) { $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => $handlerClass))); } else { $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => 'default'))); } }
function __construct($section = 'default') { $config = ConfigHandler::get('assets'); if (!$config) { throw new Exception('Config "assets" not found'); } $config = $config[$section]; $this->_config($config); }
public function beforeExecute() { parent::beforeExecute(); // TODO: Change the autogenerated stub $this->form_cfg = ['common' => ['label' => t('Common Settings'), 'settings' => ['site_name' => ['label' => t('Site Name'), 'control' => 'input', 'type' => 'text'], 'site_url' => ['label' => t('Site Url'), 'control' => 'input', 'type' => 'text', 'placeholder' => 'http://'], 'email_address' => ['label' => t('E-mail Address'), 'control' => 'input', 'type' => 'email'], 'contact_phone' => ['label' => t('Company Phone'), 'control' => 'input', 'type' => 'tel'], 'contact_address' => ['label' => t('Company Address'), 'control' => 'input', 'type' => 'text'], 'site_offline' => ['label' => t('Site Offline?'), 'control' => 'checkbox', 'value' => 1]]]]; $other_setting = ConfigHandler::get('site_setting'); if (!empty($other_setting)) { $this->form_cfg['common']['settings'] = Base::mergeArray($this->form_cfg['common']['settings'], $other_setting); } $this->form_cfg = Plugin::applyFilters('custom_system_setting', $this->form_cfg); }
/** * get Redis Connection instance * * @param string|array $config the connect name * * @throws \RedisException * @return \Flywheel\Redis\Connection */ public static function getConnection($config = null) { if (null == $config || is_string($config)) { $c = ConfigHandler::get('redis'); if (null == $config || !isset($c[$config])) { $config = $c['__default__']; } if (!isset($c[$config])) { throw new \RedisException("Connection config not found with '{$config}'"); } $config = $c[$config]; } return Connection::getInstance($config['dsn'], isset($config['option']) && $config['option'] ? $config['option'] : array()); }
/** * factory Logger by channel * * @param $channel * @return \Flywheel\Log\Logger */ public static function factory($channel) { if (!isset(self::$_instances[$channel])) { $logger = new self($channel); $loggerConfig = ConfigHandler::get('logger'); $path = $loggerConfig['path']; $debug = $loggerConfig['debug'] ? $loggerConfig['debug'] : Logger::INFO; $filePath = $path . strtolower($channel); $logger->pushHandler(new RotatingFileHandler($filePath, 60, $debug)); $logger->pushProcessor(array(__CLASS__, 'errorHandle')); self::$_instances[$channel] = $logger; } return self::$_instances[$channel]; }
/** * Get thumb image by dimension * * @param $width * @param null $height * @param string $mode * @return string */ public function getThumbs($width, $height = null, $mode = 'a') { $media_cfg = \Flywheel\Config\ConfigHandler::get('media'); $site_url = \Setting::get('site_url'); if (!$media_cfg['sfs_enable']) { return $site_url . $this->getPath(); } if (!$width && $height) { $width = $height; $height = null; } $func = $height && $width == $height ? 'square/' : 'resize/'; $thumb_url = $media_cfg['sfs_path'] . '/cache/' . $func . ($func == 'resize/' ? "w_{$width}-h_{$height}-m_{$mode}/" : "w_{$width}/") . $this->getPath(); return rtrim($site_url, '/') . preg_replace('/(\\/+)/', '/', $thumb_url); }
/** * return IStorage */ public static function factory($config = null) { $settings = ConfigHandler::get('caching'); if (!$settings) { throw new Exception('Config "caching" not found!'); } if (!isset($settings[$config])) { $config = $settings['__default__']; } if (!isset(self::$_instances[$config])) { $options = $settings[$config]; $class = "\\Flywheel\\Cache\\Storage\\" . $options['storage']; self::$_instances[$config] = new $class($config, $options); } return self::$_instances[$config]; }
/** * Initialize * * @return void */ protected function _init() { parent::_init(); ini_set('display_errors', Base::ENV_DEV == Base::getEnv() || Base::ENV_TEST == Base::getEnv() ? 'on' : 'off'); if (Base::getEnv() == Base::ENV_DEV) { error_reporting(E_ALL); } else { if (Base::getEnv() == Base::ENV_TEST) { error_reporting(E_ALL ^ E_NOTICE); } } if (ConfigHandler::has('timezone')) { date_default_timezone_set(ConfigHandler::get('timezone')); } else { date_default_timezone_set(@date_default_timezone_get()); } }
/** * */ protected function _init() { define('TASK_DIR', APP_PATH . '/'); ini_set('display_errors', ConfigHandler::get('debug') ? 'on' : 'off'); //Error reporting if (Base::getEnv() == Base::ENV_DEV) { error_reporting(E_ALL); } else { if (Base::getEnv() == Base::ENV_TEST) { error_reporting(E_ALL ^ E_NOTICE); } } //set timezone if (ConfigHandler::has('timezone')) { date_default_timezone_set(ConfigHandler::get('timezone')); } else { date_default_timezone_set(@date_default_timezone_get()); } if (true === $this->isCli()) { $argv = $_SERVER['argv']; $seek = 1; if (null == $this->_task) { $this->_task = $argv[$seek]; ++$seek; } if (null == $this->_act && isset($argv[$seek])) { $this->_act = $argv[$seek]; ++$seek; } else { $this->_act = 'default'; } if (isset($argv[$seek])) { $this->_originalParams = array_slice($argv, $seek); $this->_params = $this->_process($this->_originalParams); } } else { //run on browser (only for test) if (null !== ($task = Factory::getRequest()->get('task'))) { $this->_task = $task; } if (null !== ($act = Factory::getRequest()->get('act'))) { $this->_act = $act; } } }
/** * initConfig * @param $config */ public function __construct($config = array()) { // Load config if (empty($config)) { ConfigHandler::get('session'); // Read config from session key in config file } $this->_config = array_merge($this->_config, $config); if (isset($this->_config['storage']) && $this->_config['storage']) { $handlerClass = $this->_config['storage']; unset($this->_config['handler']); $storage = new $handlerClass($this->_config); session_set_save_handler(array(&$storage, 'open'), array(&$storage, 'close'), array(&$storage, 'read'), array(&$storage, 'write'), array(&$storage, 'destroy'), array(&$storage, 'gc')); self::$_storage = $storage; } if (isset($this->_config['name'])) { session_name($this->_config['name']); } ini_set('session.gc_maxlifetime', $this->_config['lifetime']); //define the lifetime of the cookie if (isset($this->_config['cookie_ttl']) || isset($this->_config['cookie_domain']) || isset($this->_config['cookie_path'])) { // cross subdomain validity is default behavior $ttl = isset($this->_config['cookie_ttl']) ? (int) $this->_config['cookie_ttl'] : 0; $domain = isset($this->_config['cookie_domain']) ? $this->_config['cookie_domain'] : '.' . Factory::getRouter()->getDomain(); $path = isset($this->_config['cookie_path']) ? '/' . trim($this->_config['cookie_path'], '/') . '/' : '/'; session_set_cookie_params($ttl, $path, $domain); } else { $cookie = session_get_cookie_params(); session_set_cookie_params($cookie['lifetime'], $cookie['path'], $cookie['domain']); } if (Base::getApp()) { if (Factory::getRequest()->isSecure()) { ini_set('session.cookie_secure', true); } } ini_set('session.use_only_cookies', 1); if (isset($handlerClass)) { $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => $handlerClass))); } else { $this->dispatch('onAfterInitSessionConfig', new Event($this, array('handler' => 'default'))); } }
protected function _init() { ini_set('display_errors', Base::ENV_DEV == Base::getEnv() || Base::ENV_TEST == Base::getEnv() ? 'on' : 'off'); //Error reporting if (Base::getEnv() == Base::ENV_DEV) { error_reporting(E_ALL); } else { if (Base::getEnv() == Base::ENV_TEST) { error_reporting(E_ALL ^ E_NOTICE); } } //set timezone if (ConfigHandler::has('timezone')) { date_default_timezone_set(ConfigHandler::get('timezone')); } else { date_default_timezone_set(@date_default_timezone_get()); } $this->_requestMethod = strtoupper($_SERVER['REQUEST_METHOD']); if (!in_array($this->_requestMethod, self::$RESTfulREQUEST)) { throw new ApiException('Application: Request method unsupported!', null, 400); } }
/** * factory Translator object * @return null|Translator */ public static function getInstance() { $i18nCfg = ConfigHandler::get('i18n'); if (!$i18nCfg['enable']) { return null; } if (null == static::$_instance) { $translator = new Translator($i18nCfg['default_locale'], new MessageSelector()); $translator->setFallbackLocales($i18nCfg['default_fallback']); $translator->addLoader('array', new ArrayLoader()); //add init resource if (isset($i18nCfg['resource']) && is_array($i18nCfg['resource'])) { foreach ($i18nCfg['resource'] as $locale => $files) { for ($i = 0, $size = sizeof($files); $i < $size; ++$i) { $translator->addResourceFromFile($files[$i], $locale); } } } static::$_instance = $translator; } return static::$_instance; }
/** * load languages */ private function _loadLanguage() { $i18nCfg = ConfigHandler::get('i18n'); if (!$i18nCfg['enable']) { return null; } $current_lang_code = $this->get('lang'); if (!$current_lang_code) { $current_lang_code = Factory::getCookie()->read('language'); } if (!$current_lang_code) { $this->currentLang = \Languages::retrieveByDefault(1); $current_lang_code = $this->currentLang->getLangCode(); } else { $this->currentLang = \Languages::retrieveByLangCode($current_lang_code); } if ($current_lang_code) { Factory::getCookie()->write('language', $current_lang_code); } //load message $translator = Translator::getInstance(); $translator->setLocale($current_lang_code); if ($translator) { $translator->addLoader('yml', new YamlFileLoader()); if (isset($i18nCfg['resource']) && is_array($i18nCfg['resource'])) { foreach ($i18nCfg['resource'] as $locale => $files) { for ($i = 0, $size = sizeof($files); $i < $size; ++$i) { $fileInfo = new \SplFileInfo($files[$i]); $filename = $fileInfo->getFilename(); $ext = $fileInfo->getExtension(); if ($ext == 'yml') { $domain = str_replace('.' . $fileInfo->getExtension(), '', $fileInfo->getFilename()); $translator->addResource('yml', $files[$i], $locale, $domain); } } } } } }
/** * get Cookie handler * * @return \Flywheel\Storage\Cookie */ public static function getCookie() { if (!isset(self::$_registry['cookie'])) { \Flywheel\Session\Session::getInstance()->start(); $class = self::$_classesList['Cookie']; self::$_registry['cookie'] = new $class(ConfigHandler::get('session', false)); } return self::$_registry['cookie']; }
/** * Init database's configuration */ public static function initConfig() { self::$configuration = ConfigHandler::get('database'); }
public function writePlainText($path = null) { if (!ConfigHandler::get('debug')) { return; } if (null == $path) { $path = RUNTIME_PATH . '/log'; } @mkdir($path, 777); if (!($id = session_id())) { $id = md5(uniqid() . mt_rand()); } $filename = date('Y-m-d') . '.' . $id . '.profile'; $log = "\n\n**************************"; $log .= implode("\n", $this->getProfileData()); @file_put_contents($path . '/' . $filename, $log, FILE_APPEND); }
private function _initTemplate() { $template = ConfigHandler::get('template'); include_once $this->getTemplatePath() . DIRECTORY_SEPARATOR . 'template_init.php'; }
/** * @param $url * * @return mixed|void * @throws Routing */ public function parseUrl($url) { $this->dispatch('onBeginWebRouterParsingUrl', new Event($this)); $config = ConfigHandler::get('routing'); $rawUrl = $url; $url = $this->removeUrlSuffix($url, isset($config['__urlSuffix__']) ? $config['__urlSuffix__'] : null); if ('/' == $url) { if (!isset($config['/'])) { //default throw new Routing('Router: Not found default "/" in config. Default must be set!'); } $route = $this->_parseDefaultController(); } else { for ($i = sizeof($this->_collectors) - 1; $i >= 0; --$i) { if (false !== ($route = $this->_collectors[$i]->parseUrl($this, trim($url, '/'), $rawUrl))) { break; } } if (false == $route) { $route = trim($url, '/'); } } $this->_route = $route; $segment = explode('/', $route); $seek = $this->_parseControllers($route); $seek++; if (count($segment) > $seek) { $this->_action = $segment[$seek]; $seek++; $this->params = array_slice($segment, $seek); } if (null == $this->_action) { $this->_action = 'default'; } $this->dispatch('onAfterWebRouterParsingUrl', new Event($this)); }
public static function write() { if (!ConfigHandler::get('debug')) { return; } $profiler = self::getInstance(); $handlers = $profiler->getHandlers(); foreach ($handlers as $handler) { $handler->write($profiler->getProfileData()); } }
/** * @return null|string */ public function getLocale() { $locale = ConfigHandler::get('locale'); if (!$locale) { $locale = 'en-Us'; } return $locale; }
/** * Logs the method call or SQL using the Propel::log() method or a registered logger class. * * @param string $msg Message to log. * @param integer $level Log level to use; will use self::setLogLevel() specified level by default. * @param string $methodName Name of the method whose execution is being logged. * @param array $debugSnapshot Previous return value from self::getDebugSnapshot(). */ public function log($msg, $level = null, $methodName = null, array $debugSnapshot = null) { // If logging has been specifically disabled, this method won't do anything if (!ConfigHandler::get('debug')) { return; } // We won't log empty messages if (!$msg) { return; } }
/** * Send to client * */ public function send() { if (ConfigHandler::get('response_compress') && !ini_get('zlib.output_compression') && ini_get('output_handler') != 'ob_gzhandler') { $this->compress(); } $this->sendHttpHeaders(); $this->dispatch('onAfterSendHttpHeader', new Event($this)); $this->sendContent(); $this->dispatch('onAfterSendContent', new Event($this)); }
/** * render js link * @param string $pos * @return string */ public function js($pos = 'BOTTOM') { $jsv = ConfigHandler::get('js_version'); if (null == $jsv) { $jsv = '1'; } $pos = strtoupper($pos); if (!empty($this->_jsVar[$pos])) { foreach ($this->_jsVar[$pos] as $name => $value) { $code = "var {$name} = " . json_encode($value) . ';'; $this->addJsCode($code, $pos, 'standard'); } } $jsCode = ''; if (isset($this->_jsText[$pos])) { foreach ($this->_jsText[$pos] as $lib => $code) { if ('standard' == $lib) { $jsCode .= implode("\n", $code) . "\n"; } else { $open = constant(strtoupper('self::' . $lib) . '_OPEN'); $close = constant(strtoupper('self::' . $lib) . '_CLOSE'); $jsCode .= $open . implode("\n", $code) . $close; } } $jsCode = "<script type=\"text/javascript\">\n" . $jsCode . "\n</script>"; } $js = ''; if (isset($this->_javascript[$pos])) { foreach ($this->_javascript[$pos] as $file => $option) { if (strpos($file, 'http') !== false) { $js .= '<script type="text/javascript" src="' . $file . '?v=' . $jsv . '"></script>'; } else { $js_base_url = isset($option['base_url']) && $option['base_url'] != null ? $option['base_url'] : $this->jsBaseUrl; $js .= '<script type="text/javascript" src="' . $js_base_url . $file . '?v=' . $jsv . '"></script>'; } } } if ('TOP' == $pos) { $js .= $jsCode; } else { $js = $jsCode . $js; } //single file if (isset($this->_jsSingleFile[$pos])) { foreach ($this->_jsSingleFile[$pos] as $file => $option) { $jsv = isset($option['version']) ? $option['version'] : $jsv; $js .= '<script type="text/javascript" src="' . (isset($option['base_url']) ? $option['base_url'] : $this->jsBaseUrl) . $file . '?v=' . $jsv . '"> </script>'; } } return $js . "\n"; }
/** * @param $buffer * @throws \Exception * @return string */ protected function _renderPage($buffer) { //@TODO Addition document object and register it in factory $document = $this->document(); //@TODO same as view $view = $this->view(); $view->assign('buffer', $buffer); if ($this->_layout == null) { $config = ConfigHandler::get('template'); $this->_layout = ConfigHandler::has('default_layout') ? ConfigHandler::get('default_layout') : 'default'; //load default layout } $content = $view->render($this->getTemplatePath() . '/' . $this->_layout); if ($document->getMode() == Html::MODE_ASSETS_END) { $content = $document->disbursement($content); } return $content; }