From 7a20240395db272e26c1e038d12bb6e5748cd545 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 22 Sep 2011 00:42:44 -0500 Subject: [PATCH] added some comments to the view class. --- laravel/str.php | 16 +++------------- laravel/uri.php | 8 ++++++++ laravel/url.php | 38 +++++++++++++++++++++++++++++++++++--- laravel/view.php | 28 ++++++++++++++++++++-------- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/laravel/str.php b/laravel/str.php index f0945d61..62f7c8bd 100644 --- a/laravel/str.php +++ b/laravel/str.php @@ -12,7 +12,7 @@ class Str { { if (function_exists('mb_strtolower')) { - return mb_strtolower($value, static::encoding()); + return mb_strtolower($value, Config::get('application.encoding')); } return strtolower($value); @@ -44,7 +44,7 @@ class Str { { if (function_exists('mb_convert_case')) { - return mb_convert_case($value, MB_CASE_TITLE, static::encoding()); + return mb_convert_case($value, MB_CASE_TITLE, Config::get('application.encoding')); } return ucwords(strtolower($value)); @@ -60,7 +60,7 @@ class Str { { if (function_exists('mb_strlen')) { - return mb_strlen($value, static::encoding()); + return mb_strlen($value, Config::get('application.encoding')); } return strlen($value); @@ -99,14 +99,4 @@ class Str { return implode('', array_map(function() use ($pool) { return $pool[mt_rand(0, strlen($pool) - 1)]; }, range(0, $length - 1))); } - /** - * Get the application encoding from the configuration class. - * - * @return string - */ - protected static function encoding() - { - return Config::get('application.encoding'); - } - } \ No newline at end of file diff --git a/laravel/uri.php b/laravel/uri.php index 9e2ab73c..93310beb 100644 --- a/laravel/uri.php +++ b/laravel/uri.php @@ -56,6 +56,14 @@ class URI { /** * Get a given URI segment from the URI for the current request. * + * + * // Get the first URI segment for the request + * $first = URI::segment(1); + * + * // Return a default value if the URI segment doesn't exist + * $segment = URI::segment(3, 'Default'); + * + * * @param int $segment * @param mixed $default * @return string diff --git a/laravel/url.php b/laravel/url.php index 8edec1b5..db301274 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -7,6 +7,11 @@ class URL { * * If the given URL is already well-formed, it will be returned unchanged. * + * + * // Create a URL to a location within the application + * $url = URL::to('user/profile'); + * + * * @param string $url * @param bool $https * @return string @@ -57,6 +62,14 @@ class URL { * parameter to the method. The values of this array will be used to fill the * wildcard segments of the route URI. * + * + * // Create a URL to the "profile" named route + * $url = URL::to_route('profile'); + * + * // Create a URL to the "profile" named route with wildcard parameters + * $url = URL::to_route('profile', array($username)); + * + * * @param string $name * @param array $parameters * @param bool $https @@ -70,9 +83,9 @@ class URL { $uri = substr($uris[0], strpos($uris[0], '/')); - // Spin through each route parameter and replace the route wildcard segment - // with the corresponding parameter passed to the method. - foreach ($parameters as $parameter) + // Spin through each route parameter and replace the route wildcard + // segment with the corresponding parameter passed to the method. + foreach ((array) $parameters as $parameter) { $uri = preg_replace('/\(.+?\)/', $parameter, $uri, 1); } @@ -100,6 +113,14 @@ class URL { /** * Generate a URL friendly "slug". * + * + * // Returns "this-is-my-blog-post" + * $slug = URL::slug('This is my blog post!'); + * + * // Returns "this_is_my_blog_post" + * $slug = URL::slug('This is my blog post!', '_'); + * + * * @param string $title * @param string $separator * @return string @@ -119,6 +140,17 @@ class URL { /** * Magic Method for dynamically creating URLs to named routes. + * + * + * // Create a URL to the "profile" named route + * $url = URL::to_profile(); + * + * // Create a URL to the "profile" named route with wildcard segments + * $url = URL::to_profile(array($username)); + * + * // Create a URL to the "profile" named route using HTTPS + * $url = URL::to_secure_profile(); + * */ public static function __callStatic($method, $parameters) { diff --git a/laravel/view.php b/laravel/view.php index 00355481..ac54371e 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -54,7 +54,7 @@ class View_Factory { * @param array $data * @return View */ - protected function of($name, $data = array()) + public function of($name, $data = array()) { if ( ! is_null($view = $this->composer->name($name))) { @@ -74,13 +74,9 @@ class View_Factory { { $view = str_replace('.', '/', $view); - if (file_exists($path = $this->path.$view.BLADE_EXT)) + foreach (array(BLADE_EXT, EXT) as $extension) { - return $path; - } - elseif (file_exists($path = $this->path.$view.EXT)) - { - return $path; + if (file_exists($path = $this->path.$view.$extension)) return $path; } throw new \Exception('View ['.$view.'] does not exist.'); @@ -219,6 +215,14 @@ class View { * within your application views directory. Dots or slashes may used to * reference views within sub-directories. * + * + * // Create a new view instance + * $view = View::make('home.index'); + * + * // Create a new view instance with bound data + * $view = View::make('home.index', array('name' => 'Taylor')); + * + * * @param string $view * @param array $data * @return View @@ -233,11 +237,19 @@ class View { * * View names are defined in the application composers file. * + * + * // Create an instance of the "layout" named view + * $view = View::of('layout'); + * + * // Create an instance of the "layout" view with bound data + * $view = View::of('layout', array('name' => 'Taylor')); + * + * * @param string $name * @param array $data * @return View */ - protected function of($name, $data = array()) + public static function of($name, $data = array()) { return IoC::container()->resolve('laravel.view')->of($name, $data); }