Example #1
0
 /**
  * Get a configuration item.
  *
  * If no item is requested, the entire configuration array will be returned.
  *
  * <code>
  *		// Get the "session" configuration array
  *		$session = Config::get('session');
  *
  *		// Get the "timezone" option from the "application" configuration file
  *		$timezone = Config::get('application.timezone');
  * </code>
  *
  * @param  string  $key
  * @param  string  $default
  * @return array
  */
 public static function get($key, $default = null)
 {
     list($file, $key) = static::parse($key);
     if (!static::load($file)) {
         return $default instanceof Closure ? call_user_func($default) : $default;
     }
     $items = static::$items[$file];
     // If a specific configuration item was not requested, the key will be null,
     // meaning we need to return the entire array of configuration item from the
     // requested configuration file. Otherwise we can return the item.
     return is_null($key) ? $items : Arr::get($items, $key, $default);
 }
Example #2
0
 /**
  * Get the value of a cookie.
  *
  * @param  string  $name
  * @param  mixed   $default
  * @return string
  */
 public static function get($name, $default = null)
 {
     $value = Arr::get($_COOKIE, $name);
     if (!is_null($value)) {
         // All Laravel managed cookies are "signed" with a fingerprint hash.
         // The hash serves to verify that the contents of the cookie have not
         // been modified by the user. We can verify the integrity of the cookie
         // by extracting the value and re-hashing it, then comparing that hash
         // against the hash stored in the cookie.
         if (isset($value[40]) and $value[40] === '~') {
             list($hash, $value) = explode('~', $value, 2);
             if (static::hash($name, $value) === $hash) {
                 return $value;
             }
         }
     }
     return $default instanceof Closure ? call_user_func($default) : $default;
 }
Example #3
0
 /**
  * Determine if the route has a given name.
  *
  * @param  string  $name
  * @return bool
  */
 public function is($name)
 {
     return is_array($this->callback) and Arr::get($this->callback, 'name') === $name;
 }
Example #4
0
 /**
  * Magic Method for handling the dynamic creation of named views.
  *
  * <code>
  *		// Create an instance of the "layout" named view
  *		$view = View::of_layout();
  *
  *		// Create an instance of a named view with data
  *		$view = View::of_layout(array('name' => 'Taylor'));
  * </code>
  */
 public static function __callStatic($method, $parameters)
 {
     if (strpos($method, 'of_') === 0) {
         return static::of(substr($method, 3), Arr::get($parameters, 0, array()));
     }
     throw new \BadMethodCallException("Method [{$method}] is not defined on the View class.");
 }
Example #5
0
 /**
  * Get the language line as a string.
  *
  * If a language is specified, it should correspond to a directory
  * within your application language directory.
  *
  * <code>
  *		// Get a language line
  *		$line = Lang::line('validation.required')->get();
  *
  *		// Get a language line in a specified language
  *		$line = Lang::line('validation.required')->get('sp');
  *
  *		// Return a default value if the line doesn't exist
  *		$line = Lang::line('validation.required', null, 'Default');
  * </code>
  *
  * @param  string  $language
  * @param  string  $default
  * @return string
  */
 public function get($language = null, $default = null)
 {
     if (is_null($language)) {
         $language = $this->language;
     }
     list($file, $line) = $this->parse($this->key);
     if (!$this->load($file, $language)) {
         return $default instanceof Closure ? call_user_func($default) : $default;
     }
     return $this->replace(Arr::get(static::$lines[$language][$file], $line, $default));
 }
Example #6
0
 /**
  * Get the HTTP protocol for the request.
  *
  * @return string
  */
 public static function protocol()
 {
     return Arr::get($_SERVER, 'SERVER_PROTOCOL', 'HTTP/1.1');
 }
Example #7
0
 /**
  * Validate the MIME type of a file upload attribute is in a set of MIME types.
  *
  * @param  string  $attribute
  * @param  array   $value
  * @param  array   $parameters
  * @return bool
  */
 protected function validate_mimes($attribute, $value, $parameters)
 {
     if (!is_array($value) or Arr::get($value, 'tmp_name', '') == '') {
         return true;
     }
     foreach ($parameters as $extension) {
         if (File::is($extension, $value['tmp_name'])) {
             return true;
         }
     }
     return false;
 }
Example #8
0
 /**
  * Get an item from the session.
  *
  * The session flash data will also be checked for the requested item.
  *
  * <code>
  *		// Get an item from the session
  *		$name = Session::get('name');
  *
  *		// Return a default value if the item doesn't exist
  *		$name = Session::get('name', 'Taylor');
  * </code>
  *
  * @param  string  $key
  * @param  mixed   $default
  * @return mixed
  */
 public function get($key, $default = null)
 {
     $session = $this->session['data'];
     // We check for the item in the general session data first, and if it
     // does not exist in that data, we will attempt to find it in the new
     // and old flash data. If none of those arrays contain the requested
     // item, we will just return the default value.
     if (!is_null($value = Arr::get($session, $key))) {
         return $value;
     } elseif (!is_null($value = Arr::get($session[':new:'], $key))) {
         return $value;
     } elseif (!is_null($value = Arr::get($session[':old:'], $key))) {
         return $value;
     }
     return $default instanceof Closure ? call_user_func($default) : $default;
 }