示例#1
0
 /**
  * Reinitialize the global request.
  * 
  * @return void
  */
 protected function restartRequest()
 {
     // FIXME: Ugly hack, but old contents from previous requests seem to
     // trip up the Foundation class.
     $_FILES = array();
     Request::$foundation = RequestFoundation::createFromGlobals();
 }
示例#2
0
 /**
  * Get the rendered contents of the Profiler.
  *
  * @param  Response  $response
  * @return string
  */
 public static function render($response)
 {
     // We only want to send the profiler toolbar if the request is not an AJAX
     // request, as sending it on AJAX requests could mess up JSON driven API
     // type applications, so we will not send anything in those scenarios.
     if (!Request::ajax()) {
         return render('path: ' . __DIR__ . '/template' . BLADE_EXT, static::$data);
     }
 }
示例#3
0
 /**
  * Get the rendered contents of the Profiler.
  *
  * @param  Response  $response
  * @return string
  */
 public static function render($response)
 {
     // We only want to send the profiler toolbar if the request is not an AJAX
     // request, as sending it on AJAX requests could mess up JSON driven API
     // type applications, so we will not send anything in those scenarios.
     if (!Request::ajax()) {
         static::$data['memory'] = get_file_size(memory_get_usage(true));
         static::$data['memory_peak'] = get_file_size(memory_get_peak_usage(true));
         static::$data['time'] = number_format((microtime(true) - LARAVEL_START) * 1000, 2);
         return render('path: ' . __DIR__ . '/template' . BLADE_EXT, static::$data);
     }
 }
示例#4
0
 /**
  * Dump the results of the currently established route.
  *
  * @return void
  */
 protected function route()
 {
     // We'll call the router using the method and URI specified by
     // the developer on the CLI. If a route is found, we will not
     // run the filters, but simply dump the result.
     $route = Router::route(Request::method(), URI::current());
     if (!is_null($route)) {
         var_dump($route->response());
     } else {
         echo '404: Not Found';
     }
 }
示例#5
0
 /**
  * Set the value of a cookie.
  *
  * <code>
  *		// Set the value of the "favorite" cookie
  *		Cookie::put('favorite', 'Laravel');
  *
  *		// Set the value of the "favorite" cookie for twenty minutes
  *		Cookie::put('favorite', 'Laravel', 20);
  * </code>
  *
  * @param  string  $name
  * @param  string  $value
  * @param  int     $expiration
  * @param  string  $path
  * @param  string  $domain
  * @param  bool    $secure
  * @return void
  */
 public static function put($name, $value, $expiration = 0, $path = '/', $domain = null, $secure = false)
 {
     if ($expiration !== 0) {
         $expiration = time() + $expiration * 60;
     }
     // If the secure option is set to true, yet the request is not over HTTPS
     // we'll throw an exception to let the developer know that they are
     // attempting to send a secure cookie over the unsecure HTTP.
     if ($secure and !Request::secure()) {
         throw new \Exception("Attempting to set secure cookie over HTTP.");
     }
     static::$jar[$name] = compact('name', 'value', 'expiration', 'path', 'domain', 'secure');
 }
示例#6
0
 /**
  * Run PHPUnit with the temporary XML configuration.
  *
  * @return void
  */
 protected function test()
 {
     // We'll simply fire off PHPUnit with the configuration switch
     // pointing to our requested configuration file. This allows
     // us to flexibly run tests for any setup.
     $path = 'phpunit.xml';
     // fix the spaced directories problem when using the command line
     // strings with spaces inside should be wrapped in quotes.
     $esc_path = escapeshellarg($path);
     passthru('LARAVEL_ENV=' . Request::env() . ' phpunit --configuration ' . $esc_path, $status);
     @unlink($path);
     // Pass through the exit status
     exit($status);
 }
 /**
  * Send a cookie from the cookie jar back to the browser.
  *
  * @param  array  $cookie
  * @return void
  */
 protected static function set($cookie)
 {
     extract($cookie);
     $time = $minutes !== 0 ? time() + $minutes * 60 : 0;
     $value = static::sign($name, $value);
     // A cookie payload can't exceed 4096 bytes, so if the cookie payload
     // is greater than that, we'll raise an error to warn the developer
     // since it could cause cookie session problems.
     if (strlen($value) > 4000) {
         throw new \Exception("Payload too large for cookie.");
     } else {
         // We don't want to send secure cookies over HTTP unless the developer has
         // turned off the "SSL" application configuration option, which is used
         // while developing the application but should be true in production.
         if ($secure and !Request::secure() and Config::get('application.ssl')) {
             return;
         }
         setcookie($name, $value, $time, $path, $domain, $secure);
     }
 }
示例#8
0
 /**
  * Get a database query instance for the migration table.
  *
  * @return Laravel\Database\Query
  */
 protected function table()
 {
     return DB::connection(Request::server('cli.db'))->table('laravel_migrations');
 }
示例#9
0
 /**
  * Generate an application URL.
  *
  * <code>
  *		// Create a URL to a location within the application
  *		$url = URL::to('user/profile');
  *
  *		// Create a HTTPS URL to a location within the application
  *		$url = URL::to('user/profile', true);
  * </code>
  *
  * @param  string  $url
  * @param  bool    $https
  * @return string
  */
 public static function to($url = '', $https = null)
 {
     // If the given URL is already valid or begins with a hash, we'll just return
     // the URL unchanged since it is already well formed. Otherwise we will add
     // the base URL of the application and return the full URL.
     if (static::valid($url) or starts_with($url, '#')) {
         return $url;
     }
     // Unless $https is specified (true or false) then maintain the current request
     // security for any new links generated.  So https for all secure links.
     if (is_null($https)) {
         $https = Request::secure();
     }
     $root = static::base() . '/' . Config::get('application.index');
     // Since SSL is not often used while developing the application, we allow the
     // developer to disable SSL on all framework generated links to make it more
     // convenient to work with the site while developing locally.
     if ($https and Config::get('application.ssl')) {
         $root = preg_replace('~http://~', 'https://', $root, 1);
     } else {
         $root = preg_replace('~https://~', 'http://', $root, 1);
     }
     return rtrim($root, '/') . '/' . ltrim($url, '/');
 }
示例#10
0
 /**
  * Create a redirect response to the HTTP referrer.
  *
  * @param  int       $status
  * @return Redirect
  */
 public static function back($status = 302)
 {
     return static::to(Request::referrer(), $status);
 }
示例#11
0
 public static function to($url = '', $https = null, $asset = false, $locale = true)
 {
     if (static::valid($url) or starts_with($url, '#')) {
         return $url;
     }
     if (is_null($https)) {
         $https = Request::secure();
     }
     $root = static::base();
     if (!$asset) {
         $root .= '/' . Config::get('application.index');
     }
     $languages = Config::get('application.languages');
     if (!$asset and $locale and count($languages) > 0) {
         if (in_array($default = Config::get('application.language'), $languages)) {
             $root = rtrim($root, '/') . '/' . $default;
         }
     }
     if ($https and Config::get('application.ssl')) {
         $root = preg_replace('~http://~', 'https://', $root, 1);
     } else {
         $root = preg_replace('~https://~', 'http://', $root, 1);
     }
     return rtrim($root, '/') . '/' . ltrim($url, '/');
 }
示例#12
0
    $root = Request::foundation()->getRootUrl();
    $environment = Request::detect_env($environments, $root);
}
/*
|--------------------------------------------------------------------------
| Set The Application Environment
|--------------------------------------------------------------------------
|
| Once we have determined the application environment, we will set it on
| the global server array of the HttpFoundation request. This makes it
| available throughout the application, thought it is mainly only
| used to determine which configuration files to merge in.
|
*/
if (isset($environment)) {
    Request::set_env($environment);
}
/*
|--------------------------------------------------------------------------
| Set The CLI Options Array
|--------------------------------------------------------------------------
|
| If the current request is from the Artisan command-line interface, we
| will parse the command line arguments and options and set them the
| array of options in the $_SERVER global array for convenience.
|
*/
if (defined('STDIN')) {
    $console = CLI\Command::options($_SERVER['argv']);
    list($arguments, $options) = $console;
    $options = array_change_key_case($options, CASE_UPPER);
示例#13
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;
 }
示例#14
0
|
*/
if (isset($environment)) {
    Request::set_env($environment);
}
/*
|--------------------------------------------------------------------------
| Set The CLI Options Array
|--------------------------------------------------------------------------
|
| If the current request is from the Artisan command-line interface, we
| will parse the command line arguments and options and set them the
| array of options in the $_SERVER global array for convenience.
|
*/
if (Request::cli()) {
    $console = CLI\Command::options($_SERVER['argv']);
    list($arguments, $options) = $console;
    $options = array_change_key_case($options, CASE_UPPER);
    $_SERVER['CLI'] = $options;
}
/*
|--------------------------------------------------------------------------
| Register The Laravel Bundles
|--------------------------------------------------------------------------
|
| Finally we will register all of the bundles that have been defined for
| the application. None of them will be started yet, but will be set up
| so that they may be started by the developer at any time.
|
*/
示例#15
0
 /**
  * Execute a controller method with the given parameters.
  *
  * @param  string    $method
  * @param  array     $parameters
  * @return Response
  */
 public function execute($method, $parameters = array())
 {
     // Again, as was the case with route closures, if the controller
     // "before" filters return a response, it will be considered the
     // response to the request and the controller method will not be
     // used to handle the request to the application.
     $response = Filter::run($this->filters('before', $method), array(), true);
     if (is_null($response)) {
         // The developer may mark the controller as being "RESTful" which
         // indicates that the controller actions are prefixed with the
         // HTTP verb they respond to rather than the word "action".
         if ($this->restful) {
             $action = strtolower(Request::method()) . '_' . $method;
         } else {
             $action = "action_{$method}";
         }
         $response = call_user_func_array(array($this, $action), $parameters);
         // If the controller has specified a layout view. The response
         // returned by the controller method will be bound to that view
         // and the layout will be considered the response.
         if (is_null($response) and !is_null($this->layout)) {
             $response = $this->layout;
         }
     }
     if (!$response instanceof Response) {
         $response = new Response($response);
     }
     // Stringify the response. We need to force the response to be
     // stringed before closing the session, since the developer may
     // be using the session within their views, so we cannot age
     // the session data until the view is rendered.
     $response->content = $response->render();
     Filter::run($this->filters('after', $method), array($response));
     return $response;
 }
 /**
  * Execute a controller action and return the response.
  *
  * Unlike the "execute" method, no filters will be run and the response
  * from the controller action will not be changed in any way before it
  * is returned to the consumer.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public function response($method, $parameters = array())
 {
     // The developer may mark the controller as being "RESTful" which
     // indicates that the controller actions are prefixed with the
     // HTTP verb they respond to rather than the word "action".
     if ($this->restful) {
         $action = strtolower(Request::method()) . '_' . $method;
     } else {
         $action = "action_{$method}";
     }
     $response = call_user_func_array(array($this, $action), $parameters);
     // If the controller has specified a layout view. The response
     // returned by the controller method will be bound to that
     // view and the layout will be considered the response.
     if (is_null($response) and !is_null($this->layout)) {
         $response = $this->layout;
     }
     return $response;
 }
示例#17
0
 /**
  * Generate an application URL to an asset.
  *
  * @param  string  $url
  * @param  bool    $https
  * @return string
  */
 public static function to_asset($url, $https = null)
 {
     if (is_null($https)) {
         $https = Request::secure();
     }
     $url = static::to($url, $https);
     // Since assets are not served by Laravel, we do not need to come through
     // the front controller. So, we'll remove the application index specified
     // in the application config from the generated URL.
     if (($index = Config::get('application.index')) !== '') {
         $url = str_replace($index . '/', '', $url);
     }
     return $url;
 }
示例#18
0
 /**
  * Determine if this collection's filters apply to a given method.
  *
  * @param  string  $method
  * @return bool
  */
 public function applies($method)
 {
     if (count($this->only) > 0 and !in_array($method, $this->only)) {
         return false;
     }
     if (count($this->except) > 0 and in_array($method, $this->except)) {
         return false;
     }
     $request = strtolower(Request::method());
     if (count($this->methods) > 0 and !in_array($request, $this->methods)) {
         return false;
     }
     return true;
 }
示例#19
0
 /**
  * Generate an application URL to an asset.
  *
  * @param  string  $url
  * @param  bool    $https
  * @return string
  */
 public static function to_asset($url, $https = null)
 {
     if (static::valid($url)) {
         return $url;
     }
     // If a base asset URL is defined in the configuration, use that and don't
     // try and change the HTTP protocol. This allows the delivery of assets
     // through a different server or third-party content delivery network.
     if ($root = Config::get('application.asset_url', false)) {
         return rtrim($root, '/') . '/' . ltrim($url, '/');
     }
     if (is_null($https)) {
         $https = Request::secure();
     }
     $url = static::to($url, $https);
     // Since assets are not served by Laravel, we do not need to come through
     // the front controller. So, we'll remove the application index specified
     // in the application config from the generated URL.
     if (($index = Config::get('application.index')) !== '') {
         $url = str_replace($index . '/', '', $url);
     }
     return $url;
 }
示例#20
0
 /**
  * Create a fresh session array with a unique ID.
  *
  * @return array
  */
 public function fresh()
 {
     // Fetch a guest session with the same IP address
     $old_guest_session = $this->table()->where_user_id(1)->where_last_ip(Request::ip())->first();
     // We will simply generate an empty session payload array, using an ID
     // that is either not currently assigned to any existing session or
     // that belongs to a guest with the same IP address.
     if (is_null($old_guest_session)) {
         $id = $this->id();
     } else {
         $id = $old_guest_session->id;
         Session::instance()->exists = true;
     }
     return array('id' => $id, 'data' => array(':new:' => array(), ':old:' => array()));
 }
示例#21
0
 /**
  * Send all of the response headers to the browser.
  *
  * @return void
  */
 public function send_headers()
 {
     $this->foundation->prepare(Request::foundation());
     $this->foundation->sendHeaders();
 }
示例#22
0
}
if ($uri == '') {
    $uri = '/';
}
URI::$uri = $uri;
/*
|--------------------------------------------------------------------------
| Route The Incoming Request
|--------------------------------------------------------------------------
|
| Phew! We can finally route the request to the appropriate route and
| execute the route to get the response. This will give an instance
| of the Response object that we can send back to the browser
|
*/
Request::$route = Router::route(Request::method(), $uri);
$response = Request::$route->call();
/*
|--------------------------------------------------------------------------
| "Render" The Response
|--------------------------------------------------------------------------
|
| The render method evaluates the content of the response and converts it
| to a string. This evaluates any views and sub-responses within the
| content and sets the raw string result as the new response.
|
*/
$response->render();
/*
|--------------------------------------------------------------------------
| Persist The Session To Storage