Example #1
1
 public static function init()
 {
     $uri = explode('?', $_SERVER['REQUEST_URI']);
     $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
     static::$params = ['user_agent' => $_SERVER['HTTP_USER_AGENT'], 'status' => $_SERVER['REDIRECT_STATUS'], 'host' => $_SERVER['SERVER_NAME'], 'port' => $_SERVER['SERVER_PORT'], 'ip_address' => $_SERVER['REMOTE_ADDR'], 'method' => strtolower($_SERVER['REQUEST_METHOD']), 'query_string' => $_SERVER['QUERY_STRING'], 'uri' => $uri[0], 'ajax' => $ajax, 'accept' => $_SERVER['HTTP_ACCEPT'], 'accept_encoding' => $_SERVER['HTTP_ACCEPT_ENCODING'], 'accept_language' => $_SERVER['HTTP_ACCEPT_LANGUAGE']];
     if (isset($_POST['_method'])) {
         static::$params['method'] = strtolower($_POST['_method']);
         unset($_POST['_method']);
     }
     foreach ($_GET as $key => $value) {
         static::$inputs[$key] = $value;
     }
     foreach ($_POST as $key => $value) {
         static::$inputs[$key] = $value;
     }
     foreach ($_FILES as $input_name => $file_properties) {
         if (is_array($file_properties['name'])) {
             // Closure
             $filter = function ($path) use($input_name) {
                 // get the type as: name, tmp_name, size, error, type (mime-type)
                 $type = substr($path, 0, strpos($path, '.'));
                 // get the value of path in $_FILES array from $path :P
                 $pathWitoutType = substr($path, strpos($path, '.') + 1);
                 if ($type === 'tmp_name') {
                     $file = new File(get_array_value($_FILES, $input_name . '.tmp_name.' . $pathWitoutType), static::$file_error_codes[get_array_value($_FILES, $input_name . '.error.' . $pathWitoutType)], get_array_value($_FILES, $input_name . '.name.' . $pathWitoutType));
                     $file->setArrayPath($input_name . '.' . $pathWitoutType);
                     return $file;
                 }
                 return null;
             };
             static::$files = array_merge(static::$files, array_paths($_FILES[$input_name], [], null, $filter));
         } else {
             $file = new File($file_properties['tmp_name'], static::$file_error_codes[$file_properties['error']], $file_properties['name']);
             $file->setArrayPath($input_name);
             static::$files = array_merge(static::$files, [$file]);
         }
     }
     unset($_FILES);
     unset($_GET);
     unset($_POST);
     unset($_SERVER);
 }
Example #2
0
 public static function parse($name, $src, $docendpos = 0)
 {
     $info = new static();
     $info->name($name);
     if ($docendpos > 0) {
         $doc = trim(substr($src, 0, $docendpos));
         $startpos = strrpos($doc, '/**');
         if ($startpos !== false) {
             $doc = substr($doc, $startpos);
             if (preg_match('/\\/\\*\\*(.+?)\\*\\//s', $doc, $m)) {
                 $doc = preg_replace('/^[\\s]*\\*[\\s]{0,1}/m', '', $m[1]);
             } else {
                 $doc = '';
             }
         } else {
             $doc = '';
         }
     } else {
         $doc = $src;
     }
     $params = \ebi\Dt\DocParam::parse('param', $doc);
     if (!empty($params)) {
         $info->params($params);
     }
     if (preg_match("/@return\\s+([^\\s]+)(.*)/", $doc, $m)) {
         $info->return(new \ebi\Dt\DocParam('return', $m[1], $m[2]));
     }
     $info->document(trim(preg_replace('/@.+/', '', preg_replace("/^[\\s]*\\*[\\s]{0,1}/m", '', str_replace('*' . '/', '', $doc)))));
     return $info;
 }
 /**
  * Returns a test configuration param from /data/config.php
  * @param  string $name params name
  * @param  mixed $default default value to use when param is not set.
  * @return mixed  the value of the configuration param
  */
 public static function getParam($name, $default = null)
 {
     if (static::$params === null) {
         static::$params = (require __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'config.php');
     }
     return isset(static::$params[$name]) ? static::$params[$name] : $default;
 }
Example #4
0
 /**
  * Returns a test configuration param from /data/config.php
  * @param  string $name params name
  * @param  mixed $default default value to use when param is not set.
  * @return mixed  the value of the configuration param
  */
 public static function getParam($name, $default = null)
 {
     if (static::$params === null) {
         static::$params = (require __DIR__ . '/data/config.php');
     }
     return isset(static::$params[$name]) ? static::$params[$name] : $default;
 }
Example #5
0
 public static function getParams()
 {
     if (isset(static::$params)) {
         return static::$params;
     }
     JLoader::import('joomla.application.component.helper');
     static::$params = JComponentHelper::getParams('com_fileuploadform');
     return static::$params;
 }
 /**
  * @inheritDoc
  */
 public function __construct($connectionName = null, $driverClass = null, array $params = [])
 {
     if (!static::$flagInitData) {
         static::$connectionName = $connectionName;
         static::$driverClass = $driverClass;
         static::$params = $params;
         static::$flagInitData = true;
     }
 }
Example #7
0
 public static function get($name = null, $default = null)
 {
     if (!static::$params) {
         static::$params = Router::getInstance()->request()->params();
     }
     if ($name) {
         return isset(static::$params[$name]) ? static::$params[$name] : $default;
     } else {
         return static::$params;
     }
 }
Example #8
0
 /**
  * SetUp for Tests
  */
 public function setUp()
 {
     parent::setUp();
     // provide config json for running the tests
     if (!file_exists(__DIR__ . '/config.json')) {
         die('Must provide config.json in the tests/ directory');
     } else {
         $file = file_get_contents(__DIR__ . '/config.json');
         static::$params = json_decode($file, true);
     }
 }
Example #9
0
 /**
  * Returns a test configuration param from config
  * @param string $name params name
  * @param mixed $default default value to use when param is not set.
  * @return mixed the value of the configuration param
  */
 public function getParam($name, $default = null)
 {
     if (static::$params === null) {
         static::$params = (require __DIR__ . '/config/main.php');
         $main_local = __DIR__ . '/config/main-local.php';
         if (file_exists($main_local)) {
             static::$params = array_merge(static::$params, require $main_local);
         }
     }
     return isset(static::$params[$name]) ? static::$params[$name] : $default;
 }
Example #10
0
 /**
  * init
  *
  * @param   \JDocument $template JDcoument object.
  * @param   \JRegistry $params   Template params.
  *
  * @return  Template
  */
 public function init(\JDocument $template, \JRegistry $params)
 {
     include_once static::windwalkerPath();
     static::$template = $template;
     static::$params = $params;
     static::$asset = Container::getInstance('tpl_' . static::$name)->get('helper.asset');
     // Reset AssetHelper
     static::$asset->resetPaths();
     static::$asset->setDoc($template);
     static::registerStylesheet($template);
     static::registerScript($template);
     return $this;
 }
Example #11
0
 public static function get_params()
 {
     if (static::$params !== []) {
         return static::$params;
     }
     \Config::load('db', true);
     $dsn = \Config::get('db.default.connection.dsn');
     list($driver, $tmp) = explode(':', $dsn);
     list($hostStr, $dbnameStr) = explode(';', $tmp);
     list($tmp, $host) = explode('=', $hostStr);
     list($tmp, $dbname) = explode('=', $dbnameStr);
     $username = \Config::get('db.default.connection.username');
     $password = \Config::get('db.default.connection.password');
     static::$params = ['host' => $host, 'dbname' => $dbname, 'username' => $username, 'password' => $password];
     return static::$params;
 }
Example #12
0
 /**
  * Create a route from an array representation
  *
  * @param array $array
  *
  * @return Route
  */
 public static function createFromArray(array $array)
 {
     $route = new static($array['patterns']);
     if (isset($array['name'])) {
         $route->name($array['name']);
     }
     if (isset($array['params'])) {
         $route->params($array['params']);
     }
     if (isset($array['values'])) {
         $route->values($array['values']);
     }
     if (isset($array['conditions'])) {
         $route->conditions($array['conditions']);
     }
     if (isset($array['attributes'])) {
         $route->attributes($array['attributes']);
     }
     return $route;
 }
Example #13
0
 public static function run($config)
 {
     if (isset($config['db'])) {
         if (isset($config['db']['username'])) {
             static::$db = new DB($config['db']['dsn'], $config['db']['username'], $config['db']['password']);
         } else {
             static::$db = new DB($config['db']['dsn']);
         }
     }
     static::$assets = new Assets(isset($config['assets']) ? $config['assets'] : []);
     static::$user = new User();
     static::$url = new Url();
     static::$request = new Request();
     static::$session = new Session();
     static::$helper = new Helper();
     static::$params = $config['params'];
     $url = str_replace(static::$url->path(), '', $_SERVER['REQUEST_URI']);
     $options = isset($config['route']) ? $config['route'] : [];
     static::$route = new Route($url, $options);
     static::$route->run();
 }
Example #14
0
 /**
  * Constructeur
  */
 private function __construct()
 {
     static::$params = new \stdClass();
     static::$input = new Input();
     Session::add('bow.old', static::$input->all());
 }
 private static function prepareParams($settings)
 {
     self::$params = [];
     foreach ($settings['params'] as $paramStorage) {
         if (is_array($paramStorage)) {
             static::$params = array_merge(self::$params, $paramStorage);
             continue;
         }
         // environment
         if ($paramStorage === 'env' || $paramStorage === 'environment') {
             static::$params = array_merge(self::$params, $_SERVER);
             continue;
         }
         $paramsFile = realpath(self::$dir . '/' . $paramStorage);
         if (!file_exists($paramsFile)) {
             throw new ConfigurationException("Params file {$paramsFile} not found");
         }
         // yaml parameters
         if (preg_match('~\\.yml$~', $paramStorage)) {
             $params = Yaml::parse(file_get_contents($paramsFile));
             if (isset($params['parameters'])) {
                 // Symfony style
                 $params = $params['parameters'];
             }
             static::$params = array_merge(self::$params, $params);
             continue;
         }
         // .env and ini files
         if (preg_match('~(\\.ini$|\\.env(\\.|$))~', $paramStorage)) {
             $params = parse_ini_file($paramsFile);
             static::$params = array_merge(self::$params, $params);
             continue;
         }
         throw new ConfigurationException("Params can't be loaded from `{$paramStorage}`.");
     }
 }
Example #16
0
 public function __construct()
 {
     if (static::$params === null) {
         static::$params = array_merge(static::$required, static::$optional);
     }
 }
 protected function setUp()
 {
     static::$params = (require __DIR__ . '/data/config.php');
     parent::setUp();
 }
Example #18
0
 protected static function setRoute($route)
 {
     $destination = explode('::', $route->destination);
     $info = ['controller' => $destination[0], 'method' => $destination[1], 'params' => $route->params, 'defaults' => $route->defaults, 'extension' => isset($route->params['extension']) ? $route->params['extension'] : 'html'];
     // Remove the first dot from the extension
     if ($info['extension'][0] == '.') {
         $info['extension'] = substr($info['extension'], 1);
     }
     // Allow static use current route info.
     static::$controller = $info['controller'];
     static::$method = $info['method'];
     static::$params = $info['params'];
     static::$defaults = $info['defaults'];
     static::$extension = $info['extension'];
     return static::$currentRoute = $info;
 }
 protected function setUp()
 {
     static::$params = (require __DIR__ . '/data/config.php');
     parent::setUp();
     $this->db = BaseRecord::$db = $this->getConnection(self::$resetFixture);
 }
Example #20
0
 /**
  * Returns a test configuration param from /config.php
  * and/or /config-local.php if present
  *
  * @param string $name
  *        params name
  * @param mixed $default
  *        default value to use when param is not set.
  * @return mixed the value of the configuration param
  */
 public function getParam($name, $default = null)
 {
     if (static::$params === null) {
         if (file_exists(__DIR__ . '/../config-local.php')) {
             static::$params = ArrayHelper::merge(require __DIR__ . '/../config.php', require __DIR__ . '/../config-local.php');
         } else {
             static::$params = (require __DIR__ . '/../config.php');
         }
     }
     return isset(static::$params[$name]) ? static::$params[$name] : $default;
 }
Example #21
0
 /**
  * Method: _setParamArray
  * Set {@link $params}, mostly used by the dispatcher
  * @param array $params
  */
 public static function _setParamArray($params)
 {
     static::$params = $params;
 }
Example #22
0
 /**
  * Make quick POST request
  * 
  * @param string $url
  * @param array $params [optional]
  * @return \Koldy\Http\Response
  * @example echo \Koldy\Http\Request::post('http://www.google.com') will output body HTML of google.com
  */
 public static function post($url, array $params = array())
 {
     $self = new static($url);
     $self->type(static::POST);
     $self->params($params);
     return $self->exec();
 }
 protected function setUp()
 {
     static::$params = (require __DIR__ . '/data/config.php');
     parent::setUp();
     ActiveRecord::$db = $this->getConnection();
 }
Example #24
0
    private static function setRoute($route)
    {
        $value = explode('.', $route['value']);
        $method = explode('/', implode('.', array_slice($value, 1)));
        $vars = isset($method[1]) ? explode(',', $method[1]) : array();

        static::$controller = str_replace('::', '\\', '\\'.$value[0]);
        static::$method = $method[0];
        static::$params = $route['params'];
        static::$vars = $vars;
        static::$extension = (isset($route['params']['extension']) ? $route['params']['extension'] : null);
    }