Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit of laravel!

  • Loading branch information...
commit a188d62105532fcf2a2839309fb71b862d904612 0 parents
@taylorotwell taylorotwell authored
Showing with 6,942 additions and 0 deletions.
  1. 0  application/cache/.gitignore
  2. +98 −0 application/config/application.php
  3. +32 −0 application/config/auth.php
  4. +52 −0 application/config/cache.php
  5. +60 −0 application/config/db.php
  6. +34 −0 application/config/error.php
  7. +89 −0 application/config/session.php
  8. 0  application/db/.gitignore
  9. +41 −0 application/filters.php
  10. 0  application/lang/en/.gitignore
  11. 0  application/logs/.gitignore
  12. 0  application/models/.gitignore
  13. 0  application/packages/.gitignore
  14. +25 −0 application/routes.php
  15. 0  application/sessions/.gitignore
  16. +56 −0 application/views/error/404.php
  17. +56 −0 application/views/error/500.php
  18. +77 −0 application/views/home/index.php
  19. +19 −0 license.txt
  20. +5 −0 public/.htaccess
  21. BIN  public/favicon.ico
  22. +133 −0 public/index.php
  23. +135 −0 system/auth.php
  24. +49 −0 system/benchmark.php
  25. +47 −0 system/cache.php
  26. +40 −0 system/cache/driver.php
  27. +95 −0 system/cache/driver/file.php
  28. +80 −0 system/cache/driver/memcached.php
  29. +26 −0 system/cache/factory.php
  30. +118 −0 system/config.php
  31. +78 −0 system/cookie.php
  32. +132 −0 system/crypt.php
  33. +111 −0 system/db.php
  34. +58 −0 system/db/connector.php
  35. +353 −0 system/db/eloquent.php
  36. +26 −0 system/db/eloquent/factory.php
  37. +272 −0 system/db/eloquent/hydrate.php
  38. +24 −0 system/db/eloquent/meta.php
  39. +132 −0 system/db/eloquent/relate.php
  40. +66 −0 system/db/eloquent/warehouse.php
  41. +593 −0 system/db/query.php
  42. +116 −0 system/db/query/compiler.php
  43. +145 −0 system/download.php
  44. +156 −0 system/error.php
  45. +51 −0 system/filter.php
  46. +327 −0 system/form.php
  47. +52 −0 system/hash.php
  48. +275 −0 system/html.php
  49. +230 −0 system/inflector.php
  50. +135 −0 system/input.php
  51. +178 −0 system/lang.php
  52. +50 −0 system/loader.php
  53. +102 −0 system/log.php
  54. +56 −0 system/memcached.php
  55. +66 −0 system/redirect.php
  56. +136 −0 system/request.php
  57. +252 −0 system/response.php
  58. +85 −0 system/route.php
  59. +148 −0 system/router.php
  60. +281 −0 system/session.php
  61. +37 −0 system/session/driver.php
  62. +78 −0 system/session/driver/db.php
  63. +64 −0 system/session/driver/file.php
  64. +49 −0 system/session/driver/memcached.php
  65. +29 −0 system/session/factory.php
  66. +85 −0 system/str.php
  67. +146 −0 system/text.php
  68. +132 −0 system/url.php
  69. +191 −0 system/view.php
  70. +78 −0 system/views/error/exception.php
0  application/cache/.gitignore
No changes.
98 application/config/application.php
@@ -0,0 +1,98 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application URL
+ |--------------------------------------------------------------------------
+ |
+ | The URL used to access your application. The trailing slash is optional.
+ |
+ | Note: Remove "index.php" from this URL when using mod_rewrite.
+ |
+ */
+
+ 'url' => 'http://localhost/index.php',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Language
+ |--------------------------------------------------------------------------
+ |
+ | The default language of your application. This language will be used by
+ | default by the Lang library when doing string localization.
+ |
+ | If you are not using the Lang library, this option isn't really important.
+ |
+ */
+
+ 'language' => 'en',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Timezone
+ |--------------------------------------------------------------------------
+ |
+ | The default timezone of your application. This timezone will be used when
+ | Laravel needs a date, such as when writing to a log file.
+ |
+ */
+
+ 'timezone' => 'UTC',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Key
+ |--------------------------------------------------------------------------
+ |
+ | Your application key should be a 32 character string that is totally
+ | random and secret. This key is used by the encryption class to generate
+ | secure, encrypted strings.
+ |
+ | If you will not be using the encryption class, this doesn't matter.
+ |
+ */
+
+ 'key' => '',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Class Aliases
+ |--------------------------------------------------------------------------
+ |
+ | Here, you can specify any class aliases that you would like registered
+ | when Laravel loads. Aliases are lazy-loaded, so add as many as you want.
+ |
+ | We have already setup a few to make your life easier.
+ |
+ */
+
+ 'aliases' => array(
+ 'Auth' => 'System\\Auth',
+ 'Benchmark' => 'System\\Benchmark',
+ 'Cache' => 'System\\Cache',
+ 'Config' => 'System\\Config',
+ 'Cookie' => 'System\\Cookie',
+ 'Crypt' => 'System\\Crypt',
+ 'Date' => 'System\\Date',
+ 'DB' => 'System\\DB',
+ 'Download' => 'System\\Download',
+ 'Eloquent' => 'System\\DB\\Eloquent',
+ 'Form' => 'System\\Form',
+ 'Hash' => 'System\\Hash',
+ 'HTML' => 'System\\HTML',
+ 'Inflector' => 'System\\Inflector',
+ 'Input' => 'System\\Input',
+ 'Lang' => 'System\\Lang',
+ 'URL' => 'System\\URL',
+ 'Redirect' => 'System\\Redirect',
+ 'Request' => 'System\\Request',
+ 'Response' => 'System\\Response',
+ 'Session' => 'System\\Session',
+ 'Str' => 'System\\Str',
+ 'Text' => 'System\\Text',
+ 'View' => 'System\View',
+ ),
+
+);
32 application/config/auth.php
@@ -0,0 +1,32 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Authentication Model
+ |--------------------------------------------------------------------------
+ |
+ | This model will be used by the Auth class when retrieving the users of
+ | your application. Feel free to change it to the name of your user model.
+ |
+ | Note: The authentication model must be an Eloquent model.
+ |
+ */
+
+ 'model' => 'User',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Authentication Username
+ |--------------------------------------------------------------------------
+ |
+ | The authentication username is the column on your users table that
+ | is considered the username of the user. Typically, this is either "email"
+ | or "username". However, you are free to make it whatever you wish.
+ |
+ */
+
+ 'username' => 'email',
+
+);
52 application/config/cache.php
@@ -0,0 +1,52 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Cache Driver
+ |--------------------------------------------------------------------------
+ |
+ | The name of the default cache driver for your application.
+ |
+ | Caching can be used to increase the performance of your application
+ | by storing commonly accessed data in memory or in a file.
+ |
+ | Supported Drivers: 'file', 'memcached'.
+ |
+ */
+
+ 'driver' => 'file',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Memcached Servers
+ |--------------------------------------------------------------------------
+ |
+ | Here you can define the Memcached servers used by your application.
+ |
+ | Memcached is a free and open source, high-performance, distributed memory
+ | object caching system, generic in nature, but intended for use in speeding
+ | up dynamic web applications by alleviating database load.
+ |
+ | For more information about Memcached, check out: http://memcached.org
+ |
+ */
+
+ 'servers' => array(
+ array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100),
+ ),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Memcached Key
+ |--------------------------------------------------------------------------
+ |
+ | This key will be prepended to items stored using Memcached to avoid
+ | collisions with other applications on the server.
+ |
+ */
+
+ 'key' => 'laravel',
+
+);
60 application/config/db.php
@@ -0,0 +1,60 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Default Database Connection
+ |--------------------------------------------------------------------------
+ |
+ | The name of your default database connection.
+ |
+ | This connection will be used by default for all database operations
+ | unless a different connection is specified when performing the operation.
+ |
+ */
+
+ 'default' => 'sqlite',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Database Connections
+ |--------------------------------------------------------------------------
+ |
+ | Here you can define all of the databases used by your application.
+ |
+ | Supported Drivers: 'mysql', 'pgsql', 'sqlite'.
+ |
+ | Note: When using the SQLite driver, the path and "sqlite" extention will
+ | be added automatically. You only need to specify the database name.
+ |
+ */
+
+ 'connections' => array(
+
+ 'sqlite' => array(
+ 'driver' => 'sqlite',
+ 'database' => 'application',
+ ),
+
+ 'mysql' => array(
+ 'driver' => 'mysql',
+ 'host' => 'localhost',
+ 'database' => 'database',
+ 'username' => 'root',
+ 'password' => 'password',
+ 'charset' => 'utf8',
+ ),
+
+ 'pgsql' => array(
+ 'driver' => 'pgsql',
+ 'host' => 'localhost',
+ 'database' => 'database',
+ 'username' => 'root',
+ 'password' => 'password',
+ 'charset' => 'utf8',
+ ),
+
+ ),
+
+);
34 application/config/error.php
@@ -0,0 +1,34 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Error Detail
+ |--------------------------------------------------------------------------
+ |
+ | Would you like detailed error messages?
+ |
+ | If your application is in production, consider turning off error details
+ | for enhanced security and user experience.
+ |
+ */
+
+ 'detail' => true,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Error Logging
+ |--------------------------------------------------------------------------
+ |
+ | Would you like errors to be logged? Error logging can be extremely
+ | helpful when debugging a production application.
+ |
+ | Note: When error logging is enabled, errors will be logged even when
+ | error detail is disabled.
+ |
+ */
+
+ 'log' => false,
+
+);
89 application/config/session.php
@@ -0,0 +1,89 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Driver
+ |--------------------------------------------------------------------------
+ |
+ | The name of the session driver for your application.
+ |
+ | Since HTTP is stateless, sessions are used to maintain "state" across
+ | multiple requests from the same user of your application.
+ |
+ | Supported Drivers: 'file', 'db', 'memcached'.
+ |
+ */
+
+ 'driver' => '',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Database
+ |--------------------------------------------------------------------------
+ |
+ | The database table on which the session should be stored.
+ |
+ | If you are not using database based sessions, don't worry about this.
+ |
+ */
+
+ 'table' => 'sessions',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Lifetime
+ |--------------------------------------------------------------------------
+ |
+ | How many minutes can a session be idle before expiring?
+ |
+ */
+
+ 'lifetime' => 60,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Expiration On Close
+ |--------------------------------------------------------------------------
+ |
+ | Should the session expire when the user's web browser closes?
+ |
+ */
+
+ 'expire_on_close' => false,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Cookie Path
+ |--------------------------------------------------------------------------
+ |
+ | The path for which the session cookie is available.
+ |
+ */
+
+ 'path' => '/',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Cookie Domain
+ |--------------------------------------------------------------------------
+ |
+ | The domain for which the session cookie is available.
+ |
+ */
+
+ 'domain' => null,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Session Cookie HTTPS
+ |--------------------------------------------------------------------------
+ |
+ | Should the session cookie only be transported over HTTPS?
+ |
+ */
+
+ 'https' => false,
+
+);
0  application/db/.gitignore
No changes.
41 application/filters.php
@@ -0,0 +1,41 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Filters
+ |--------------------------------------------------------------------------
+ |
+ | Filters provide a convenient method for filtering access to your route
+ | functions. To make your life easier, we have already setup basic filters
+ | for authentication and CSRF protection.
+ |
+ | For more information, check out: http://laravel.com/docs/basics/routes#filters
+ |
+ */
+
+ 'before' => function()
+ {
+ // Do stuff before every request is executed.
+ },
+
+
+ 'after' => function($response)
+ {
+ // Do stuff after every request is executed.
+ },
+
+
+ 'auth' => function()
+ {
+ return ( ! Auth::check()) ? Redirect::to_login() : null;
+ },
+
+
+ 'csrf' => function()
+ {
+ return (Input::get('csrf_token') !== Form::raw_token()) ? Response::view('error/500', 500) : null;
+ },
+
+);
0  application/lang/en/.gitignore
No changes.
0  application/logs/.gitignore
No changes.
0  application/models/.gitignore
No changes.
0  application/packages/.gitignore
No changes.
25 application/routes.php
@@ -0,0 +1,25 @@
+<?php
+
+return array(
+
+ /*
+ |--------------------------------------------------------------------------
+ | Application Routes
+ |--------------------------------------------------------------------------
+ |
+ | Here is the "definition", or the public API, of your application.
+ |
+ | To add functionality to your application, you add to the array located
+ | in this file. It's a breeze. Just tell Laravel the request method and
+ | URI a function should respond to.
+ |
+ | To learn more, check out: http://laravel.com/docs/basics/routes
+ |
+ */
+
+ 'GET /' => function()
+ {
+ return View::make('home/index');
+ },
+
+);
0  application/sessions/.gitignore
No changes.
56 application/views/error/404.php
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>404 - Not Found</title>
+
+ <link href='http://fonts.googleapis.com/css?family=Ubuntu&amp;subset=latin' rel='stylesheet' type='text/css'>
+
+ <style type="text/css">
+ body {
+ background-color: #fff;
+ margin: 45px 0 0 0;
+ font-family: 'Ubuntu', sans-serif;
+ font-size: 16px;
+ color: #3f3f3f;
+ }
+
+ h1 {
+ font-size: 40px;
+ margin: 0 0 10px 0;
+ }
+
+ a {
+ color: #000;
+ }
+
+ #wrapper {
+ width: 740px;
+ margin: 0 auto;
+ }
+
+ #content {
+ padding: 10px 10px 10px 10px;
+ background-color: #ffebe8;
+ border: 1px solid #dd3c10;
+ border-radius: 10px;
+ }
+ </style>
+</head>
+<body>
+ <div id="wrapper">
+ <?php
+ $messages = array('Should we ask for directions?', 'This doesn\'t look familiar.', 'We need a map.');
+ $message = $messages[mt_rand(0, 2)];
+ ?>
+
+ <h1><?php echo $message; ?></h1>
+
+ <div id="content">
+ The resource you requested was not found.
+ <br /><br />
+ Would you like go to our <a href="<?php echo System\Config::get('application.url'); ?>">home page</a> instead?
+ </div>
+ </div>
+</body>
+</html>
56 application/views/error/500.php
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>500 - Internal Server Error</title>
+
+ <link href='http://fonts.googleapis.com/css?family=Ubuntu&amp;subset=latin' rel='stylesheet' type='text/css'>
+
+ <style type="text/css">
+ body {
+ background-color: #fff;
+ margin: 45px 0 0 0;
+ font-family: 'Ubuntu', sans-serif;
+ font-size: 16px;
+ color: #3f3f3f;
+ }
+
+ h1 {
+ font-size: 40px;
+ margin: 0 0 10px 0;
+ }
+
+ a {
+ color: #000;
+ }
+
+ #wrapper {
+ width: 740px;
+ margin: 0 auto;
+ }
+
+ #content {
+ padding: 10px 10px 10px 10px;
+ background-color: #ffebe8;
+ border: 1px solid #dd3c10;
+ border-radius: 10px;
+ }
+ </style>
+</head>
+<body>
+ <div id="wrapper">
+ <?php
+ $messages = array('Whoops!', 'Oh no!', 'Ouch!');
+ $message = $messages[mt_rand(0, 2)];
+ ?>
+
+ <h1><?php echo $message; ?></h1>
+
+ <div id="content">
+ An error occured while we were processing your request.
+ <br /><br />
+ Would you like go to our <a href="<?php echo System\Config::get('application.url'); ?>">home page</a> instead?
+ </div>
+ </div>
+</body>
+</html>
77 application/views/home/index.php
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Welcome To Laravel!</title>
+
+ <link href="http://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css" media="all" />
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
+
+ <style type="text/css">
+ body {
+ background-color: #fff;
+ font-family: 'Ubuntu', sans-serif;
+ font-size: 16px;
+ color: #3f3f3f;
+ }
+
+ h1 {
+ font-size: 40px;
+ color: #6d6d6d;
+ margin: 0 0 10px 0;
+ text-shadow: 1px 1px #000;
+ }
+
+ a {
+ color: #000;
+ }
+
+ #wrapper {
+ width: 740px;
+ }
+
+ #content {
+ padding: 10px 10px 10px 10px;
+ background-color: #eee;
+ border-radius: 10px;
+ }
+
+ #footer {
+ font-size: 12px;
+ padding-top: 10px;
+ text-align: right;
+ }
+ </style>
+
+ <script type="text/javascript">
+ $(document).ready(function(){
+ $(window).resize(function(){
+ $('#wrapper').css({
+ position:'absolute',
+ left: ($(window).width() - $('#wrapper').outerWidth()) / 2,
+ top: ($(window).height() - $('#wrapper').outerHeight()) / 3
+ });
+ });
+
+ $(window).resize();
+ });
+ </script>
+</head>
+<body>
+ <div id="wrapper">
+ <h1>Laravel</h1>
+
+ <div id="content">
+ You have successfully installed Laravel.
+
+ <br /><br />
+
+ Perhaps you would like to <a href="http://laravel.com/docs">peruse the documentation</a> or <a href="http://github.com/taylorotwell/laravel">contribute on GitHub</a>?
+ </div>
+
+ <div id="footer">
+ <?php echo Benchmark::memory(); ?>mb &middot; <?php echo Benchmark::check('laravel'); ?>ms
+ </div>
+ </div>
+</body>
+</html>
19 license.txt
@@ -0,0 +1,19 @@
+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.
5 public/.htaccess
@@ -0,0 +1,5 @@
+Options +FollowSymLinks
+RewriteEngine on
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule . /index.php [L]
BIN  public/favicon.ico
Binary file not shown
133 public/index.php
@@ -0,0 +1,133 @@
+<?php
+/**
+ * Laravel - A clean and classy framework for PHP web development.
+ *
+ * @package Laravel
+ * @version 1.0.0 Beta 1
+ * @author Taylor Otwell
+ * @license MIT License
+ * @link http://laravel.com
+ */
+
+// --------------------------------------------------------------
+// Set the framework starting time.
+// --------------------------------------------------------------
+define('LARAVEL_START', microtime(true));
+
+// --------------------------------------------------------------
+// Define the framework paths.
+// --------------------------------------------------------------
+define('APP_PATH', realpath('../application').'/');
+define('SYS_PATH', realpath('../system').'/');
+define('BASE_PATH', realpath('../').'/');
+
+// --------------------------------------------------------------
+// Define the PHP file extension.
+// --------------------------------------------------------------
+define('EXT', '.php');
+
+// --------------------------------------------------------------
+// Load the configuration and string classes.
+// --------------------------------------------------------------
+require SYS_PATH.'config'.EXT;
+require SYS_PATH.'str'.EXT;
+
+// --------------------------------------------------------------
+// Register the auto-loader.
+// --------------------------------------------------------------
+spl_autoload_register(require SYS_PATH.'loader'.EXT);
+
+// --------------------------------------------------------------
+// Set the Laravel starting time in the Benchmark class.
+// --------------------------------------------------------------
+System\Benchmark::$marks['laravel'] = LARAVEL_START;
+
+// --------------------------------------------------------------
+// Set the error reporting level.
+// --------------------------------------------------------------
+error_reporting((System\Config::get('error.detail')) ? E_ALL | E_STRICT : 0);
+
+// --------------------------------------------------------------
+// Register the error handlers.
+// --------------------------------------------------------------
+set_exception_handler(function($e)
+{
+ System\Error::handle($e);
+});
+
+set_error_handler(function($number, $error, $file, $line)
+{
+ System\Error::handle(new ErrorException($error, 0, $number, $file, $line));
+});
+
+register_shutdown_function(function()
+{
+ if ( ! is_null($error = error_get_last()))
+ {
+ System\Error::handle(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
+ }
+});
+
+// --------------------------------------------------------------
+// Set the default timezone.
+// --------------------------------------------------------------
+date_default_timezone_set(System\Config::get('application.timezone'));
+
+// --------------------------------------------------------------
+// Load the session.
+// --------------------------------------------------------------
+if (System\Config::get('session.driver') != '')
+{
+ System\Session::load();
+}
+
+// --------------------------------------------------------------
+// Execute the global "before" filter.
+// --------------------------------------------------------------
+$response = System\Filter::call('before');
+
+// --------------------------------------------------------------
+// Only execute the route function if the "before" filter did
+// not override by sending a response.
+// --------------------------------------------------------------
+if (is_null($response))
+{
+ // ----------------------------------------------------------
+ // Route the request to the proper route.
+ // ----------------------------------------------------------
+ $route = System\Router::route(Request::method(), Request::uri());
+
+ // ----------------------------------------------------------
+ // Execute the route function.
+ // ----------------------------------------------------------
+ if ( ! is_null($route))
+ {
+ $response = $route->call();
+ }
+ else
+ {
+ $response = System\Response::view('error/404', 404);
+ }
+}
+else
+{
+ $response = ( ! $response instanceof System\Response) ? new System\Response($response) : $response;
+}
+
+// ----------------------------------------------------------
+// Execute the global "after" filter.
+// ----------------------------------------------------------
+System\Filter::call('after', array($response));
+
+// --------------------------------------------------------------
+// Close the session.
+// --------------------------------------------------------------
+if (System\Config::get('session.driver') != '')
+{
+ System\Session::close();
+}
+
+// --------------------------------------------------------------
+// Send the response to the browser.
+// --------------------------------------------------------------
+$response->send();
135 system/auth.php
@@ -0,0 +1,135 @@
+<?php namespace System;
+
+class Auth {
+
+ /**
+ * The current user of the application.
+ *
+ * @var object
+ */
+ public static $user;
+
+ /**
+ * The key used to store the user ID in the session.
+ *
+ * @var string
+ */
+ private static $key = 'laravel_user_id';
+
+ /**
+ * Determine if the current user of the application is authenticated.
+ *
+ * @return bool
+ */
+ public static function check()
+ {
+ return ( ! is_null(static::user()));
+ }
+
+ /**
+ * Get the current user of the application.
+ *
+ * @return object
+ */
+ public static function user()
+ {
+ // -----------------------------------------------------
+ // Verify that sessions are enabled.
+ // -----------------------------------------------------
+ if (Config::get('session.driver') == '')
+ {
+ throw new \Exception("You must specify a session driver before using the Auth class.");
+ }
+
+ // -----------------------------------------------------
+ // Get the authentication model.
+ // -----------------------------------------------------
+ $model = static::model();
+
+ // -----------------------------------------------------
+ // Load the user using the ID stored in the session.
+ // -----------------------------------------------------
+ if (is_null(static::$user) and Session::has(static::$key))
+ {
+ static::$user = $model::find(Session::get(static::$key));
+ }
+
+ return static::$user;
+ }
+
+ /**
+ * Attempt to login a user.
+ *
+ * @param string $username
+ * @param string $password
+ */
+ public static function login($username, $password)
+ {
+ // -----------------------------------------------------
+ // Get the authentication model.
+ // -----------------------------------------------------
+ $model = static::model();
+
+ // -----------------------------------------------------
+ // Get the user by username.
+ // -----------------------------------------------------
+ $user = $model::where(Config::get('auth.username'), '=', $username)->first();
+
+ if ( ! is_null($user))
+ {
+ // -----------------------------------------------------
+ // Hash the password.
+ // -----------------------------------------------------
+ $password = (isset($user->salt)) ? Hash::make($password, $user->salt)->value : sha1($password);
+
+ // -----------------------------------------------------
+ // Verify that the passwords match.
+ // -----------------------------------------------------
+ if ($user->password == $password)
+ {
+ // -----------------------------------------------------
+ // Set the user property.
+ // -----------------------------------------------------
+ static::$user = $user;
+
+ // -----------------------------------------------------
+ // Store the user ID in the session.
+ // -----------------------------------------------------
+ Session::put(static::$key, $user->id);
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Logout the current user of the application.
+ *
+ * @return void
+ */
+ public static function logout()
+ {
+ // -----------------------------------------------------
+ // Remove the user ID from the session.
+ // -----------------------------------------------------
+ Session::forget(static::$key);
+
+ // -----------------------------------------------------
+ // Clear the current user variable.
+ // -----------------------------------------------------
+ static::$user = null;
+ }
+
+ /**
+ * Get the authentication model.
+ *
+ * @return string
+ */
+ private static function model()
+ {
+ return '\\'.Config::get('auth.model');
+ }
+
+}
49 system/benchmark.php
@@ -0,0 +1,49 @@
+<?php namespace System;
+
+class Benchmark {
+
+ /**
+ * Benchmark starting times.
+ *
+ * @var array
+ */
+ public static $marks = array();
+
+ /**
+ * Start a benchmark.
+ *
+ * @param string $name
+ * @return void
+ */
+ public static function start($name)
+ {
+ static::$marks[$name] = microtime(true);
+ }
+
+ /**
+ * Get the elapsed time in milliseconds since starting a benchmark.
+ *
+ * @param string $name
+ * @return float
+ */
+ public static function check($name)
+ {
+ if (array_key_exists($name, static::$marks))
+ {
+ return number_format((microtime(true) - static::$marks[$name]) * 1000, 2);
+ }
+
+ return 0.0;
+ }
+
+ /**
+ * Get the total memory usage in megabytes.
+ *
+ * @return float
+ */
+ public static function memory()
+ {
+ return number_format(memory_get_usage() / 1024 / 1024, 2);
+ }
+
+}
47 system/cache.php
@@ -0,0 +1,47 @@
+<?php namespace System;
+
+class Cache {
+
+ /**
+ * The active cache drivers.
+ *
+ * @var Cache\Driver
+ */
+ private static $drivers = array();
+
+ /**
+ * Get the cache driver instance.
+ *
+ * @param string $driver
+ * @return Cache\Driver
+ */
+ public static function driver($driver = null)
+ {
+ if ( ! array_key_exists($driver, static::$drivers))
+ {
+ // --------------------------------------------------
+ // If no driver was specified, use the default.
+ // --------------------------------------------------
+ if (is_null($driver))
+ {
+ $driver = Config::get('cache.driver');
+ }
+
+ // --------------------------------------------------
+ // Create the cache driver.
+ // --------------------------------------------------
+ static::$drivers[$driver] = Cache\Factory::make($driver);
+ }
+
+ return static::$drivers[$driver];
+ }
+
+ /**
+ * Pass all other methods to the default driver.
+ */
+ public static function __callStatic($method, $parameters)
+ {
+ return call_user_func_array(array(static::driver(), $method), $parameters);
+ }
+
+}
40 system/cache/driver.php
@@ -0,0 +1,40 @@
+<?php namespace System\Cache;
+
+interface Driver {
+
+ /**
+ * Determine if an item exists in the cache.
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function has($key);
+
+ /**
+ * Get an item from the cache.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function get($key, $default = null);
+
+ /**
+ * Write an item to the cache.
+ *
+ * @param string $key
+ * @param mixed $value
+ * @param int $minutes
+ * @return void
+ */
+ public function put($key, $value, $minutes);
+
+ /**
+ * Delete an item from the cache.
+ *
+ * @param string $key
+ * @return void
+ */
+ public function forget($key);
+
+}
95 system/cache/driver/file.php
@@ -0,0 +1,95 @@
+<?php namespace System\Cache\Driver;
+
+class File implements \System\Cache\Driver {
+
+ /**
+ * All of the loaded cache items.
+ *
+ * @var array
+ */
+ private $items = array();
+
+ /**
+ * Determine if an item exists in the cache.
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function has($key)
+ {
+ return ( ! is_null($this->get($key)));
+ }
+
+ /**
+ * Get an item from the cache.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function get($key, $default = null)
+ {
+ // --------------------------------------------------
+ // If the item has already been loaded, return it.
+ // --------------------------------------------------
+ if (array_key_exists($key, $this->items))
+ {
+ return $this->items[$key];
+ }
+
+ // --------------------------------------------------
+ // Verify that the cache file exists.
+ // --------------------------------------------------
+ if ( ! file_exists(APP_PATH.'cache/'.$key))
+ {
+ return $default;
+ }
+
+ // --------------------------------------------------
+ // Read the contents of the cache file.
+ // --------------------------------------------------
+ $cache = file_get_contents(APP_PATH.'cache/'.$key);
+
+ // --------------------------------------------------
+ // Has the cache expired? The UNIX expiration time
+ // is stored at the beginning of the file.
+ // --------------------------------------------------
+ if (time() >= substr($cache, 0, 10))
+ {
+ $this->forget($key);
+
+ return $default;
+ }
+
+ return $this->items[$key] = unserialize(substr($cache, 10));
+ }
+
+ /**
+ * Write an item to the cache.
+ *
+ * @param string $key
+ * @param mixed $value
+ * @param int $minutes
+ * @return void
+ */
+ public function put($key, $value, $minutes)
+ {
+ // --------------------------------------------------
+ // The expiration time is stored as a UNIX timestamp
+ // at the beginning of the cache file.
+ // --------------------------------------------------
+ file_put_contents(APP_PATH.'cache/'.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX);
+ }
+
+ /**
+ * Delete an item from the cache.
+ *
+ * @param string $key
+ * @return void
+ */
+ public function forget($key)
+ {
+ @unlink(APP_PATH.'cache/'.$key);
+ }
+
+}
80 system/cache/driver/memcached.php
@@ -0,0 +1,80 @@
+<?php namespace System\Cache\Driver;
+
+class Memcached implements \System\Cache\Driver {
+
+ /**
+ * All of the loaded cache items.
+ *
+ * @var array
+ */
+ private $items = array();
+
+ /**
+ * Determine if an item exists in the cache.
+ *
+ * @param string $key
+ * @return bool
+ */
+ public function has($key)
+ {
+ return ( ! is_null($this->get($key)));
+ }
+
+ /**
+ * Get an item from the cache.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ */
+ public function get($key, $default = null)
+ {
+ // --------------------------------------------------
+ // If the item has already been loaded, return it.
+ // --------------------------------------------------
+ if (array_key_exists($key, $this->items))
+ {
+ return $this->items[$key];
+ }
+
+ // --------------------------------------------------
+ // Attempt to the get the item from cache.
+ // --------------------------------------------------
+ $cache = \System\Memcached::instance()->get(\System\Config::get('cache.key').$key);
+
+ // --------------------------------------------------
+ // Verify that the item was retrieved.
+ // --------------------------------------------------
+ if ($cache === false)
+ {
+ return $default;
+ }
+
+ return $this->items[$key] = $cache;
+ }
+
+ /**
+ * Write an item to the cache.
+ *
+ * @param string $key
+ * @param mixed $value
+ * @param int $minutes
+ * @return void
+ */
+ public function put($key, $value, $minutes)
+ {
+ \System\Memcached::instance()->set(\System\Config::get('cache.key').$key, $value, 0, $minutes * 60);
+ }
+
+ /**
+ * Delete an item from the cache.
+ *
+ * @param string $key
+ * @return void
+ */
+ public function forget($key)
+ {
+ \System\Memcached::instance()->delete(\System\Config::get('cache.key').$key);
+ }
+
+}
26 system/cache/factory.php
@@ -0,0 +1,26 @@
+<?php namespace System\Cache;
+
+class Factory {
+
+ /**
+ * Create a cache driver instance.
+ *
+ * @param string $driver
+ * @return Driver
+ */
+ public static function make($driver)
+ {
+ switch ($driver)
+ {
+ case 'file':
+ return new Driver\File;
+
+ case 'memcached':
+ return new Driver\Memcached;
+
+ default:
+ throw new \Exception("Cache driver [$driver] is not supported.");
+ }
+ }
+
+}
118 system/config.php
@@ -0,0 +1,118 @@
+<?php namespace System;
+
+class Config {
+
+ /**
+ * All of the loaded configuration items.
+ *
+ * @var array
+ */
+ private static $items = array();
+
+ /**
+ * Get a configuration item.
+ *
+ * @param string $key
+ * @return mixed
+ */
+ public static function get($key)
+ {
+ // ---------------------------------------------
+ // Parse the configuration key.
+ // ---------------------------------------------
+ list($file, $key) = static::parse($key);
+
+ // ---------------------------------------------
+ // Load the configuration file.
+ // ---------------------------------------------
+ static::load($file);
+
+ // ---------------------------------------------
+ // Return the requested item.
+ // ---------------------------------------------
+ return (array_key_exists($key, static::$items[$file])) ? static::$items[$file][$key] : null;
+ }
+
+ /**
+ * Set a configuration item.
+ *
+ * @param string $key
+ * @param mixed $value
+ * @return void
+ */
+ public static function set($file, $value)
+ {
+ // ---------------------------------------------
+ // Parse the configuration key.
+ // ---------------------------------------------
+ list($file, $key) = static::parse($key);
+
+ // ---------------------------------------------
+ // Load the configuration file.
+ // ---------------------------------------------
+ static::load($file);
+
+ // ---------------------------------------------
+ // Set the item's value.
+ // ---------------------------------------------
+ static::$items[$file][$key] = $value;
+ }
+
+ /**
+ * Parse a configuration key.
+ *
+ * @param string $key
+ * @return array
+ */
+ private static function parse($key)
+ {
+ // ---------------------------------------------
+ // Get the key segments.
+ // ---------------------------------------------
+ $segments = explode('.', $key);
+
+ // ---------------------------------------------
+ // Validate the key format.
+ // ---------------------------------------------
+ if (count($segments) < 2)
+ {
+ throw new \Exception("Invalid configuration key [$key].");
+ }
+
+ // ---------------------------------------------
+ // Return the file and item name.
+ // ---------------------------------------------
+ return array($segments[0], implode('.', array_slice($segments, 1)));
+ }
+
+ /**
+ * Load all of the configuration items.
+ *
+ * @param string $file
+ * @return void
+ */
+ public static function load($file)
+ {
+ // ---------------------------------------------
+ // If the file has already been loaded, bail.
+ // ---------------------------------------------
+ if (array_key_exists($file, static::$items))
+ {
+ return;
+ }
+
+ // ---------------------------------------------
+ // Verify that the configuration file exists.
+ // ---------------------------------------------
+ if ( ! file_exists($path = APP_PATH.'config/'.$file.EXT))
+ {
+ throw new \Exception("Configuration file [$file] does not exist.");
+ }
+
+ // ---------------------------------------------
+ // Load the configuration file.
+ // ---------------------------------------------
+ static::$items[$file] = require $path;
+ }
+
+}
78 system/cookie.php
@@ -0,0 +1,78 @@
+<?php namespace System;
+
+class Cookie {
+
+ /**
+ * Determine if a cookie exists.
+ *
+ * @param string $key
+ * @return bool
+ */
+ public static function has($key)
+ {
+ return ( ! is_null(static::get($key)));
+ }
+
+ /**
+ * Get the value of a cookie.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return string
+ */
+ public static function get($key, $default = null)
+ {
+ return (array_key_exists($key, $_COOKIE)) ? $_COOKIE[$key] : $default;
+ }
+
+ /**
+ * Set a "permanent" cookie. The cookie will last 5 years.
+ *
+ * @param string $key
+ * @param string $value
+ * @param string $path
+ * @param string $domain
+ * @param bool $secure
+ * @return bool
+ */
+ public static function forever($key, $value, $path = '/', $domain = null, $secure = false)
+ {
+ return static::put($key, $value, 2628000, $path, $domain, $secure);
+ }
+
+ /**
+ * Set the value of a cookie.
+ *
+ * @param string $key
+ * @param string $value
+ * @param int $minutes
+ * @param string $path
+ * @param string $domain
+ * @param bool $secure
+ * @return bool
+ */
+ public static function put($key, $value, $minutes = 0, $path = '/', $domain = null, $secure = false)
+ {
+ // ----------------------------------------------------------
+ // If the lifetime is less than zero, delete the cookie.
+ // ----------------------------------------------------------
+ if ($minutes < 0)
+ {
+ unset($_COOKIE[$key]);
+ }
+
+ return setcookie($key, $value, ($minutes != 0) ? time() + ($minutes * 60) : 0, $path, $domain, $secure);
+ }
+
+ /**
+ * Delete a cookie.
+ *
+ * @param string $key
+ * @return bool
+ */
+ public static function forget($key)
+ {
+ return static::put($key, null, -60);
+ }
+
+}
132 system/crypt.php
@@ -0,0 +1,132 @@
+<?php namespace System;
+
+class Crypt {
+
+ /**
+ * The encryption cipher.
+ *
+ * @var string
+ */
+ public static $cipher = 'rijndael-256';
+
+ /**
+ * The encryption mode.
+ *
+ * @var string
+ */
+ public static $mode = 'cbc';
+
+ /**
+ * Encrypt a value using the MCrypt library.
+ *
+ * @param string $value
+ * @return string
+ */
+ public static function encrypt($value)
+ {
+ // -----------------------------------------------------
+ // Determine the input vector source.
+ // -----------------------------------------------------
+ if (defined('MCRYPT_DEV_URANDOM'))
+ {
+ $random = MCRYPT_DEV_URANDOM;
+ }
+ elseif (defined('MCRYPT_DEV_RANDOM'))
+ {
+ $random = MCRYPT_DEV_RANDOM;
+ }
+ else
+ {
+ $random = MCRYPT_RAND;
+ }
+
+ // -----------------------------------------------------
+ // The system random number generator must be seeded.
+ // -----------------------------------------------------
+ if ($random === MCRYPT_RAND)
+ {
+ mt_srand();
+ }
+
+ // -----------------------------------------------------
+ // Create the input vector.
+ // -----------------------------------------------------
+ $iv = mcrypt_create_iv(static::iv_size(), $random);
+
+ // -----------------------------------------------------
+ // Encrypt the value using MCrypt.
+ // -----------------------------------------------------
+ $value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
+
+ // -----------------------------------------------------
+ // Use base64 encoding to get a string value.
+ // -----------------------------------------------------
+ return base64_encode($iv.$value);
+ }
+
+ /**
+ * Decrypt a value using the MCrypt library.
+ *
+ * @param string $value
+ * @return string
+ */
+ public static function decrypt($value)
+ {
+ // -----------------------------------------------------
+ // Decode the base64 value.
+ // -----------------------------------------------------
+ $value = base64_decode($value, true);
+
+ // -----------------------------------------------------
+ // Validate the base64 conversion.
+ // -----------------------------------------------------
+ if ( ! $value)
+ {
+ throw new \Exception('Decryption error. Input value is not valid base64 data.');
+ }
+
+ // -----------------------------------------------------
+ // Extract the input vector from the value.
+ // -----------------------------------------------------
+ $iv = substr($value, 0, static::iv_size());
+
+ // -----------------------------------------------------
+ // Remove the input vector from the value.
+ // -----------------------------------------------------
+ $value = substr($value, static::iv_size());
+
+ // -----------------------------------------------------
+ // Decrypt the value using MCrypt.
+ // -----------------------------------------------------
+ return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
+ }
+
+ /**
+ * Get the application key.
+ *
+ * @return string
+ */
+ private static function key()
+ {
+ // -----------------------------------------------------
+ // Validate the application key.
+ // -----------------------------------------------------
+ if (is_null($key = Config::get('application.key')) or $key == '')
+ {
+ throw new \Exception("The encryption class can not be used without an encryption key.");
+ }
+
+ return $key;
+ }
+
+ /**
+ * Get the input vector size for the cipher and mode.
+ *
+ * @return int
+ */
+ private static function iv_size()
+ {
+ return mcrypt_get_iv_size(static::$cipher, static::$mode);
+ }
+
+}
111 system/db.php
@@ -0,0 +1,111 @@
+<?php namespace System;
+
+class DB {
+
+ /**
+ * The active database connections.
+ *
+ * @var array
+ */
+ private static $connections = array();
+
+ /**
+ * Get a database connection.
+ *
+ * @param string $connection
+ * @return PDO
+ */
+ public static function connection($connection = null)
+ {
+ // ---------------------------------------------------
+ // If no connection was given, use the default.
+ // ---------------------------------------------------
+ if (is_null($connection))
+ {
+ $connection = Config::get('db.default');
+ }
+
+ // ---------------------------------------------------
+ // If we have already established this connection,
+ // simply return the existing connection.
+ // ---------------------------------------------------
+ if ( ! array_key_exists($connection, static::$connections))
+ {
+ // ---------------------------------------------------
+ // Get the database configurations.
+ // ---------------------------------------------------
+ $config = Config::get('db.connections');
+
+ // ---------------------------------------------------
+ // Verify the connection has been defined.
+ // ---------------------------------------------------
+ if ( ! array_key_exists($connection, $config))
+ {
+ throw new \Exception("Database connection [$connection] is not defined.");
+ }
+
+ // ---------------------------------------------------
+ // Establish the database connection.
+ // ---------------------------------------------------
+ static::$connections[$connection] = DB\Connector::connect((object) $config[$connection]);
+ }
+
+ return static::$connections[$connection];
+ }
+
+ /**
+ * Execute a SQL query against the connection.
+ *
+ * @param string $sql
+ * @param array $bindings
+ * @param string $connection
+ * @return mixed
+ */
+ public static function query($sql, $bindings = array(), $connection = null)
+ {
+ // ---------------------------------------------------
+ // Create a new PDO statement from the SQL.
+ // ---------------------------------------------------
+ $query = static::connection($connection)->prepare($sql);
+
+ // ---------------------------------------------------
+ // Execute the query with the bindings.
+ // ---------------------------------------------------
+ $result = $query->execute($bindings);
+
+ // ---------------------------------------------------
+ // For SELECT statements, return the results in an
+ // array of stdClasses.
+ //
+ // For UPDATE and DELETE statements, return the number
+ // or rows affected by the query.
+ //
+ // For INSERT statements, return a boolean.
+ // ---------------------------------------------------
+ if (strpos(Str::upper($sql), 'SELECT') === 0)
+ {
+ return $query->fetchAll(\PDO::FETCH_CLASS, 'stdClass');
+ }
+ elseif (strpos(Str::upper($sql), 'UPDATE') === 0 or strpos(Str::upper($sql), 'DELETE') === 0)
+ {
+ return $query->rowCount();
+ }
+ else
+ {
+ return $result;
+ }
+ }
+
+ /**
+ * Begin a fluent query against a table.
+ *
+ * @param string $table
+ * @param string $connection
+ * @return Query
+ */
+ public static function table($table, $connection = null)
+ {
+ return new DB\Query($table, $connection);
+ }
+
+}
58 system/db/connector.php
@@ -0,0 +1,58 @@
+<?php namespace System\DB;
+
+class Connector {
+
+ /**
+ * The PDO connection options.
+ *
+ * @var array
+ */
+ public static $options = array(
+ \PDO::ATTR_CASE => \PDO::CASE_LOWER,
+ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
+ \PDO::ATTR_ORACLE_NULLS => \PDO::NULL_NATURAL,
+ \PDO::ATTR_STRINGIFY_FETCHES => false,
+ );
+
+ /**
+ * Establish a PDO database connection.
+ *
+ * @param object $config
+ * @return PDO
+ */
+ public static function connect($config)
+ {
+ // ---------------------------------------------------
+ // Establish a SQLite PDO connection.
+ // ---------------------------------------------------
+ if ($config->driver == 'sqlite')
+ {
+ return new \PDO('sqlite:'.APP_PATH.'db/'.$config->database.'.sqlite', null, null, static::$options);
+ }
+ // ---------------------------------------------------
+ // Establish a MySQL or Postgres PDO connection.
+ // ---------------------------------------------------
+ elseif ($config->driver == 'mysql' or $config->driver == 'pgsql')
+ {
+ $connection = new \PDO($config->driver.':host='.$config->host.';dbname='.$config->database, $config->username, $config->password, static::$options);
+
+ // ---------------------------------------------------
+ // Set the correct character set.
+ // ---------------------------------------------------
+ if (isset($config->charset))
+ {
+ $connection->prepare("SET NAMES '".$config->charset."'")->execute();
+ }
+
+ return $connection;
+ }
+ // ---------------------------------------------------
+ // If the driver isn't supported, bail out.
+ // ---------------------------------------------------
+ else
+ {
+ throw new \Exception('Database driver '.$config->driver.' is not supported.');
+ }
+ }
+
+}
353 system/db/eloquent.php
@@ -0,0 +1,353 @@
+<?php namespace System\DB;
+
+abstract class Eloquent {
+
+ /**
+ * Indicates if the model exists in the database.
+ *
+ * @var bool
+ */
+ public $exists = false;
+
+ /**
+ * The model attributes.
+ *
+ * @var array
+ */
+ public $attributes = array();
+
+ /**
+ * The model's dirty attributes.
+ *
+ * @var array
+ */
+ public $dirty = array();
+
+ /**
+ * The model's ignored attributes.
+ *
+ * Ignored attributes will not be saved to the database, and
+ * are primarily used to hold relationships.
+ *
+ * @var array
+ */
+ public $ignore = array();
+
+ /**
+ * The relationships that should be eagerly loaded.
+ *
+ * @var array
+ */
+ public $includes = array();
+
+ /**
+ * The relationship type the model is currently resolving.
+ *
+ * @var string
+ */
+ public $relating;
+
+ /**
+ * The foreign key of the "relating" relationship.
+ *
+ * @var string
+ */
+ public $relating_key;
+
+ /**
+ * The table name of the model being resolved. Used during many-to-many eager loading.
+ *
+ * @var string
+ */
+ public $relating_table;
+
+ /**
+ * The model query instance.
+ *
+ * @var Query
+ */
+ public $query;
+
+ /**
+ * Create a new model instance and set the relationships
+ * that should be eagerly loaded.
+ *
+ * @return mixed
+ */
+ public static function with()
+ {
+ // -----------------------------------------------------
+ // Create a new model instance.
+ // -----------------------------------------------------
+ $model = Eloquent\Factory::make(get_called_class());
+
+ // -----------------------------------------------------
+ // Set the eager relationships.
+ // -----------------------------------------------------
+ $model->includes = func_get_args();
+
+ return $model;
+ }
+
+ /**
+ * Get a model by the primary key.
+ *
+ * @param int $id
+ * @return mixed
+ */
+ public static function find($id)
+ {
+ return Eloquent\Factory::make(get_called_class())->where('id', '=', $id)->first();
+ }
+
+ /**
+ * Get an array of models from the database.
+ *
+ * @return array
+ */
+ private function _get()
+ {
+ return Eloquent\Hydrate::from($this);
+ }
+
+ /**
+ * Get the first model result
+ *
+ * @return mixed
+ */
+ private function _first()
+ {
+ // -----------------------------------------------------
+ // Load the hydrated models.
+ // -----------------------------------------------------
+ $results = Eloquent\Hydrate::from($this->take(1));
+
+ // -----------------------------------------------------
+ // Return the first result.
+ // -----------------------------------------------------
+ if (count($results) > 0)
+ {
+ reset($results);
+
+ return current($results);
+ }
+ }
+
+ /**
+ * Retrieve the query for a 1:1 relationship.
+ *
+ * @param string $model
+ * @return mixed
+ */
+ public function has_one($model)
+ {
+ return Eloquent\Relate::has_one($model, $this);
+ }
+
+ /**
+ * Retrieve the query for a 1:* relationship.
+ *
+ * @param string $model
+ * @return mixed
+ */
+ public function has_many($model)
+ {
+ return Eloquent\Relate::has_many($model, $this);
+ }
+
+ /**
+ * Retrieve the query for a 1:1 belonging relationship.
+ *
+ * @param string $model
+ * @return mixed
+ */
+ public function belongs_to($model)
+ {
+ // -----------------------------------------------------
+ // Get the calling function name.
+ // -----------------------------------------------------
+ list(, $caller) = debug_backtrace(false);
+
+ return Eloquent\Relate::belongs_to($caller, $model, $this);
+ }
+
+ /**
+ * Retrieve the query for a *:* relationship.
+ *
+ * @param string $model
+ * @return mixed
+ */
+ public function has_many_and_belongs_to($model)
+ {
+ return Eloquent\Relate::has_many_and_belongs_to($model, $this);
+ }
+
+ /**
+ * Save the model to the database.
+ *
+ * @return void
+ */
+ public function save()
+ {
+ Eloquent\Warehouse::store($this);
+ }
+
+ /**
+ * Magic method for retrieving model attributes.
+ */
+ public function __get($key)
+ {
+ // -----------------------------------------------------
+ // Check the ignored attributes first.
+ // -----------------------------------------------------
+ if (array_key_exists($key, $this->ignore))
+ {
+ return $this->ignore[$key];
+ }
+
+ // -----------------------------------------------------
+ // Is the attribute actually a relationship?
+ // -----------------------------------------------------
+ if (method_exists($this, $key))
+ {
+ // -----------------------------------------------------
+ // Get the query / model for the relationship.
+ // -----------------------------------------------------
+ $model = $this->$key();
+
+ // -----------------------------------------------------
+ // Return the relationship results.
+ // -----------------------------------------------------
+ return ($this->relating == 'has_one' or $this->relating == 'belongs_to')
+ ? $this->ignore[$key] = $model->first()
+ : $this->ignore[$key] = $model->get();
+ }
+
+ // -----------------------------------------------------
+ // Check the "regular" attributes.
+ // -----------------------------------------------------
+ return (array_key_exists($key, $this->attributes)) ? $this->attributes[$key] : null;
+ }
+
+ /**
+ * Magic Method for setting model attributes.
+ */
+ public function __set($key, $value)
+ {
+ // -----------------------------------------------------
+ // Is the key actually a relationship?
+ // -----------------------------------------------------
+ if (method_exists($this, $key))
+ {
+ $this->ignore[$key] = $value;
+ }
+ else
+ {
+ // -----------------------------------------------------
+ // Add the value to the attributes.
+ // -----------------------------------------------------
+ $this->attributes[$key] = $value;
+ $this->dirty[$key] = $value;
+ }
+ }
+
+ /**
+ * Magic Method for determining if a model attribute is set.
+ */
+ public function __isset($key)
+ {
+ return (array_key_exists($key, $this->attributes) or array_key_exists($key, $this->ignore));
+ }
+
+ /**
+ * Magic Method for unsetting model attributes.
+ */
+ public function __unset($key)
+ {
+ unset($this->attributes[$key]);
+ unset($this->ignore[$key]);
+ unset($this->dirty[$key]);
+ }
+
+ /**
+ * Magic Method for handling dynamic method calls.
+ */
+ public function __call($method, $parameters)
+ {
+ // -----------------------------------------------------
+ // Is the "get" method being called?
+ // -----------------------------------------------------
+ if ($method == 'get')
+ {
+ return $this->_get();
+ }
+
+ // -----------------------------------------------------
+ // Is the "first" method being called?
+ // -----------------------------------------------------
+ if ($method == 'first')
+ {
+ return $this->_first();
+ }
+
+ // -----------------------------------------------------
+ // If the method is an aggregate function, just return
+ // the aggregate value from the query.
+ // -----------------------------------------------------
+ if (in_array($method, array('count', 'sum', 'min', 'max', 'avg')))
+ {
+ return call_user_func_array(array($this->query, $method), $parameters);
+ }
+
+ // -----------------------------------------------------
+ // Pass the method call to the query instance.
+ // -----------------------------------------------------
+ call_user_func_array(array($this->query, $method), $parameters);
+
+ return $this;
+ }
+
+ /**
+ * Magic Method for handling dynamic static method calls.
+ */
+ public static function __callStatic($method, $parameters)
+ {
+ // -----------------------------------------------------
+ // Create a new model instance.
+ // -----------------------------------------------------
+ $model = Eloquent\Factory::make(get_called_class());
+
+ // -----------------------------------------------------
+ // Do we need to return the entire table?
+ // -----------------------------------------------------
+ if ($method == 'get')
+ {
+ return $model->_get();
+ }
+
+ // -----------------------------------------------------
+ // Do we need to return the first model from the table?
+ // -----------------------------------------------------
+ if ($method == 'first')
+ {
+ return $model->_first();
+ }
+
+ // -----------------------------------------------------
+ // If the method is an aggregate function, just return
+ // the aggregate value from the query.
+ // -----------------------------------------------------
+ if (in_array($method, array('count', 'sum', 'min', 'max', 'avg')))
+ {
+ return call_user_func_array(array($model->query, $method), $parameters);
+ }
+
+ // -----------------------------------------------------
+ // Pass the method call to the query instance.
+ // -----------------------------------------------------
+ call_user_func_array(array($model->query, $method), $parameters);
+
+ return $model;
+ }
+
+}
26 system/db/eloquent/factory.php
@@ -0,0 +1,26 @@
+<?php namespace System\DB\Eloquent;
+
+class Factory {
+
+ /**
+ * Factory for creating new model instances.
+ *
+ * @param string $class
+ * @return object
+ */
+ public static function make($class)
+ {
+ // -----------------------------------------------------<