Ejemplo n.º 1
0
 /**
  * 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];
 }
Ejemplo n.º 2
0
function schemas_execute()
{
    $params = func_get_arg(0);
    ConfigHandler::import('root.config');
    if (isset($params['config'])) {
        $conn = Manager::getConnection($params['config']);
    } else {
        throw new \Flywheel\Exception('missing "config" config key in user parameter');
    }
    $builder = new BuildSchemas($conn);
    $builder->_configKey = $params['config'];
    if (isset($params['help'])) {
        die($builder->get_help());
    }
    $builder->mod = isset($params['m']) ? $params['m'] : 'preserve';
    $builder->tbPrefix = isset($params['prefix']) ? $params['prefix'] : '';
    $builder->package = isset($params['pack']) ? $params['pack'] : '';
    if (isset($params['table'])) {
        $builder->setSpecialTbl($params['table']);
    }
    if (isset($params['igtbl'])) {
        $builder->setIgnoreTables($params['igtbl']);
    }
    if (isset($params['igprefix'])) {
        $builder->setIgnoreTablePrefixes($params['igprefix']);
    }
    if (isset($params['allow_tbl'])) {
        $builder->setAllowTables($params['allow_tbl']);
    }
    if (isset($params['allow_prefix'])) {
        $builder->setAllowTablePrefixes($params['allow_prefix']);
    }
    $builder->run();
}
Ejemplo n.º 3
0
 /**
  * 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')));
     }
 }
Ejemplo n.º 4
0
 function __construct($section = 'default')
 {
     $config = ConfigHandler::get('assets');
     if (!$config) {
         throw new Exception('Config "assets" not found');
     }
     $config = $config[$section];
     $this->_config($config);
 }
Ejemplo n.º 5
0
 private static function _createApplication($class, $config, $env, $debug, $type)
 {
     self::$_env = $env;
     ConfigHandler::set('debug', $debug);
     if ($debug) {
         Debugger::enable();
     }
     self::$_app = new $class($config, $type);
     return self::$_app;
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 /**
  * 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];
 }
Ejemplo n.º 8
0
 /**
  * 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());
 }
Ejemplo n.º 9
0
 /**
  * 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);
 }
Ejemplo n.º 10
0
 /**
  * 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];
 }
Ejemplo n.º 11
0
 /**
  * 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());
     }
 }
Ejemplo n.º 12
0
 /**
  *
  */
 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;
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * 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')));
     }
 }
Ejemplo n.º 14
0
 /**
  * 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);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * 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;
 }
Ejemplo n.º 16
0
 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);
     }
 }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
 private function _initTemplate()
 {
     $template = ConfigHandler::get('template');
     include_once $this->getTemplatePath() . DIRECTORY_SEPARATOR . 'template_init.php';
 }
Ejemplo n.º 19
0
 /**
  * @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));
 }
Ejemplo n.º 20
0
 public static function write()
 {
     if (!ConfigHandler::get('debug')) {
         return;
     }
     $profiler = self::getInstance();
     $handlers = $profiler->getHandlers();
     foreach ($handlers as $handler) {
         $handler->write($profiler->getProfileData());
     }
 }
Ejemplo n.º 21
0
 /**
  * @return null|string
  */
 public function getLocale()
 {
     $locale = ConfigHandler::get('locale');
     if (!$locale) {
         $locale = 'en-Us';
     }
     return $locale;
 }
Ejemplo n.º 22
0
 /**
  * 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;
     }
 }
Ejemplo n.º 23
0
    /**
     * 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";
    }
Ejemplo n.º 24
0
 /**
  * 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));
 }
Ejemplo n.º 25
0
 /**
  * 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'];
 }
Ejemplo n.º 26
0
 /**
  * Init database's configuration
  */
 public static function initConfig()
 {
     self::$configuration = ConfigHandler::get('database');
 }
Ejemplo n.º 27
0
 /**
  * @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;
 }
Ejemplo n.º 28
0
 public function _loadConfig()
 {
     $this->_configParam = ConfigHandler::load('global.config.mongodb', 'mongodb');
     if ($this->_configParam) {
         $params = $this->_configParam;
         if ($params['host'] == "" || $params['port'] == "") {
             throw new Exception('No host or port configured to connect to Mongo');
         }
         if (!empty($params['db'])) {
             $this->db = $params['db'];
         } else {
             throw new Exception('No Mongo database selected');
         }
         $this->_dbname = $params['db'];
         $this->_replicaSet = $params['replica_set'];
         $this->_querySafety = $params['query_safety'];
         $this->_persistKey = $params['persist_key'];
         $this->_persist = $params['persist'];
         $this->_configData = array('hostname' => "mongodb://{$params['host']}:{$params['port']}/{$params['db']}", 'dsn' => "mongodb://{$params['host']}:{$params['port']}/{$params['db']}", 'persist' => true, 'persist_key' => $this->_persistKey, 'replica_set' => $this->_replicaSet, 'query_safety' => $this->_querySafety);
         $this->_dsn = $this->_configData['dsn'];
     }
 }