Exemplo n.º 1
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');
 }
 /**
  * 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);
     }
 }
Exemplo n.º 3
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, '/');
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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, '/');
 }