From 7317b5857b2583b5b79ac4848e33232583b758e1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 11 Oct 2011 21:27:16 -0500 Subject: [PATCH] refactored welcome pages. --- application/composers.php | 8 --- application/config/error.php | 13 +--- application/views/error/404.php | 64 -------------------- application/views/error/500.php | 55 ----------------- application/views/error/exception.php | 66 -------------------- application/views/home/index.php | 66 ++------------------ laravel/bootstrap/core.php | 1 + laravel/database/connection.php | 34 +++++++++++ laravel/database/grammars/grammar.php | 86 ++++++++++++++------------- laravel/str.php | 49 +++++++++++++++ laravel/view.php | 13 ++-- laravel/views/error/404.php | 34 +++++++++++ laravel/views/error/500.php | 53 +++++++++++++++++ public/css/laravel.css | 76 +++++++++++++++++++++++ public/index.php | 2 +- 15 files changed, 311 insertions(+), 309 deletions(-) delete mode 100644 application/views/error/404.php delete mode 100644 application/views/error/500.php delete mode 100644 application/views/error/exception.php create mode 100644 laravel/views/error/404.php create mode 100644 laravel/views/error/500.php create mode 100644 public/css/laravel.css diff --git a/application/composers.php b/application/composers.php index 5acd4d6c..6e61babb 100644 --- a/application/composers.php +++ b/application/composers.php @@ -37,16 +37,8 @@ return array( | // | }) | - | The "shared" composer is called for every view. This allows the - | convenient binding of global data or assets. - | */ - 'shared' => function($view) - { - // This composer is called for every view. - }, - 'home.index' => array('name' => 'home', function($view) { // This composer is called for the "home.index" view. diff --git a/application/config/error.php b/application/config/error.php index 6cb77488..8d30867a 100644 --- a/application/config/error.php +++ b/application/config/error.php @@ -49,18 +49,11 @@ return array( 'handler' => function($exception, $severity, $message, $config) { - if ($config['detail']) - { - $data = compact('exception', 'severity', 'message'); + $data = compact('exception', 'severity', 'message'); - $response = Response::view('error.exception', $data)->status(500); - } - else - { - $response = Response::error('500'); - } + $data['detailed'] = $config['detail']; - $response->send(); + Response::error('500', $data)->send(); }, /* diff --git a/application/views/error/404.php b/application/views/error/404.php deleted file mode 100644 index 4513dbe0..00000000 --- a/application/views/error/404.php +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - Error 404 - Not Found - - - - -
- - -

- -

We're really sorry, but we couldn't find the resource you requested.

- -

Perhaps you would like to go to our instead?

-
- - \ No newline at end of file diff --git a/application/views/error/500.php b/application/views/error/500.php deleted file mode 100644 index fefb6aea..00000000 --- a/application/views/error/500.php +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - Error 500 - Internal Server Error - - - - -
- - -

- -

We're really sorry, but something went wrong while we were processing your request.

- -

Perhaps you would like to go to our instead?

-
- - \ No newline at end of file diff --git a/application/views/error/exception.php b/application/views/error/exception.php deleted file mode 100644 index 25b3987e..00000000 --- a/application/views/error/exception.php +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - Laravel - <?php echo $severity; ?> - - - - -
-

- -

Message

- -
- -

Stack Trace

- -
getTraceAsString(); ?>
-
- - \ No newline at end of file diff --git a/application/views/home/index.php b/application/views/home/index.php index 51afb94b..88e5486f 100644 --- a/application/views/home/index.php +++ b/application/views/home/index.php @@ -6,70 +6,16 @@ Laravel - A Framework For Web Artisans
-

Welcome to Laravel

+ + +

Welcome To Laravel

+ +

A Framework For Web Artisans

You have successfully installed the Laravel framework. Laravel is a simple framework diff --git a/laravel/bootstrap/core.php b/laravel/bootstrap/core.php index 2a3a2403..4d2dfcd1 100644 --- a/laravel/bootstrap/core.php +++ b/laravel/bootstrap/core.php @@ -20,6 +20,7 @@ define('ROUTE_PATH', APP_PATH.'routes/'); define('SESSION_PATH', STORAGE_PATH.'sessions/'); define('SYS_CONFIG_PATH', SYS_PATH.'config/'); define('SYS_LANG_PATH', SYS_PATH.'language/'); +define('SYS_VIEW_PATH', SYS_PATH.'views/'); define('VIEW_PATH', APP_PATH.'views/'); define('EXT', '.php'); diff --git a/laravel/database/connection.php b/laravel/database/connection.php index 2790b8a9..ebd695b6 100644 --- a/laravel/database/connection.php +++ b/laravel/database/connection.php @@ -109,11 +109,45 @@ class Connection { */ public function query($sql, $bindings = array()) { + $sql = $this->transform($sql, $bindings); + $this->queries[] = compact('sql', 'bindings'); return $this->execute($this->pdo->prepare(trim($sql)), $bindings); } + /** + * Transform an SQL query into an executable query. + * + * Laravel provides a convenient short-cut when writing raw queries for + * handling cumbersome "where in" statements. This method will transform + * those segments into their full SQL counterparts. + * + * @param string $sql + * @param array $bindings + * @return string + */ + protected function transform($sql, $bindings) + { + if (strpos($sql, '(...)') === false) return $sql; + + for ($i = 0; $i < count($bindings); $i++) + { + // If the binding is an array, we can assume it is being used to fill + // a "where in" condition, so we will replace the next place-holder + // in the query with the correct number of parameters based on the + // number of elements in this binding. + if (is_array($bindings[$i])) + { + $parameters = implode(', ', array_fill(0, count($bindings[$i]), '?')); + + $sql = preg_replace('~\(\.\.\.\)~', "({$parameters})", $sql, 1); + } + } + + return $sql; + } + /** * Execute a prepared PDO statement and return the appropriate results. * diff --git a/laravel/database/grammars/grammar.php b/laravel/database/grammars/grammar.php index 257f71f3..acb1e1df 100644 --- a/laravel/database/grammars/grammar.php +++ b/laravel/database/grammars/grammar.php @@ -19,9 +19,9 @@ class Grammar { /** * 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 pased into each component - * compiler for convenience. + * 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 @@ -30,11 +30,15 @@ class Grammar { { $sql = array(); - // Iterate through each query component, calling the compiler for that - // component, and passing the query instance into the compiler. + // Iterate through each query component, calling the compiler + // for that component, and passing the query instance into + // the compiler. foreach ($this->components as $component) { - if ( ! is_null($query->$component)) $sql[] = call_user_func(array($this, $component), $query); + if ( ! is_null($query->$component)) + { + $sql[] = call_user_func(array($this, $component), $query); + } } return implode(' ', Arr::without($sql, array(null, ''))); @@ -59,9 +63,7 @@ class Grammar { */ protected function aggregate(Query $query) { - list($aggregator, $column) = array($query->aggregate['aggregator'], $query->aggregate['column']); - - return 'SELECT '.$aggregator.'('.$this->wrap($column).')'; + return 'SELECT '.$query->aggregate['aggregator'].'('.$this->wrap($query->aggregate['column']).')'; } /** @@ -83,15 +85,18 @@ class Grammar { */ protected function joins(Query $query) { - // Since creating a JOIN clause using string concatenation is a little cumbersome, - // we will create a format we can pass to "sprintf" to make things cleaner. + // Since creating a JOIN clause using string concatenation is a + // little cumbersome, we will create a format we can pass to + // "sprintf" to make things cleaner. $format = '%s JOIN %s ON %s %s %s'; foreach ($query->joins as $join) { extract($join, EXTR_SKIP); - list($column1, $column2) = array($this->wrap($column1), $this->wrap($column2)); + $column1 = $this->wrap($column1); + + $column2 = $this->wrap($column2); $sql[] = sprintf($format, $type, $this->wrap($table), $column1, $operator, $column2); } @@ -107,15 +112,16 @@ class Grammar { */ final protected function wheres(Query $query) { - // Each WHERE clause array has a "type" that is assigned by the query builder, and - // each type has its own compiler function. For example, "where in" queries are - // compiled by the "where_in" function. - // - // The only exception to this rule are "raw" where clauses, which are simply - // appended to the query as-is, without any further compiling. + // Each WHERE clause array has a "type" that is assigned by the + // query builder, and each type has its own compiler function. + // The only exception to this rule are "raw" where clauses, + // which are simply appended to the query as-is, without + // any further compiling. foreach ($query->wheres as $where) { - $sql[] = ($where['type'] == 'raw') ? $where['sql'] : $where['connector'].' '.$this->{$where['type']}($where); + $sql[] = ($where['type'] !== 'raw') + ? $where['connector'].' '.$this->{$where['type']}($where) + : $where['sql']; } if (isset($sql)) return implode(' ', array_merge(array('WHERE 1 = 1'), $sql)); @@ -207,20 +213,20 @@ class Grammar { */ public function insert(Query $query, $values) { - // Force every insert to be treated like a batch insert. This simply makes creating - // the SQL syntax a little easier on us since we can always treat the values as if - // is an array containing multiple inserts. + // Force every insert to be treated like a batch insert. + // This simply makes creating the SQL syntax a little + // easier on us since we can always treat the values + // as if is an array containing multiple inserts. if ( ! is_array(reset($values))) $values = array($values); - // Since we only care about the column names, we can pass any of the insert arrays - // into the "columnize" method. The names should be the same for every insert. + // Since we only care about the column names, we can pass + // any of the insert arrays into the "columnize" method. + // The names should be the same for every insert. $columns = $this->columnize(array_keys(reset($values))); - // We need to create a string of comma-delimited insert segments. Each segment contains - // PDO place-holders for each value being inserted into the table. So, if we are inserting - // into three columns, the string should look like this: - // - // (?, ?, ?), (?, ?, ?), (?, ?, ?) + // We need to create a string of comma-delimited insert + // segments. Each segment contains PDO place-holders for + // each value being inserted into the table. $parameters = implode(', ', array_fill(0, count($values), '('.$this->parameterize(reset($values)).')')); return 'INSERT INTO '.$this->wrap($query->from).' ('.$columns.') VALUES '.$parameters; @@ -229,8 +235,9 @@ class Grammar { /** * Compile a SQL UPDATE statment from a Query instance. * - * Note: Since UPDATE statements can be limited by a WHERE clause, this method will - * use the same WHERE clause compilation functions as the "select" method. + * Note: Since UPDATE statements can be limited by a WHERE clause, + * this method will use the same WHERE clause compilation + * functions as the "select" method. * * @param Query $query * @param array $values @@ -255,17 +262,16 @@ class Grammar { } /** - * The following functions primarily serve as utility functions for the grammar. - * They perform tasks such as wrapping values in keyword identifiers or creating - * variable lists of bindings. Most likely, they will not need to change across - * various database systems. + * The following functions primarily serve as utility functions + * for the grammar. They perform tasks such as wrapping values + * in keyword identifiers or creating variable lists of bindings. */ /** * Create a comma-delimited list of wrapped column names. * - * Optionally, an "append" value may be passed to the method. This value will be - * appended to every wrapped column name. + * Optionally, an "append" value may be passed to the method. + * This value will be appended to every wrapped column name. * * @param array $columns * @param string $append @@ -284,9 +290,9 @@ class Grammar { /** * Wrap a value in keyword identifiers. * - * They keyword identifier used by the method is specified as a property on - * the grammar class so it can be conveniently overriden without changing - * the wrapping logic itself. + * They keyword identifier used by the method is specified as + * a property on the grammar class so it can be conveniently + * overriden without changing the wrapping logic itself. * * @param string $value * @return string diff --git a/laravel/str.php b/laravel/str.php index 10066696..b01d397b 100644 --- a/laravel/str.php +++ b/laravel/str.php @@ -98,6 +98,55 @@ class Str { return strlen($value); } + /** + * Limit the number of chars in a string + * + * + * // Limit the characters + * echo Str::limit_chars('taylor otwell', 3); + * results in 'tay...' + * + * + * @param string $value + * @param int $length + * @param string $end + * @return string + */ + public static function limit($value, $length = 100, $end = '...') + { + if (static::length($value) <= $length) return $value; + + if (function_exists('mb_substr')) + { + return mb_substr($value, 0, $length).$end; + } + + return substr($value, 0, $length).$end; + } + + /** + * Limit the number of words in a string + * + * + * // Limit the words + * echo Str::limit_chars('This is a sentence.', 3); + * results in 'This is a...' + * + * + * @param string $value + * @param int $length + * @param string $end + * @return string + */ + public static function limit_words($value, $length = 100, $end = '...') + { + $count = str_word_count($value,1); + + if ($count <= $length) return $value; + + return implode(' ',array_slice($count,0,$length)).$end; + } + /** * Convert a string to 7-bit ASCII. * diff --git a/laravel/view.php b/laravel/view.php index cd54d553..1739265a 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -59,7 +59,14 @@ class View { foreach (array(EXT, BLADE_EXT) as $extension) { - if (file_exists($path = VIEW_PATH.$view.$extension)) return $path; + if (file_exists($path = VIEW_PATH.$view.$extension)) + { + return $path; + } + elseif (file_exists($path = SYS_VIEW_PATH.$view.$extension)) + { + return $path; + } } throw new \Exception("View [$view] does not exist."); @@ -145,10 +152,6 @@ class View { { if (is_null(static::$composers)) static::$composers = require APP_PATH.'composers'.EXT; - // The shared composer is called for every view instance. This allows the - // convenient binding of global view data or partials within a single method. - if (isset(static::$composers['shared'])) call_user_func(static::$composers['shared'], $view); - if (isset(static::$composers[$view->view])) { foreach ((array) static::$composers[$view->view] as $key => $value) diff --git a/laravel/views/error/404.php b/laravel/views/error/404.php new file mode 100644 index 00000000..8f7b48a0 --- /dev/null +++ b/laravel/views/error/404.php @@ -0,0 +1,34 @@ + + + + + + Error 404 - Not Found + + + + +

+ + + + +

+ +

Server Error: 404 (Not Found)

+ +

What does this mean?

+ +

+ We couldn't find the page you requested on our servers. We're really sorry about that. + It's our fault, not yours. We'll work hard to get this page back online as soon as possible. +

+ +

+ Perhaps you would like to go to our ? +

+
+ + \ No newline at end of file diff --git a/laravel/views/error/500.php b/laravel/views/error/500.php new file mode 100644 index 00000000..6698e6ff --- /dev/null +++ b/laravel/views/error/500.php @@ -0,0 +1,53 @@ + + + + + + Error 500 - Internal Server Error + + + + +
+ + + + +

+ +

Server Error: 500 (Internal Server Error)

+ +

What does this mean?

+ +

+ Something went wrong on our servers while we were processing your request. + We're really sorry about this, and will work hard to get this resolved as + soon as possible. +

+ +

+ Perhaps you would like to go to our ? +

+ + +

Error Message:

+ +
+ +

Stack Trace:

+ + getTraceAsString()); + ?> + +
+ +
+ + \ No newline at end of file diff --git a/public/css/laravel.css b/public/css/laravel.css new file mode 100644 index 00000000..9485d3bb --- /dev/null +++ b/public/css/laravel.css @@ -0,0 +1,76 @@ +@import url(http://fonts.googleapis.com/css?family=Ubuntu); + +body { + background: #eee; + color: #6d6d6d; + font: normal normal normal 14px/1.253 Ubuntu, sans-serif; + margin:0; + min-width: 800px; + padding:0; +} + +#main { + background-clip: padding-box; + background-color: #fff; + border:1px solid #ccc; + border-radius: 5px; + box-shadow: 0 0 10px #cdcdcd; + margin: 50px auto 0; + padding: 30px; + width: 700px; + position: relative; +} + +#main h1 { + font-family: 'Ubuntu'; + font-size: 38px; + margin: 0 0 10px 0; + padding: 0; +} + +#main h2 { + color: #999; + font-size: 18px; + letter-spacing: 3px; + margin: 0 0 25px 0; + padding: 0 0 0 0; +} + +#main h3 { + color: #999; + margin-top: 24px; + padding: 0 0 0 0; +} + +#main h3 { + font-size: 18px; +} + +#main p { + line-height: 25px; + margin: 10px 0; +} + +#main pre { + background-color: #333; + border-left: 1px solid #d8d8d8; + border-top: 1px solid #d8d8d8; + border-radius: 5px; + color: #eee; + padding: 10px; +} + +#main ul { + margin: 10px 0; + padding: 0 30px; +} + +#main li { + margin: 5px 0; +} + +#main .marker { + float: left; + left: -24px; top: -24px; + position: absolute; +} \ No newline at end of file diff --git a/public/index.php b/public/index.php index 7c03c0d8..06006852 100644 --- a/public/index.php +++ b/public/index.php @@ -45,4 +45,4 @@ $public = __DIR__; */ require $laravel.'/laravel.php'; -echo number_format((microtime(true) - START_TIME) * 1000, 2); \ No newline at end of file +//echo number_format((microtime(true) - START_TIME) * 1000, 2); \ No newline at end of file