From ee5386e3b2140a0b18ac1e232f5fbba8aa30ac9b Mon Sep 17 00:00:00 2001 From: David Thorpe Date: Tue, 17 Apr 2012 19:25:41 +0100 Subject: [PATCH] Implemented View::exists function magical Signed-off-by: David Thorpe --- laravel/view.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/laravel/view.php b/laravel/view.php index 50d7a4d5..33f85733 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -110,12 +110,12 @@ public function __construct($view, $data = array()) } /** - * Get the path to a given view on disk. - * - * @param string $view - * @return string + * Allows people to check if a view passed in exists, handy for certain types of CMS development + * @param string $view The view name (ex. site.home) + * @param boolean $return_path Setting to TRUE will return the path found if it exists + * @return string / boolean */ - protected function path($view) + public static function exists($view, $return_path = false) { list($bundle, $view) = Bundle::parse($view); @@ -127,6 +127,21 @@ protected function path($view) $path = Event::first(static::loader, array($bundle, $view)); if ( ! is_null($path)) + { + return $return_path ? $path : true; + } + return false; + } + + /** + * Get the path to a given view on disk. + * + * @param string $view + * @return string + */ + protected function path($view) + { + if ($path = $this->exists($view,true)) { return $path; }