/** * Compile a SQL SELECT statement from a Query instance. * * The query will be compiled according to the order of the elements specified * in the "components" property. The entire query is passed into each component * compiler for convenience. * * @param Query $query * @return string */ public final function select(Query $query) { $sql = array(); foreach ($this->components as $component) { if (!is_null($query->{$component})) { $sql[] = call_user_func(array($this, $component), $query); } } return implode(' ', Arr::without($sql, array(null, ''))); }
/** * 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; }
/** * 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; }
/** * Load the applicable routes for a given URI. * * @param string $uri * @return array */ public function load($uri) { $segments = Arr::without(explode('/', $uri), ''); return array_merge($this->nested($segments), require $this->base . 'routes' . EXT); }
/** * 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."); }
/** * 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)); }
/** * Get the HTTP protocol for the request. * * @return string */ public static function protocol() { return Arr::get($_SERVER, 'SERVER_PROTOCOL', 'HTTP/1.1'); }
/** * 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; }
/** * Remove an item from the session data. * * @param string $key * @return void */ public function forget($key) { Arr::forget($this->session['data'], $key); }
/** * Set a configuration item's value. * * <code> * // Set the "session" configuration array * Config::set('session', $array); * * // Set the "timezone" option in the "application" configuration file * Config::set('application.timezone', 'UTC'); * </code> * * @param string $key * @param mixed $value * @return void */ public static function set($key, $value) { list($file, $key) = static::parse($key); static::load($file); if (is_null($key)) { Arr::set(static::$items, $file, $value); } else { Arr::set(static::$items[$file], $key, $value); } }