added some comments to the view class.

This commit is contained in:
Taylor Otwell 2011-09-22 00:42:44 -05:00
parent 5d67672d66
commit 7a20240395
4 changed files with 66 additions and 24 deletions

View File

@ -12,7 +12,7 @@ public static function lower($value)
{
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 @@ public static function title($value)
{
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 @@ public static function length($value)
{
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 @@ public static function random($length = 16, $type = 'alpha_num')
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');
}
}

View File

@ -56,6 +56,14 @@ public function get()
/**
* Get a given URI segment from the URI for the current request.
*
* <code>
* // 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');
* </code>
*
* @param int $segment
* @param mixed $default
* @return string

View File

@ -7,6 +7,11 @@ class URL {
*
* If the given URL is already well-formed, it will be returned unchanged.
*
* <code>
* // Create a URL to a location within the application
* $url = URL::to('user/profile');
* </code>
*
* @param string $url
* @param bool $https
* @return string
@ -57,6 +62,14 @@ public static function to_asset($url, $https = null)
* parameter to the method. The values of this array will be used to fill the
* wildcard segments of the route URI.
*
* <code>
* // 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));
* </code>
*
* @param string $name
* @param array $parameters
* @param bool $https
@ -70,9 +83,9 @@ public static function to_route($name, $parameters = array(), $https = false)
$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 @@ public static function to_secure_route($name, $parameters = array())
/**
* Generate a URL friendly "slug".
*
* <code>
* // 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!', '_');
* </code>
*
* @param string $title
* @param string $separator
* @return string
@ -119,6 +140,17 @@ public static function slug($title, $separator = '-')
/**
* Magic Method for dynamically creating URLs to named routes.
*
* <code>
* // 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();
* </code>
*/
public static function __callStatic($method, $parameters)
{

View File

@ -54,7 +54,7 @@ public function make($view, $data = array())
* @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 @@ protected function path($view)
{
$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 @@ public function __construct(View_Factory $factory, View_Composer $composer, $vie
* within your application views directory. Dots or slashes may used to
* reference views within sub-directories.
*
* <code>
* // 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'));
* </code>
*
* @param string $view
* @param array $data
* @return View
@ -233,11 +237,19 @@ public static function make($view, $data = array())
*
* View names are defined in the application composers file.
*
* <code>
* // 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'));
* </code>
*
* @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);
}