Exemplo n.º 1
0
 public static function load($group, $save = true)
 {
     $paths = array();
     $paths[] = J_PATH . "config" . DS . $group . EXT;
     $paths[] = J_PATH . "config" . DS . strtolower(Request::env()) . DS . $group . EXT;
     if (URI::isManager()) {
         $paths[] = J_MANAGERPATH . DS . "config" . DS . $group . EXT;
         $paths[] = J_MANAGERPATH . DS . "config" . DS . strtolower(Request::env()) . DS . $group . EXT;
     } else {
         $paths[] = J_APPPATH . "config" . DS . $group . EXT;
         $paths[] = J_APPPATH . "config" . DS . strtolower(Request::env()) . DS . $group . EXT;
     }
     $items = array();
     foreach ($paths as $path) {
         if (file_exists($path)) {
             $result = (require $path);
             if (is_array($result)) {
                 $items = array_merge($items, $result);
             }
         }
     }
     if (count($items) > 0) {
         if ($save) {
             static::$items[$group] = $items;
         }
         return $items;
     }
 }
Exemplo n.º 2
0
 public function testIndex()
 {
     $req = new Request('test/test', ['td1' => 'd1']);
     $this->assertEquals('test/test', $req->getRequestUri());
     $this->assertEquals('d1', $req->td1);
     $this->assertTrue(isset($req->td1));
     $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
     $this->assertTrue($req->isXmlHttpRequest());
     $req->setParam('a', 1);
     $this->assertEquals(1, $req->a);
     $this->assertEquals(1, $req->env('q', 1));
     $this->assertEquals(1, $req->cookie('q', 1));
     $this->assertEquals(1, $req->server('q', 1));
     $this->assertInstanceOf('Yagrysha\\MVC\\User', $req->user);
 }
Exemplo n.º 3
0
 /**
  * Start the application.
  */
 static function start($dispatch = true)
 {
     ob_start();
     // Set error reporting level.
     error_reporting(E_ALL ^ E_NOTICE);
     // Setup default error handelers.
     set_error_handler(array('Request', 'default_error_handler'), E_ALL);
     set_exception_handler(array('Request', 'default_exception_handler'));
     // Setup autoloader.
     spl_autoload_register(array('Request', 'autoload'));
     // Load app config.
     self::$config = new Config('app');
     $config =& self::$config;
     // Get current environment (default local).
     self::$env = is_file(APP_ROOT . 'config/.env') ? trim(file_get_contents(APP_ROOT . 'config/.env')) : 'local';
     // Load environment config.
     if (is_file(APP_ROOT . 'config/' . self::$env . '.yml')) {
         self::$env_config = new Config(self::$env);
         $env_config =& self::$env_config;
         // Merge environment config into app config.
         $config = Config::merge($config, $env_config);
     }
     // Setup app defaults.
     $default_app_config = array('view_path' => APP_ROOT . 'app/templates/', 'public_path' => APP_ROOT . 'public/', 'default_controller' => 'index', 'default_action' => 'index', 'default_output' => 'html', 'default_layout' => 'default', 'default_locale' => 'en_US.UTF-8', 'ajax_layout' => null);
     $config->app = Config::merge($default_app_config, $config->app);
     // Setup default locale.
     setlocale(LC_ALL, $config->app['default_locale']);
     // Setup default route.
     if (!is_array($config->routes)) {
         $config->routes = array();
     }
     array_push($config->routes, array('/'));
     array_push($config->routes, array('/:controller/:action/*'));
     // Include core and app helpers.
     self::include_helpers(APP_ROOT . 'app/helpers/');
     self::include_helpers(APP_ROOT . 'core/helpers/');
     // Include core and app models.
     self::include_models(APP_ROOT . 'app/models/', false);
     self::include_models(APP_ROOT . 'core/models/', false);
     // Include core and app plugins.
     self::include_plugins(APP_ROOT . 'app/plugins/');
     self::include_plugins(APP_ROOT . 'core/plugins/');
     // Dispatch request?
     if ($dispatch) {
         return self::dispatch($_SERVER['REQUEST_URI'] ?: $_SERVER['argv'][1]);
     }
 }
Exemplo n.º 4
0
 /**
  * Google Analytics
  * 
  * Assemble the Google Analytics tracking code based on the values defined 
  * in the config file.
  *
  * @access	private
  * @return 	string		Google Analytics tracking code
  */
 private static function google_analytics()
 {
     // Don’t try and track if no GA tracking ID is set
     if (!Config::get('xtatic::xtatic.google_analytics_id')) {
         return;
     }
     // Don’t try and track if page is served locally
     if (Request::env() == 'local') {
         return;
     }
     // Retrieve the GA ID(s) from the config, ensuring we have an array
     $ga_ids = (array) Config::get('xtatic::xtatic.google_analytics_id');
     $ga_domain = Config::get('xtatic::xtatic.google_analytics_domain');
     $multiple_domains = Config::get('xtatic::xtatic.google_analytics_multiple_tlds');
     // Assemble the tracking code
     $tracking_code = "\t" . 'var _gaq = _gaq || [];' . "\n";
     // Insert first GA tracking ID
     $tracking_code .= "\t" . '_gaq.push([\'_setAccount\', \'' . array_shift($ga_ids) . '\']);' . "\n";
     $tracking_code .= "\t" . '_gaq.push([\'_trackPageview\']);' . "\n";
     // If multiple GA tracking IDs have been specified then we need to append code for them too
     $id_counter = 1;
     while (count($ga_ids)) {
         $id_counter++;
         $tracking_code .= "\t" . '_gaq.push([\'t' . $id_counter . '._setAccount\', \'' . array_shift($ga_ids) . '\']);' . "\n";
         $tracking_code .= "\t" . '_gaq.push([\'t' . $id_counter . '._trackPageview\']);' . "\n";
     }
     // Additional line if we are tracking multiple subdomains
     if ($ga_domain) {
         $tracking_code .= "\t" . '_gaq.push([\'_setDomainName\', \'' . $ga_domain . '\']);' . "\n";
     }
     // Additional line if we are tracking multiple top level domains
     if ($multiple_domains) {
         $tracking_code .= "\t" . '_gaq.push([\'_setAllowLinker\', true]);' . "\n";
     }
     $tracking_code .= "\n";
     $tracking_code .= "\t" . '(function() {' . "\n";
     $tracking_code .= "\t\t" . 'var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;' . "\n";
     $tracking_code .= "\t\t" . 'ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';' . "\n";
     $tracking_code .= "\t\t" . 'var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);' . "\n";
     $tracking_code .= "\t" . '})();' . "\n";
     return $tracking_code;
 }
Exemplo n.º 5
0
 /**
  * Get the array of configuration paths that should be searched for a bundle.
  *
  * @param  string  $bundle
  * @return array
  */
 protected static function paths($bundle)
 {
     $paths[] = Bundle::path($bundle) . 'config/';
     // Configuration files can be made specific for a given environment. If an
     // environment has been set, we will merge the environment configuration
     // in last, so that it overrides all other options.
     if (!is_null(Request::env())) {
         $paths[] = $paths[count($paths) - 1] . Request::env() . '/';
     }
     return $paths;
 }
 /**
  * Execute the request and return a response.
  *
  * @param   array    additional cURL options
  * @return  string   request response body
  * @uses    array_get
  * @uses    Core::remote
  */
 public function execute(array $options = null)
 {
     // Get the URL of the request
     $url = $this->url;
     if (!isset($options[CURLOPT_USERAGENT])) {
         // Set the default user agent. GitHub requires one.
         $options[CURLOPT_USERAGENT] = "OneAuth - https://github.com/codenitive/laravel-oneauth";
     }
     if (!isset($options[CURLOPT_CONNECTTIMEOUT])) {
         // Use the request default timeout
         $options[CURLOPT_CONNECTTIMEOUT] = $this->timeout;
     }
     if (\Request::env() === 'local') {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     if (substr($this->method, 0, 4) === 'POST') {
         // Send the request as a POST
         $options[CURLOPT_POST] = true;
         $as_string = false;
         if ($this->method === 'POST_QUERY') {
             $as_string = true;
         }
         if ($post = $this->as_query($as_string)) {
             // Attach the post fields to the request
             $options[CURLOPT_POSTFIELDS] = $post;
         }
     } elseif ($query = $this->as_query()) {
         // Append the parameters to the query string
         $url = "{$url}?{$query}";
     }
     $response = Core::remote($url, $options);
     // check if it's a json string
     if ($this->name === 'access' and strpos(trim($response), '{') === 0) {
         $response = http_build_query(json_decode($response, true));
     }
     return $response;
 }
Exemplo n.º 7
0
 /**
  * @covers spriebsch\MVC\Request::__construct
  * @covers spriebsch\MVC\Request::__call
  */
 public function testEnvReturnsExistingValue()
 {
     $request = new Request(array(), array(), array(), array(), array(), array('key' => 'value'));
     $this->assertEquals('value', $request->env('key'));
 }