From 7ca5a2359acf7e4676518c7c950324afeac80a25 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 08:37:01 -0700 Subject: [PATCH 01/45] Added HTML::span method. --- system/html.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/system/html.php b/system/html.php index f7c53282..e4da34ee 100644 --- a/system/html.php +++ b/system/html.php @@ -35,6 +35,18 @@ public static function style($url, $media = 'all') return ''.PHP_EOL; } + /** + * Generate a HTML span. + * + * @param string $value + * @param array $attributes + * @return string + */ + public static function span($value, $attributes = array()) + { + return ''.static::entities($value).''; + } + /** * Generate a HTML link. * From 8d2eefe18f4b73ed45d600ab6e4454ab7e8664b8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 08:37:33 -0700 Subject: [PATCH 02/45] Refactoring paginator. --- system/paginator.php | 47 +++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/system/paginator.php b/system/paginator.php index 7cd732da..df3ca356 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -110,8 +110,6 @@ public function links($adjacent = 3) */ private function numbers($adjacent = 3) { - // "7" is added to the adjacent range to account for the seven constant elements - // in a slider: the first and last two links, the current page, and the two "..." strings. return ($this->last_page < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page) : $this->slider($adjacent); } @@ -125,7 +123,7 @@ private function slider($adjacent) { if ($this->page <= $adjacent * 2) { - return $this->range(1, 4 + ($adjacent * 2)).$this->ending(); + return $this->range(1, 2 + ($adjacent * 2)).$this->ending(); } elseif ($this->page >= $this->last_page - ($adjacent * 2)) { @@ -144,12 +142,7 @@ public function previous() { $text = Lang::line('pagination.previous')->get($this->language); - if ($this->page > 1) - { - return HTML::link(Request::uri().'?page='.($this->page - 1), $text, array('class' => 'prev_page'), $this->https).' '; - } - - return "$text "; + return ($this->page > 1) ? $this->link($this->page - 1, $text, 'prev_page').' ' : HTML::span($text, array('class' => 'disabled prev_page')).' '; } /** @@ -161,12 +154,7 @@ public function next() { $text = Lang::line('pagination.next')->get($this->language); - if ($this->page < $this->last_page) - { - return HTML::link(Request::uri().'?page='.($this->page + 1), $text, array('class' => 'next_page'), $this->https); - } - - return "$text"; + return ($this->page < $this->last_page) ? $this->link($this->page + 1, $text, 'next_page') : HTML::span($text, array('class' => 'disabled next_page')).' '; } /** @@ -176,7 +164,7 @@ public function next() */ private function beginning() { - return $this->range(1, 2).'... '; + return $this->range(1, 2).$this->dots(); } /** @@ -186,7 +174,30 @@ private function beginning() */ private function ending() { - return '... '.$this->range($this->last_page - 1, $this->last_page); + return $this->dots().$this->range($this->last_page - 1, $this->last_page); + } + + /** + * Create a HTML page link. + * + * @param int $page + * @param string $text + * @param string $attributes + * @return string + */ + private function link($page, $text, $class) + { + return HTML::link(Request::uri().'?page='.$page, $text, array('class' => $class), $this->https); + } + + /** + * Build a "dots" HTML span element. + * + * @return string + */ + private function dots() + { + return HTML::span('...', array('class' => 'dots')).' '; } /** @@ -204,7 +215,7 @@ private function range($start, $end) for ($i = $start; $i <= $end; $i++) { - $pages .= ($this->page == $i) ? "$i " : HTML::link(Request::uri().'?page='.$i, $i, array(), $this->https).' '; + $pages .= ($this->page == $i) ? HTML::span($i, array('class' => 'current')).' ' : $this->link($i, $i, null).' '; } return $pages; From dac63a50c625731227481e0b5de597b1992a5c7e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 12:00:16 -0700 Subject: [PATCH 03/45] Refactored the paginator class for cleanliness. --- system/paginator.php | 68 ++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/system/paginator.php b/system/paginator.php index df3ca356..a8a7378b 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -30,13 +30,6 @@ class Paginator { */ public $per_page; - /** - * The last page number. - * - * @var int - */ - public $last_page; - /** * The language that should be used when generating page links. * @@ -44,13 +37,6 @@ class Paginator { */ public $language; - /** - * Indicates if HTTPS links should be generated. - * - * @var bool - */ - public $https = false; - /** * Create a new Paginator instance. * @@ -62,7 +48,6 @@ class Paginator { public function __construct($results, $total, $per_page) { $this->page = static::page($total, $per_page); - $this->last_page = ceil($total / $per_page); $this->per_page = $per_page; $this->results = $results; $this->total = $total; @@ -86,7 +71,7 @@ public static function page($total, $per_page) return $last_page; } - return (filter_var($page, FILTER_VALIDATE_INT) === false or $page < 1) ? 1 : $page; + return ($page < 1 or filter_var($page, FILTER_VALIDATE_INT) === false) ? 1 : $page; } /** @@ -97,7 +82,7 @@ public static function page($total, $per_page) */ public function links($adjacent = 3) { - return ($this->last_page > 1) ? '' : ''; + return ($this->last_page() > 1) ? '' : ''; } /** @@ -110,7 +95,7 @@ public function links($adjacent = 3) */ private function numbers($adjacent = 3) { - return ($this->last_page < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page) : $this->slider($adjacent); + return ($this->last_page() < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page()) : $this->slider($adjacent); } /** @@ -125,12 +110,14 @@ private function slider($adjacent) { return $this->range(1, 2 + ($adjacent * 2)).$this->ending(); } - elseif ($this->page >= $this->last_page - ($adjacent * 2)) + elseif ($this->page >= $this->last_page() - ($adjacent * 2)) { - return $this->beginning().$this->range($this->last_page - 2 - ($adjacent * 2), $this->last_page); + return $this->beginning().$this->range($this->last_page() - 2 - ($adjacent * 2), $this->last_page()); + } + else + { + return $this->beginning().$this->range($this->page - $adjacent, $this->page + $adjacent).$this->ending(); } - - return $this->beginning().$this->range($this->page - $adjacent, $this->page + $adjacent).$this->ending(); } /** @@ -140,7 +127,7 @@ private function slider($adjacent) */ public function previous() { - $text = Lang::line('pagination.previous')->get($this->language); + $text = Lang::line('pagination.previous')->get(); return ($this->page > 1) ? $this->link($this->page - 1, $text, 'prev_page').' ' : HTML::span($text, array('class' => 'disabled prev_page')).' '; } @@ -152,9 +139,9 @@ public function previous() */ public function next() { - $text = Lang::line('pagination.next')->get($this->language); + $text = Lang::line('pagination.next')->get(); - return ($this->page < $this->last_page) ? $this->link($this->page + 1, $text, 'next_page') : HTML::span($text, array('class' => 'disabled next_page')).' '; + return ($this->page < $this->last_page()) ? $this->link($this->page + 1, $text, 'next_page') : HTML::span($text, array('class' => 'disabled next_page')); } /** @@ -174,7 +161,7 @@ private function beginning() */ private function ending() { - return $this->dots().$this->range($this->last_page - 1, $this->last_page); + return $this->dots().$this->range($this->last_page() - 1, $this->last_page()); } /** @@ -187,7 +174,7 @@ private function ending() */ private function link($page, $text, $class) { - return HTML::link(Request::uri().'?page='.$page, $text, array('class' => $class), $this->https); + return HTML::link(Request::uri().'?page='.$page, $text, array('class' => $class), Request::is_secure()); } /** @@ -205,8 +192,8 @@ private function dots() * * For the current page, an HTML span element will be generated instead of a link. * - * @param int $start - * @param int $end + * @param int $start + * @param int $end * @return string */ private function range($start, $end) @@ -222,7 +209,17 @@ private function range($start, $end) } /** - * Set the language that should be used when generating pagination links. + * Determine the last page number based on the total pages and per page limit. + * + * @return int + */ + private function last_page() + { + return ceil($this->total / $this->per_page); + } + + /** + * Set the language that should be used when generating page links. * * @param string $language * @return Paginator @@ -233,15 +230,4 @@ public function lang($language) return $this; } - /** - * Force the pagination links to use HTTPS. - * - * @return Paginator - */ - public function secure() - { - $this->https = true; - return $this; - } - } \ No newline at end of file From 44db0e72f949bc2b8a19b6a3d60fc481ef3b2971 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 12:16:27 -0700 Subject: [PATCH 04/45] Refactoring the paginator class again... --- system/paginator.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/system/paginator.php b/system/paginator.php index a8a7378b..a15a13bf 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -187,6 +187,16 @@ private function dots() return HTML::span('...', array('class' => 'dots')).' '; } + /** + * Determine the last page number based on the total pages and per page limit. + * + * @return int + */ + private function last_page() + { + return ceil($this->total / $this->per_page); + } + /** * Build a range of page links. * @@ -208,16 +218,6 @@ private function range($start, $end) return $pages; } - /** - * Determine the last page number based on the total pages and per page limit. - * - * @return int - */ - private function last_page() - { - return ceil($this->total / $this->per_page); - } - /** * Set the language that should be used when generating page links. * From 6e9bf0a0e32054ecf9bf6688624d88b56b8ed4e6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 12:37:10 -0700 Subject: [PATCH 05/45] URL::to_asset should use Request::is_secure to determine if asset link should use HTTPS. --- system/url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/url.php b/system/url.php index 0755ba56..9bf47dd5 100644 --- a/system/url.php +++ b/system/url.php @@ -54,7 +54,7 @@ public static function to_secure($url = '') */ public static function to_asset($url = '') { - return static::to($url, false, true); + return static::to($url, Request::is_secure(), true); } /** From 3c216d897fdc89fdf5989c613d1db11b4c108902 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:15:24 -0700 Subject: [PATCH 06/45] Refactoring URL class. --- system/url.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/system/url.php b/system/url.php index 9bf47dd5..5235b68c 100644 --- a/system/url.php +++ b/system/url.php @@ -5,33 +5,27 @@ class URL { /** * Generate an application URL. * + * If the given URL is already well-formed, it will be returned unchanged. + * * @param string $url * @param bool $https - * @param bool $asset * @return string */ - public static function to($url = '', $https = false, $asset = false) + public static function to($url = '', $https = false) { - if (strpos($url, '://') !== false) + if (filter_var($url, FILTER_VALIDATE_URL) !== false) { return $url; } - $base = Config::get('application.url'); + $base = Config::get('application.url').'/'.Config::get('application.index'); - // If the URL is being generated for a public asset such as an - // image, we do not want to include "index.php" in the path. - if ( ! $asset) - { - $base .= '/'.Config::get('application.index'); - } - - if (strpos($base, 'http://') === 0 and $https) + if ($https and strpos($base, 'http://') === 0) { $base = 'https://'.substr($base, 7); } - return rtrim($base, '/').'/'.trim($url, '/'); + return $base.'/'.ltrim($url, '/'); } /** @@ -52,9 +46,9 @@ public static function to_secure($url = '') * @param string $url * @return string */ - public static function to_asset($url = '') + public static function to_asset($url) { - return static::to($url, Request::is_secure(), true); + return str_replace('/'.Config::get('application.index'), '', static::to($url, Request::is_secure())); } /** From 7f465f307bbfa94498261ea572b9b79cc73b9270 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:19:39 -0700 Subject: [PATCH 07/45] Refactoring URL class. --- system/url.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/url.php b/system/url.php index 5235b68c..0346f019 100644 --- a/system/url.php +++ b/system/url.php @@ -9,9 +9,10 @@ class URL { * * @param string $url * @param bool $https + * @param bool $asset * @return string */ - public static function to($url = '', $https = false) + public static function to($url = '', $https = false, $asset = false) { if (filter_var($url, FILTER_VALIDATE_URL) !== false) { @@ -20,10 +21,9 @@ public static function to($url = '', $https = false) $base = Config::get('application.url').'/'.Config::get('application.index'); - if ($https and strpos($base, 'http://') === 0) - { - $base = 'https://'.substr($base, 7); - } + $base = ($asset) ? str_replace('/'.Config::get('application.index'), '', $base) : $base; + + $base = ($https and strpos($base, 'http://') === 0) ? 'https://'.substr($base, 7) : $base; return $base.'/'.ltrim($url, '/'); } @@ -48,7 +48,7 @@ public static function to_secure($url = '') */ public static function to_asset($url) { - return str_replace('/'.Config::get('application.index'), '', static::to($url, Request::is_secure())); + return static::to($url, Request::is_secure(), true); } /** From d48c5d186d9716ef9551a96f6afc1a6eea08d6dc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:22:52 -0700 Subject: [PATCH 08/45] Added comments to URL class. --- system/url.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/url.php b/system/url.php index 0346f019..f97e6a7a 100644 --- a/system/url.php +++ b/system/url.php @@ -21,8 +21,10 @@ public static function to($url = '', $https = false, $asset = false) $base = Config::get('application.url').'/'.Config::get('application.index'); + // If the URL is to an asset such as an image, we do not need to go through the front controller. $base = ($asset) ? str_replace('/'.Config::get('application.index'), '', $base) : $base; + // If the resource should be accessed over HTTPS, change the protocol in the URL. $base = ($https and strpos($base, 'http://') === 0) ? 'https://'.substr($base, 7) : $base; return $base.'/'.ltrim($url, '/'); From 721693a52a9c872be4dd67c58bcdfd48a9f080f1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:25:47 -0700 Subject: [PATCH 09/45] Continuing work on URL class. --- system/url.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/system/url.php b/system/url.php index f97e6a7a..0346f019 100644 --- a/system/url.php +++ b/system/url.php @@ -21,10 +21,8 @@ public static function to($url = '', $https = false, $asset = false) $base = Config::get('application.url').'/'.Config::get('application.index'); - // If the URL is to an asset such as an image, we do not need to go through the front controller. $base = ($asset) ? str_replace('/'.Config::get('application.index'), '', $base) : $base; - // If the resource should be accessed over HTTPS, change the protocol in the URL. $base = ($https and strpos($base, 'http://') === 0) ? 'https://'.substr($base, 7) : $base; return $base.'/'.ltrim($url, '/'); From 873e4ee2d78172c22217a0750bcd6defffc2b168 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:29:53 -0700 Subject: [PATCH 10/45] Tweaking paginator class. --- system/paginator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/paginator.php b/system/paginator.php index a15a13bf..8e85bbee 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -47,10 +47,12 @@ class Paginator { */ public function __construct($results, $total, $per_page) { - $this->page = static::page($total, $per_page); $this->per_page = $per_page; $this->results = $results; $this->total = $total; + + // Determine the current page based on the total results and per page limit. + $this->page = static::page($this->total, $this->per_page); } /** From a6a2588ed160de03dbf5f6d9e06033e46ad910c2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:34:54 -0700 Subject: [PATCH 11/45] A few more tweaks to the paginator class. --- system/paginator.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/system/paginator.php b/system/paginator.php index 8e85bbee..a15a13bf 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -47,12 +47,10 @@ class Paginator { */ public function __construct($results, $total, $per_page) { + $this->page = static::page($total, $per_page); $this->per_page = $per_page; $this->results = $results; $this->total = $total; - - // Determine the current page based on the total results and per page limit. - $this->page = static::page($this->total, $this->per_page); } /** From 7499586bb312c73aa644e118be0ea85d24344f9e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:35:41 -0700 Subject: [PATCH 12/45] Edited system/paginator.php via GitHub --- system/paginator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/paginator.php b/system/paginator.php index a15a13bf..10bf3367 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -48,6 +48,7 @@ class Paginator { public function __construct($results, $total, $per_page) { $this->page = static::page($total, $per_page); + $this->per_page = $per_page; $this->results = $results; $this->total = $total; From 7191a6768033da6ab76604948bd5e183137dc7c9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 13:37:07 -0700 Subject: [PATCH 13/45] Edited system/paginator.php via GitHub --- system/paginator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/paginator.php b/system/paginator.php index 10bf3367..a15a13bf 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -48,7 +48,6 @@ class Paginator { public function __construct($results, $total, $per_page) { $this->page = static::page($total, $per_page); - $this->per_page = $per_page; $this->results = $results; $this->total = $total; From e9397b7107168e83692f243391fa10ba08b3644c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 14:07:46 -0700 Subject: [PATCH 14/45] More refactoring on paginator. --- system/paginator.php | 95 +++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/system/paginator.php b/system/paginator.php index a15a13bf..14113b6d 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -30,6 +30,13 @@ class Paginator { */ public $per_page; + /** + * The last page available for the result set. + * + * @var int + */ + public $last_page; + /** * The language that should be used when generating page links. * @@ -41,22 +48,40 @@ class Paginator { * Create a new Paginator instance. * * @param array $results + * @param int $page * @param int $total * @param int $per_page + * @param int $last_page * @return void */ - public function __construct($results, $total, $per_page) + public function __construct($results, $page, $total, $per_page, $last_page) { - $this->page = static::page($total, $per_page); + $this->last_page = $last_page; $this->per_page = $per_page; $this->results = $results; $this->total = $total; + $this->page = $page; + } + + /** + * Create a new Paginator instance. + * + * @param array $results + * @param int $total + * @param int $per_page + * @return Paginator + */ + public static function make($results, $total, $per_page) + { + return new static($results, static::page($total, $per_page), $total, $per_page, ceil($total / $per_page)); } /** * Get the current page from the request query string. * * The page will be validated and adjusted if it is less than one or greater than the last page. + * For example, if the current page is not an integer or less than one, one will be returned. + * If the current page is greater than the last page, the last page will be returned. * * @param int $total * @param int $per_page @@ -82,7 +107,7 @@ public static function page($total, $per_page) */ public function links($adjacent = 3) { - return ($this->last_page() > 1) ? '' : ''; + return ($this->last_page > 1) ? '' : ''; } /** @@ -95,7 +120,7 @@ public function links($adjacent = 3) */ private function numbers($adjacent = 3) { - return ($this->last_page() < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page()) : $this->slider($adjacent); + return ($this->last_page < 7 + ($adjacent * 2)) ? $this->range(1, $this->last_page) : $this->slider($adjacent); } /** @@ -110,14 +135,12 @@ private function slider($adjacent) { return $this->range(1, 2 + ($adjacent * 2)).$this->ending(); } - elseif ($this->page >= $this->last_page() - ($adjacent * 2)) + elseif ($this->page >= $this->last_page - ($adjacent * 2)) { - return $this->beginning().$this->range($this->last_page() - 2 - ($adjacent * 2), $this->last_page()); - } - else - { - return $this->beginning().$this->range($this->page - $adjacent, $this->page + $adjacent).$this->ending(); + return $this->beginning().$this->range($this->last_page - 2 - ($adjacent * 2), $this->last_page); } + + return $this->beginning().$this->range($this->page - $adjacent, $this->page + $adjacent).$this->ending(); } /** @@ -141,7 +164,7 @@ public function next() { $text = Lang::line('pagination.next')->get(); - return ($this->page < $this->last_page()) ? $this->link($this->page + 1, $text, 'next_page') : HTML::span($text, array('class' => 'disabled next_page')); + return ($this->page < $this->last_page) ? $this->link($this->page + 1, $text, 'next_page') : HTML::span($text, array('class' => 'disabled next_page')); } /** @@ -151,7 +174,7 @@ public function next() */ private function beginning() { - return $this->range(1, 2).$this->dots(); + return $this->range(1, 2).'...'; } /** @@ -161,40 +184,7 @@ private function beginning() */ private function ending() { - return $this->dots().$this->range($this->last_page() - 1, $this->last_page()); - } - - /** - * Create a HTML page link. - * - * @param int $page - * @param string $text - * @param string $attributes - * @return string - */ - private function link($page, $text, $class) - { - return HTML::link(Request::uri().'?page='.$page, $text, array('class' => $class), Request::is_secure()); - } - - /** - * Build a "dots" HTML span element. - * - * @return string - */ - private function dots() - { - return HTML::span('...', array('class' => 'dots')).' '; - } - - /** - * Determine the last page number based on the total pages and per page limit. - * - * @return int - */ - private function last_page() - { - return ceil($this->total / $this->per_page); + return '...'.$this->range($this->last_page - 1, $this->last_page); } /** @@ -218,6 +208,19 @@ private function range($start, $end) return $pages; } + /** + * Create a HTML page link. + * + * @param int $page + * @param string $text + * @param string $attributes + * @return string + */ + private function link($page, $text, $class) + { + return HTML::link(Request::uri().'?page='.$page, $text, array('class' => $class), Request::is_secure()); + } + /** * Set the language that should be used when generating page links. * From db6b93f668aac1c7fb1b07e7c33fff67ab019921 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 14:09:08 -0700 Subject: [PATCH 15/45] Tweak Query->paginate for new paginator constructor API. --- system/db/query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/db/query.php b/system/db/query.php index 15a2e4f8..3482f8c8 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -466,7 +466,7 @@ public function paginate($per_page) $current_page = \System\Paginator::page($total, $per_page); - return new \System\Paginator($this->for_page($current_page, $per_page)->get(), $total, $per_page); + return \System\Paginator::make($this->for_page($current_page, $per_page)->get(), $total, $per_page); } /** From 5a43f29f31ba25b5d70b5fcd75c2e1d18235ac3c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 14:09:54 -0700 Subject: [PATCH 16/45] Tweak eloquent->paginate() for new paginator constructor API. --- system/db/eloquent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/db/eloquent.php b/system/db/eloquent.php index d4a1a64f..f0eb9d9e 100644 --- a/system/db/eloquent.php +++ b/system/db/eloquent.php @@ -202,7 +202,7 @@ private function _paginate($per_page = null) $current_page = \System\Paginator::page($total, $per_page); - return new \System\Paginator($this->for_page($current_page, $per_page)->get(), $total, $per_page); + return \System\Paginator::make($this->for_page($current_page, $per_page)->get(), $total, $per_page); } /** From c9698df285d22914bb1f4f9e9b4f1454ab7c06f1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 22:01:17 -0500 Subject: [PATCH 17/45] added support for environment driven configuration files. --- system/config.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/config.php b/system/config.php index af8360c3..f4c3f291 100644 --- a/system/config.php +++ b/system/config.php @@ -100,7 +100,9 @@ private static function parse($key) */ public static function load($file) { - if ( ! array_key_exists($file, static::$items) and file_exists($path = APP_PATH.'config/'.$file.EXT)) + $directory = (isset($_ENV['LARAVEL_ENV'])) ? $_ENV['LARAVEL_ENV'].'/' : ''; + + if ( ! array_key_exists($file, static::$items) and file_exists($path = APP_PATH.'config/'.$directory.$file.EXT)) { static::$items[$file] = require $path; } From 2c774adbde986fc2019662f8f44865eea48a76c9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 22:16:20 -0500 Subject: [PATCH 18/45] check for $_SERVER instead of $_ENV LARAVEL_ENV. --- system/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/config.php b/system/config.php index f4c3f291..ec459195 100644 --- a/system/config.php +++ b/system/config.php @@ -100,7 +100,7 @@ private static function parse($key) */ public static function load($file) { - $directory = (isset($_ENV['LARAVEL_ENV'])) ? $_ENV['LARAVEL_ENV'].'/' : ''; + $directory = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'].'/' : ''; if ( ! array_key_exists($file, static::$items) and file_exists($path = APP_PATH.'config/'.$directory.$file.EXT)) { From 8356151f71478921503b800661211e06694f29f9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 22:47:33 -0500 Subject: [PATCH 19/45] added support for environment configuration files. --- application/config/.gitignore | 2 ++ application/storage/db/.gitignore | 1 + public/index.php | 3 ++- system/config.php | 13 ++++++++++--- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 application/config/.gitignore diff --git a/application/config/.gitignore b/application/config/.gitignore new file mode 100644 index 00000000..2b706e2b --- /dev/null +++ b/application/config/.gitignore @@ -0,0 +1,2 @@ +local/* +staging/* \ No newline at end of file diff --git a/application/storage/db/.gitignore b/application/storage/db/.gitignore index e69de29b..6a91a439 100644 --- a/application/storage/db/.gitignore +++ b/application/storage/db/.gitignore @@ -0,0 +1 @@ +*.sqlite \ No newline at end of file diff --git a/public/index.php b/public/index.php index aed6bb74..30ea8a1b 100644 --- a/public/index.php +++ b/public/index.php @@ -15,8 +15,9 @@ define('BASE_PATH', realpath('../').'/'); define('APP_PATH', realpath('../application').'/'); define('SYS_PATH', realpath('../system').'/'); -define('PUBLIC_PATH', realpath(__DIR__.'/')); +define('CONFIG_PATH', APP_PATH.'config/'); define('PACKAGE_PATH', APP_PATH.'packages/'); +define('PUBLIC_PATH', realpath(__DIR__.'/')); // -------------------------------------------------------------- // Define the PHP file extension. diff --git a/system/config.php b/system/config.php index ec459195..5cc0d30f 100644 --- a/system/config.php +++ b/system/config.php @@ -95,17 +95,24 @@ private static function parse($key) /** * Load all of the configuration items from a file. * + * If it exists, the configuration file in the application/config directory will be loaded first. + * Any environment specific configuration files will be merged with the root file. + * * @param string $file * @return void */ public static function load($file) { - $directory = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'].'/' : ''; + if (array_key_exists($file, static::$items)) return; - if ( ! array_key_exists($file, static::$items) and file_exists($path = APP_PATH.'config/'.$directory.$file.EXT)) + $config = (file_exists($path = CONFIG_PATH.$file.EXT)) ? require $path : array(); + + if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/'.$file.EXT)) { - static::$items[$file] = require $path; + $config = array_merge($config, require $path); } + + return static::$items[$file] = $config; } } \ No newline at end of file From 2c18083572b5d5e21e7466796020c8dc3aff0c5f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 23:20:19 -0500 Subject: [PATCH 20/45] make view->find method protected instead of private. --- system/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/view.php b/system/view.php index 40b64467..4c1d5466 100644 --- a/system/view.php +++ b/system/view.php @@ -82,7 +82,7 @@ public function get() * * @return string */ - private function find() + protected function find() { if (file_exists($path = APP_PATH.'views/'.$this->view.EXT)) { From 79e814cd935e05bac5dc22cf60680543c0c34431 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 23:32:25 -0500 Subject: [PATCH 21/45] modified readme and license. --- license.txt | 19 ------------------- public/index.php | 3 +-- readme.md | 3 --- readme.txt | 10 ++++++++++ unlicense.txt | 24 ++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 24 deletions(-) delete mode 100644 license.txt delete mode 100644 readme.md create mode 100644 readme.txt create mode 100644 unlicense.txt diff --git a/license.txt b/license.txt deleted file mode 100644 index 49ab775e..00000000 --- a/license.txt +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2011 Taylor Otwell - taylorotwell@gmail.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/public/index.php b/public/index.php index 30ea8a1b..2e067c82 100644 --- a/public/index.php +++ b/public/index.php @@ -5,8 +5,7 @@ * @package Laravel * @version 1.3.0 * @author Taylor Otwell - * @license MIT License - * @link http://laravel.com + * @link http://laravel.com */ // -------------------------------------------------------------- diff --git a/readme.md b/readme.md deleted file mode 100644 index b498e6bd..00000000 --- a/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# Laravel - A Clean & Classy PHP Framework - -## For complete documentation: http://laravel.com \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 00000000..52e8b5d9 --- /dev/null +++ b/readme.txt @@ -0,0 +1,10 @@ +Laravel - A Clean & Classy PHP Framework + +For complete documentation: http://laravel.com + +Laravel is a clean and classy framework for PHP web development. Freeing you +from spaghetti code, Laravel helps you create wonderful applications using +simple, expressive syntax. Development should be a creative experience that you +enjoy, not something that is painful. + +Creator: Taylor Otwell \ No newline at end of file diff --git a/unlicense.txt b/unlicense.txt new file mode 100644 index 00000000..00d2e135 --- /dev/null +++ b/unlicense.txt @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to \ No newline at end of file From 2837af68f58619652783eb71834d3b8046b2f89a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Jul 2011 23:33:22 -0500 Subject: [PATCH 22/45] removed line breaks from readme. --- readme.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/readme.txt b/readme.txt index 52e8b5d9..f591e533 100644 --- a/readme.txt +++ b/readme.txt @@ -2,9 +2,6 @@ Laravel - A Clean & Classy PHP Framework For complete documentation: http://laravel.com -Laravel is a clean and classy framework for PHP web development. Freeing you -from spaghetti code, Laravel helps you create wonderful applications using -simple, expressive syntax. Development should be a creative experience that you -enjoy, not something that is painful. +Laravel is a clean and classy framework for PHP web development. Freeing you from spaghetti code, Laravel helps you create wonderful applications using simple, expressive syntax. Development should be a creative experience that you enjoy, not something that is painful. Creator: Taylor Otwell \ No newline at end of file From 8cea0232569ea6f742e0adbf1f2781f2cfb39629 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 08:13:49 -0500 Subject: [PATCH 23/45] Remove staging from config .gitignore. --- application/config/.gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/config/.gitignore b/application/config/.gitignore index 2b706e2b..aa5195c6 100644 --- a/application/config/.gitignore +++ b/application/config/.gitignore @@ -1,2 +1 @@ -local/* -staging/* \ No newline at end of file +local/* \ No newline at end of file From 989ba6743b64bc251edab633ba486f9928f768d7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 08:24:32 -0500 Subject: [PATCH 24/45] Added support for specifying columns when paginating. --- system/db/query.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/system/db/query.php b/system/db/query.php index 3482f8c8..c4383d52 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -458,12 +458,26 @@ private function aggregate($aggregator, $column) * Get paginated query results. * * @param int $per_page + * @param array $columns * @return Paginator */ - public function paginate($per_page) + public function paginate($per_page, $columns = array('*')) { + $select = $this->select; + $total = $this->count(); + // Every query clears the SELECT clause, so we store the contents of the clause + // before executing the count query and then put the contents back in afterwards. + if ( ! is_null($select)) + { + $this->select = $select; + } + else + { + $this->select($columns); + } + $current_page = \System\Paginator::page($total, $per_page); return \System\Paginator::make($this->for_page($current_page, $per_page)->get(), $total, $per_page); From f4f82d1761a81078d529e890ebcb3b976154eb25 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 14:35:44 -0500 Subject: [PATCH 25/45] Added View::of method and $view->partial() method. --- system/view.php | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/system/view.php b/system/view.php index 4c1d5466..8f6d5197 100644 --- a/system/view.php +++ b/system/view.php @@ -49,6 +49,25 @@ public static function make($view, $data = array()) return new static($view, $data); } + /** + * Create a new named view instance. + * + * @param string $view + * @param array $data + * @return View + */ + public static function of($view, $data = array()) + { + $views = Config::get('view.names'); + + if ( ! array_key_exists($view, $views)) + { + throw new \Exception("Named view [$view] is not defined."); + } + + return static::make($views[$view], $data); + } + /** * Get the parsed content of the view. * @@ -98,6 +117,19 @@ protected function find() } } + /** + * Add a view instance to the view data. + * + * @param string $key + * @param string $view + * @param array $data + * @return View + */ + public function partial($key, $view, $data = array()) + { + return $this->bind($key, View::make($view, $data)); + } + /** * Add a key / value pair to the view data. * @@ -118,14 +150,7 @@ public static function __callStatic($method, $parameters) { if (strpos($method, 'of_') === 0) { - $views = Config::get('view.names'); - - if ( ! array_key_exists($view = substr($method, 3), $views)) - { - throw new \Exception("Named view [$view] is not defined."); - } - - return static::make($views[$view], (isset($parameters[0]) and is_array($parameters[0])) ? $parameters[0] : array()); + return static::of(substr($method, 3), Arr::get($parameters, 0, array())); } } From 14c8878b67444afa39aec083f09b4dc2e26e6cd0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 14:36:47 -0500 Subject: [PATCH 26/45] Switch make call to static in partial method. --- system/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/view.php b/system/view.php index 8f6d5197..798e7f6b 100644 --- a/system/view.php +++ b/system/view.php @@ -127,7 +127,7 @@ protected function find() */ public function partial($key, $view, $data = array()) { - return $this->bind($key, View::make($view, $data)); + return $this->bind($key, static::make($view, $data)); } /** From 5ad61844ec2b6d7b0683b181394966fc2824c737 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 15:27:42 -0500 Subject: [PATCH 27/45] Moved auto-loader into public/index.php. --- public/index.php | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/public/index.php b/public/index.php index 2e067c82..42cb6754 100644 --- a/public/index.php +++ b/public/index.php @@ -8,6 +8,8 @@ * @link http://laravel.com */ +$time = microtime(true); + // -------------------------------------------------------------- // Define the framework paths. // -------------------------------------------------------------- @@ -15,8 +17,12 @@ define('APP_PATH', realpath('../application').'/'); define('SYS_PATH', realpath('../system').'/'); define('CONFIG_PATH', APP_PATH.'config/'); +define('LIBRARY_PATH', APP_PATH.'libraries/'); +define('MODEL_PATH', APP_PATH.'models/'); define('PACKAGE_PATH', APP_PATH.'packages/'); define('PUBLIC_PATH', realpath(__DIR__.'/')); +define('ROUTE_PATH', APP_PATH.'routes/'); +define('VIEW_PATH', APP_PATH.'views/'); // -------------------------------------------------------------- // Define the PHP file extension. @@ -32,7 +38,25 @@ // -------------------------------------------------------------- // Register the auto-loader. // -------------------------------------------------------------- -spl_autoload_register(require SYS_PATH.'loader'.EXT); +spl_autoload_register(function($class) +{ + $file = strtolower(str_replace('\\', '/', $class)); + + if (array_key_exists($class, $aliases = System\Config::get('aliases'))) + { + return class_alias($aliases[$class], $class); + } + + foreach (array(BASE_PATH, MODEL_PATH, LIBRARY_PATH) as $directory) + { + if (file_exists($path = $directory.$file.EXT)) + { + require $path; + + return; + } + } +}); // -------------------------------------------------------------- // Set the error reporting and display levels. @@ -91,9 +115,9 @@ // ---------------------------------------------------------- if (is_null($response)) { - $route = System\Router::route(Request::method(), Request::uri()); + $route = System\Router::route(System\Request::method(), System\Request::uri()); - $response = (is_null($route)) ? System\Response::make(View::make('error/404'), 404) : $route->call(); + $response = (is_null($route)) ? System\Response::make(System\View::make('error/404'), 404) : $route->call(); } else { @@ -121,4 +145,6 @@ // -------------------------------------------------------------- // Send the response to the browser. // -------------------------------------------------------------- -$response->send(); \ No newline at end of file +$response->send(); + +echo (microtime(true) - $time) * 1000; \ No newline at end of file From 4ed6d488ca74d7fc9b78c521fbf238254e9e38cf Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 15:29:38 -0500 Subject: [PATCH 28/45] Added SYS_VIEW_PATH constant. --- public/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public/index.php b/public/index.php index 42cb6754..70cfc3cf 100644 --- a/public/index.php +++ b/public/index.php @@ -22,6 +22,7 @@ define('PACKAGE_PATH', APP_PATH.'packages/'); define('PUBLIC_PATH', realpath(__DIR__.'/')); define('ROUTE_PATH', APP_PATH.'routes/'); +define('SYS_VIEW_PATH', SYS_PATH.'views/'); define('VIEW_PATH', APP_PATH.'views/'); // -------------------------------------------------------------- From a4e8375febaa45cb89461a8e3f70b1d93360e07e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 15:31:10 -0500 Subject: [PATCH 29/45] Use view path constants in view->find() method. --- system/view.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/view.php b/system/view.php index 798e7f6b..5db1345a 100644 --- a/system/view.php +++ b/system/view.php @@ -103,11 +103,11 @@ public function get() */ protected function find() { - if (file_exists($path = APP_PATH.'views/'.$this->view.EXT)) + if (file_exists($path = VIEW_PATH.$this->view.EXT)) { return $path; } - elseif (file_exists($path = SYS_PATH.'views/'.$this->view.EXT)) + elseif (file_exists($path = SYS_VIEW_PATH.$this->view.EXT)) { return $path; } From 6b9b0ad5cd208ca2f60abebf340084243cefca8d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 15:31:56 -0500 Subject: [PATCH 30/45] remove unnecessary else. --- system/view.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/system/view.php b/system/view.php index 5db1345a..bcfc9750 100644 --- a/system/view.php +++ b/system/view.php @@ -111,10 +111,8 @@ protected function find() { return $path; } - else - { - throw new \Exception("View [".$this->view."] doesn't exist."); - } + + throw new \Exception("View [".$this->view."] doesn't exist."); } /** From 7bbee401b239563406818ba88aa6aac46f326731 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 15:40:48 -0500 Subject: [PATCH 31/45] Added Response::error method. --- system/response.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/system/response.php b/system/response.php index c1734d2b..3a3f7dd6 100644 --- a/system/response.php +++ b/system/response.php @@ -101,6 +101,18 @@ public static function make($content, $status = 200) return new static($content, $status); } + /** + * Factory for creating new error response instances. + * + * @param int $code + * @param array $data + * @return Response + */ + public static function error($code, $data = array()) + { + return static::make(View::make('error/'.$code, $data), $code); + } + /** * Take a value returned by a route and prepare a Response instance. * From b796ef1bd7ac0448edb831cd020a85d193fc150f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 16:24:41 -0500 Subject: [PATCH 32/45] Remove time echo from index.php. Whoops! --- public/index.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/public/index.php b/public/index.php index 70cfc3cf..b0b63b90 100644 --- a/public/index.php +++ b/public/index.php @@ -8,8 +8,6 @@ * @link http://laravel.com */ -$time = microtime(true); - // -------------------------------------------------------------- // Define the framework paths. // -------------------------------------------------------------- @@ -146,6 +144,4 @@ // -------------------------------------------------------------- // Send the response to the browser. // -------------------------------------------------------------- -$response->send(); - -echo (microtime(true) - $time) * 1000; \ No newline at end of file +$response->send(); \ No newline at end of file From d8cab0a7b689647612cdee59b98adc9f625693ba Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 17:01:59 -0500 Subject: [PATCH 33/45] Tweak framework constants. --- public/index.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/index.php b/public/index.php index b0b63b90..8744f1c1 100644 --- a/public/index.php +++ b/public/index.php @@ -9,16 +9,20 @@ */ // -------------------------------------------------------------- -// Define the framework paths. +// Define the core framework paths. // -------------------------------------------------------------- -define('BASE_PATH', realpath('../').'/'); define('APP_PATH', realpath('../application').'/'); +define('BASE_PATH', realpath('../').'/'); +define('PUBLIC_PATH', realpath(__DIR__.'/')); define('SYS_PATH', realpath('../system').'/'); + +// -------------------------------------------------------------- +// Define various other framework paths. +// -------------------------------------------------------------- define('CONFIG_PATH', APP_PATH.'config/'); define('LIBRARY_PATH', APP_PATH.'libraries/'); define('MODEL_PATH', APP_PATH.'models/'); define('PACKAGE_PATH', APP_PATH.'packages/'); -define('PUBLIC_PATH', realpath(__DIR__.'/')); define('ROUTE_PATH', APP_PATH.'routes/'); define('SYS_VIEW_PATH', SYS_PATH.'views/'); define('VIEW_PATH', APP_PATH.'views/'); From 1cf4431659de2a0ffb6cc9775938d378b77dfa5a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 22:11:16 -0500 Subject: [PATCH 34/45] added a few more path constants. --- public/index.php | 7 +++++-- system/cache/driver/file.php | 8 ++++---- system/db/connector.php | 2 +- system/session/driver/file.php | 8 ++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/public/index.php b/public/index.php index 8744f1c1..bc862839 100644 --- a/public/index.php +++ b/public/index.php @@ -12,18 +12,21 @@ // Define the core framework paths. // -------------------------------------------------------------- define('APP_PATH', realpath('../application').'/'); -define('BASE_PATH', realpath('../').'/'); -define('PUBLIC_PATH', realpath(__DIR__.'/')); define('SYS_PATH', realpath('../system').'/'); +define('PUBLIC_PATH', realpath(__DIR__.'/')); +define('BASE_PATH', realpath('../').'/'); // -------------------------------------------------------------- // Define various other framework paths. // -------------------------------------------------------------- +define('CACHE_PATH', APP_PATH.'storage/cache/'); define('CONFIG_PATH', APP_PATH.'config/'); +define('DATABASE_PATH', APP_PATH.'storage/db/'); define('LIBRARY_PATH', APP_PATH.'libraries/'); define('MODEL_PATH', APP_PATH.'models/'); define('PACKAGE_PATH', APP_PATH.'packages/'); define('ROUTE_PATH', APP_PATH.'routes/'); +define('SESSION_PATH', APP_PATH.'storage/sessions/'); define('SYS_VIEW_PATH', SYS_PATH.'views/'); define('VIEW_PATH', APP_PATH.'views/'); diff --git a/system/cache/driver/file.php b/system/cache/driver/file.php index 442f1cfd..3b266d96 100644 --- a/system/cache/driver/file.php +++ b/system/cache/driver/file.php @@ -22,12 +22,12 @@ public function has($key) */ public function get($key) { - if ( ! file_exists(APP_PATH.'storage/cache/'.$key)) + if ( ! file_exists(CACHE_PATH.$key)) { return null; } - $cache = file_get_contents(APP_PATH.'storage/cache/'.$key); + $cache = file_get_contents(CACHE_PATH.$key); if (time() >= substr($cache, 0, 10)) { @@ -49,7 +49,7 @@ public function get($key) */ public function put($key, $value, $minutes) { - file_put_contents(APP_PATH.'storage/cache/'.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); + file_put_contents(CACHE_PATH.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); } /** @@ -60,7 +60,7 @@ public function put($key, $value, $minutes) */ public function forget($key) { - @unlink(APP_PATH.'storage/cache/'.$key); + @unlink(CACHE_PATH.$key); } } \ No newline at end of file diff --git a/system/db/connector.php b/system/db/connector.php index 13d44184..769f4f27 100644 --- a/system/db/connector.php +++ b/system/db/connector.php @@ -54,7 +54,7 @@ public static function connect($connection) */ private static function connect_to_sqlite($config) { - if (file_exists($path = APP_PATH.'storage/db/'.$config->database.'.sqlite')) + if (file_exists($path = DATABASE_PATH.$config->database.'.sqlite')) { return new \PDO('sqlite:'.$path, null, null, static::$options); } diff --git a/system/session/driver/file.php b/system/session/driver/file.php index 47c70f10..e6788ab0 100644 --- a/system/session/driver/file.php +++ b/system/session/driver/file.php @@ -10,7 +10,7 @@ class File implements \System\Session\Driver { */ public function load($id) { - if (file_exists($path = APP_PATH.'storage/sessions/'.$id)) + if (file_exists($path = SESSION_PATH.$id)) { return unserialize(file_get_contents($path)); } @@ -24,7 +24,7 @@ public function load($id) */ public function save($session) { - file_put_contents(APP_PATH.'storage/sessions/'.$session['id'], serialize($session), LOCK_EX); + file_put_contents(SESSION_PATH.$session['id'], serialize($session), LOCK_EX); } /** @@ -35,7 +35,7 @@ public function save($session) */ public function delete($id) { - @unlink(APP_PATH.'storage/sessions/'.$id); + @unlink(SESSION_PATH.$id); } /** @@ -46,7 +46,7 @@ public function delete($id) */ public function sweep($expiration) { - foreach (glob(APP_PATH.'storage/sessions/*') as $file) + foreach (glob(SESSION_PATH.'*') as $file) { if (filetype($file) == 'file' and filemtime($file) < $expiration) { From 306ecd3bfef220ad770aac3ba533ec487bfb6408 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 22:12:20 -0500 Subject: [PATCH 35/45] added the storage_path constant. --- application/config/error.php | 2 +- public/index.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/application/config/error.php b/application/config/error.php index d0029390..6b13b0d2 100644 --- a/application/config/error.php +++ b/application/config/error.php @@ -49,7 +49,7 @@ 'logger' => function($severity, $message) { - System\File::append(APP_PATH.'storage/log.txt', date('Y-m-d H:i:s').' '.$severity.' - '.$message.PHP_EOL); + System\File::append(STORAGE_PATH.'log.txt', date('Y-m-d H:i:s').' '.$severity.' - '.$message.PHP_EOL); }, ); \ No newline at end of file diff --git a/public/index.php b/public/index.php index bc862839..e92b43fa 100644 --- a/public/index.php +++ b/public/index.php @@ -27,6 +27,7 @@ define('PACKAGE_PATH', APP_PATH.'packages/'); define('ROUTE_PATH', APP_PATH.'routes/'); define('SESSION_PATH', APP_PATH.'storage/sessions/'); +define('STORAGE_PATH', APP_PATH.'storage/'); define('SYS_VIEW_PATH', SYS_PATH.'views/'); define('VIEW_PATH', APP_PATH.'views/'); From 066db38ddb84bee27cc1e408e05cef87bdbf51c7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 22:13:56 -0500 Subject: [PATCH 36/45] deprecated auto-loader file. moved to public/index.php. --- system/loader.php | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 system/loader.php diff --git a/system/loader.php b/system/loader.php deleted file mode 100644 index adf3a126..00000000 --- a/system/loader.php +++ /dev/null @@ -1,35 +0,0 @@ - Date: Tue, 26 Jul 2011 22:16:55 -0500 Subject: [PATCH 37/45] added db::first method. --- system/db.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/system/db.php b/system/db.php index 4769fc74..e2765f61 100644 --- a/system/db.php +++ b/system/db.php @@ -33,6 +33,19 @@ public static function connection($connection = null) return static::$connections[$connection]; } + /** + * Execute a SQL query against the connection and return the first result. + * + * @param string $sql + * @param array $bindings + * @param string $connection + * @return object + */ + public static function first($sql, $bindings = array(), $connection = null) + { + return (count($results = static::query($sql, $bindings, $connection)) > 0) ? $results[0] : null; + } + /** * Execute a SQL query against the connection. * @@ -46,7 +59,7 @@ public static function connection($connection = null) * @param string $sql * @param array $bindings * @param string $connection - * @return mixed + * @return array */ public static function query($sql, $bindings = array(), $connection = null) { From 7e439ab52efb54621ca7fade65480f6d7b4a5310 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 22:56:51 -0500 Subject: [PATCH 38/45] fixed bug in config has method. --- system/config.php | 7 +++++-- system/db/query.php | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/system/config.php b/system/config.php index 5cc0d30f..e1727da9 100644 --- a/system/config.php +++ b/system/config.php @@ -7,7 +7,7 @@ class Config { * * @var array */ - private static $items = array(); + public static $items = array(); /** * Determine if a configuration item or file exists. @@ -112,7 +112,10 @@ public static function load($file) $config = array_merge($config, require $path); } - return static::$items[$file] = $config; + if (count($config) > 0) + { + static::$items[$file] = $config; + } } } \ No newline at end of file diff --git a/system/db/query.php b/system/db/query.php index c4383d52..5260f9a8 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -413,7 +413,6 @@ public function find($id, $columns = array('*')) */ public function first($columns = array('*')) { - return (count($results = $this->take(1)->get($columns)) > 0) ? $results[0] : null; } From c76d0fb66906eea2d55993433933378c87604ce0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 23:23:34 -0500 Subject: [PATCH 39/45] use language in paginator class. --- system/lang.php | 10 ++++++---- system/paginator.php | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/system/lang.php b/system/lang.php index 711d489d..c02f11a6 100644 --- a/system/lang.php +++ b/system/lang.php @@ -9,21 +9,21 @@ class Lang { * * @var array */ - private static $lines = array(); + public static $lines = array(); /** * The key of the line that is being requested. * * @var string */ - private $key; + public $key; /** * The place-holder replacements. * * @var array */ - private $replacements = array(); + public $replacements = array(); /** * Create a new Lang instance. @@ -117,7 +117,9 @@ private function parse($key) */ private function load($file, $language) { - if ( ! array_key_exists($language.$file, static::$lines) and file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT)) + if (array_key_exists($language.$file, static::$lines)) return; + + if (file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT)) { static::$lines[$language.$file] = require $path; } diff --git a/system/paginator.php b/system/paginator.php index 14113b6d..e9d5861b 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -150,7 +150,7 @@ private function slider($adjacent) */ public function previous() { - $text = Lang::line('pagination.previous')->get(); + $text = Lang::line('pagination.previous')->get($this->language); return ($this->page > 1) ? $this->link($this->page - 1, $text, 'prev_page').' ' : HTML::span($text, array('class' => 'disabled prev_page')).' '; } @@ -162,7 +162,7 @@ public function previous() */ public function next() { - $text = Lang::line('pagination.next')->get(); + $text = Lang::line('pagination.next')->get($this->language); return ($this->page < $this->last_page) ? $this->link($this->page + 1, $text, 'next_page') : HTML::span($text, array('class' => 'disabled next_page')); } From 0ca2171071c312378c086b32d9a8ad9d73a580bc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 23:26:04 -0500 Subject: [PATCH 40/45] added lang_path constant. --- public/index.php | 1 + system/lang.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index e92b43fa..d7cf0932 100644 --- a/public/index.php +++ b/public/index.php @@ -22,6 +22,7 @@ define('CACHE_PATH', APP_PATH.'storage/cache/'); define('CONFIG_PATH', APP_PATH.'config/'); define('DATABASE_PATH', APP_PATH.'storage/db/'); +define('LANG_PATH', APP_PATH.'lang/'); define('LIBRARY_PATH', APP_PATH.'libraries/'); define('MODEL_PATH', APP_PATH.'models/'); define('PACKAGE_PATH', APP_PATH.'packages/'); diff --git a/system/lang.php b/system/lang.php index c02f11a6..7a0b177e 100644 --- a/system/lang.php +++ b/system/lang.php @@ -119,7 +119,7 @@ private function load($file, $language) { if (array_key_exists($language.$file, static::$lines)) return; - if (file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT)) + if (file_exists($path = LANG_PATH.$language.'/'.$file.EXT)) { static::$lines[$language.$file] = require $path; } From c870fdbe5734a630bde00da163f087482ce05405 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 26 Jul 2011 23:28:24 -0500 Subject: [PATCH 41/45] trimmed readme. --- readme.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index f591e533..52e8b5d9 100644 --- a/readme.txt +++ b/readme.txt @@ -2,6 +2,9 @@ Laravel - A Clean & Classy PHP Framework For complete documentation: http://laravel.com -Laravel is a clean and classy framework for PHP web development. Freeing you from spaghetti code, Laravel helps you create wonderful applications using simple, expressive syntax. Development should be a creative experience that you enjoy, not something that is painful. +Laravel is a clean and classy framework for PHP web development. Freeing you +from spaghetti code, Laravel helps you create wonderful applications using +simple, expressive syntax. Development should be a creative experience that you +enjoy, not something that is painful. Creator: Taylor Otwell \ No newline at end of file From 095c2362347bea48a7a40b0f5321f9ea6015ab48 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2011 08:48:00 -0500 Subject: [PATCH 42/45] Fixed empty result set bug in paginator class. --- system/paginator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/paginator.php b/system/paginator.php index e9d5861b..1045b831 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -93,7 +93,7 @@ public static function page($total, $per_page) if (is_numeric($page) and $page > $last_page = ceil($total / $per_page)) { - return $last_page; + return ($last_page > 0) ? $last_page : 1; } return ($page < 1 or filter_var($page, FILTER_VALIDATE_INT) === false) ? 1 : $page; From 77331efc9d4ed8ee839c121fa49bb3f30af3c24a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2011 08:51:11 -0500 Subject: [PATCH 43/45] Fix slash bug in url class. --- system/url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/url.php b/system/url.php index 0346f019..30cd3c2d 100644 --- a/system/url.php +++ b/system/url.php @@ -25,7 +25,7 @@ public static function to($url = '', $https = false, $asset = false) $base = ($https and strpos($base, 'http://') === 0) ? 'https://'.substr($base, 7) : $base; - return $base.'/'.ltrim($url, '/'); + return rtrim($base, '/').'/'.ltrim($url, '/'); } /** From 60f69659ea3b95b4677d8e150c82d5ac59efe90e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2011 12:02:11 -0500 Subject: [PATCH 44/45] Added Router::call method for making HMVC requests. --- system/router.php | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/system/router.php b/system/router.php index e7328759..71c09dee 100644 --- a/system/router.php +++ b/system/router.php @@ -3,11 +3,27 @@ class Router { /** - * All of the loaded routes. + * All of the loaded routes keyed by route file. * * @var array */ - public static $routes; + private static $routes = array(); + + /** + * Simulate a request to a given route. Useful for implementing HMVC. + * + * @param array|string $parameters + * @return Response + */ + public static function call($parameters) + { + $route = static::route('GET', (is_array($parameters)) ? implode('/', $parameters) : (string) $parameters); + + if ( ! is_null($route)) + { + return $route->call(); + } + } /** * Search a set of routes for the route matching a method and URI. @@ -18,22 +34,19 @@ class Router { */ public static function route($method, $uri) { - if (is_null(static::$routes)) - { - static::$routes = static::load($uri); - } + $routes = static::load($uri); // Put the request method and URI in route form. // Routes begin with the request method and a forward slash. $uri = $method.' /'.trim($uri, '/'); // Is there an exact match for the request? - if (isset(static::$routes[$uri])) + if (isset($routes[$uri])) { - return Request::$route = new Route($uri, static::$routes[$uri]); + return Request::$route = new Route($uri, $routes[$uri]); } - foreach (static::$routes as $keys => $callback) + foreach ($routes as $keys => $callback) { // Only check routes that have multiple URIs or wildcards. // Other routes would have been caught by the check for literal matches. @@ -58,7 +71,7 @@ public static function route($method, $uri) */ public static function load($uri) { - $base = require APP_PATH.'routes'.EXT; + $base = (isset(static::$routes[$path = APP_PATH.'routes'.EXT])) ? static::$routes[$path] : static::$routes[$path] = require $path; return (is_dir(APP_PATH.'routes') and $uri !== '') ? array_merge(static::load_from_directory($uri), $base) : $base; } @@ -77,9 +90,13 @@ private static function load_from_directory($uri) // Iterate backwards through the URI looking for the deepest matching file. foreach (array_reverse($segments, true) as $key => $value) { - if (file_exists($path = APP_PATH.'routes/'.implode('/', array_slice($segments, 0, $key + 1)).EXT)) + if (isset(static::$routes[$path = ROUTE_PATH.implode('/', array_slice($segments, 0, $key + 1)).EXT])) { - return require $path; + return static::$routes[$path]; + } + elseif (file_exists($path)) + { + return static::$routes[$path] = require $path; } } From 45cc0f171591bb03e53ca01ae36bbe6dc3aa6722 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2011 13:16:13 -0500 Subject: [PATCH 45/45] Make Router::$routes public. --- system/router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/router.php b/system/router.php index 71c09dee..731d64f0 100644 --- a/system/router.php +++ b/system/router.php @@ -7,7 +7,7 @@ class Router { * * @var array */ - private static $routes = array(); + public static $routes = array(); /** * Simulate a request to a given route. Useful for implementing HMVC.