diff --git a/application/composers.php b/application/composers.php index 3fad0a3d..71a2428b 100644 --- a/application/composers.php +++ b/application/composers.php @@ -39,7 +39,7 @@ | */ - 'home.index' => array('name' => 'home', function($laravel, $view) + 'home.index' => array('name' => 'home', function($view) { // }), diff --git a/application/config/aliases.php b/application/config/aliases.php index 6722eb2d..55e9d324 100644 --- a/application/config/aliases.php +++ b/application/config/aliases.php @@ -18,6 +18,7 @@ | */ + 'Arr' => 'Laravel\\Arr', 'Asset' => 'Laravel\\Asset', 'Auth' => 'Laravel\\Security\\Authenticator_Facade', 'Benchmark' => 'Laravel\\Benchmark', diff --git a/laravel/application.php b/laravel/application.php deleted file mode 100644 index 9808cf0e..00000000 --- a/laravel/application.php +++ /dev/null @@ -1,12 +0,0 @@ -container = new Container($dependencies); +$container = new Container($dependencies); -IoC::$container = $application->container; +IoC::$container = $container; // -------------------------------------------------------------- // Load the auto-loader. // -------------------------------------------------------------- -spl_autoload_register(array($application->loader, 'load')); - -// -------------------------------------------------------------- -// Register the application in the container. -// -------------------------------------------------------------- -IoC::container()->instance('laravel.application', $application); \ No newline at end of file +spl_autoload_register(array($container->loader, 'load')); \ No newline at end of file diff --git a/laravel/config/container.php b/laravel/config/container.php index a1f2fc92..fd359491 100644 --- a/laravel/config/container.php +++ b/laravel/config/container.php @@ -202,7 +202,7 @@ 'laravel.view.composer' => array('resolver' => function($container) { - return new View_Composer($container->resolve('laravel.application'), require APP_PATH.'composers'.EXT); + return new View_Composer(require APP_PATH.'composers'.EXT); }), /* diff --git a/laravel/container.php b/laravel/container.php index eb8505ec..c79d0237 100644 --- a/laravel/container.php +++ b/laravel/container.php @@ -141,4 +141,21 @@ public function resolve($name) return $object; } + /** + * Magic Method for resolving classes out of the IoC container. + */ + public function __get($key) + { + if ($this->registered('laravel.'.$key)) + { + return $this->resolve('laravel.'.$key); + } + elseif ($this->registered($key)) + { + return $this->resolve($key); + } + + throw new \Exception("Attempting to resolve undefined class [$key]."); + } + } \ No newline at end of file diff --git a/laravel/controller.php b/laravel/controller.php index 35b5c779..8cc534a4 100644 --- a/laravel/controller.php +++ b/laravel/controller.php @@ -1,6 +1,13 @@ response->error('404'); + return $this->container->resolve('laravel.response')->error('404'); } } \ No newline at end of file diff --git a/laravel/laravel.php b/laravel/laravel.php index e7b2c8f2..5ac5fc78 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -15,51 +15,51 @@ // -------------------------------------------------------------- // Register the error / exception handlers. // -------------------------------------------------------------- -set_exception_handler(function($e) use ($application) +set_exception_handler(function($e) use ($container) { - call_user_func($application->config->get('error.handler'), $e); + call_user_func($container->config->get('error.handler'), $e); }); -set_error_handler(function($number, $error, $file, $line) use ($application) +set_error_handler(function($number, $error, $file, $line) use ($container) { $exception = new \ErrorException($error, $number, 0, $file, $line); - call_user_func($application->config->get('error.handler'), $exception); + call_user_func($container->config->get('error.handler'), $exception); }); -register_shutdown_function(function() use ($application) +register_shutdown_function(function() use ($container) { if ( ! is_null($error = error_get_last())) { $exception = new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']); - call_user_func($application->config->get('error.handler'), $exception); + call_user_func($container->config->get('error.handler'), $exception); } }); // -------------------------------------------------------------- // Set the default timezone. // -------------------------------------------------------------- -date_default_timezone_set($application->config->get('application.timezone')); +date_default_timezone_set($container->config->get('application.timezone')); // -------------------------------------------------------------- // Load the session and session manager. // -------------------------------------------------------------- -if ($application->config->get('session.driver') !== '') +if ($container->config->get('session.driver') !== '') { - $cookie = $application->input->cookies->get('laravel_session'); + $cookie = $container->input->cookies->get('laravel_session'); - $application->session->start($cookie, $application->config->get('session.lifetime')); + $container->session->start($cookie, $container->config->get('session.lifetime')); } // -------------------------------------------------------------- // Load the packages that are in the auto-loaded packages array. // -------------------------------------------------------------- -$packages = $application->config->get('application.packages'); +$packages = $container->config->get('application.packages'); if (count($packages) > 0) { - $application->package->load($packages); + $container->package->load($packages); } unset($packages); @@ -67,17 +67,17 @@ // -------------------------------------------------------------- // Route the request and get the response from the route. // -------------------------------------------------------------- -$route = $application->container->resolve('laravel.routing.router')->route(); +$route = $container->resolve('laravel.routing.router')->route(); if ( ! is_null($route)) { $route->filters = require APP_PATH.'filters'.EXT; - $response = $application->container->resolve('laravel.routing.caller')->call($route); + $response = $container->resolve('laravel.routing.caller')->call($route); } else { - $response = $application->response->error('404'); + $response = $container->response->error('404'); } // -------------------------------------------------------------- @@ -88,9 +88,9 @@ // -------------------------------------------------------------- // Close the session. // -------------------------------------------------------------- -if ($application->config->get('session.driver') !== '') +if ($container->config->get('session.driver') !== '') { - $application->session->close($application->input, $application->config->get('session')); + $container->session->close($container->input, $container->config->get('session')); } // -------------------------------------------------------------- diff --git a/laravel/loader.php b/laravel/loader.php index 978a0f68..24362c2e 100644 --- a/laravel/loader.php +++ b/laravel/loader.php @@ -13,14 +13,14 @@ class Loader { * * @var array */ - private $paths; + protected $paths; /** * All of the class aliases. * * @var array */ - private $aliases; + protected $aliases; /** * Bootstrap the auto-loader. diff --git a/laravel/resolver.php b/laravel/resolver.php deleted file mode 100644 index 4a1398a2..00000000 --- a/laravel/resolver.php +++ /dev/null @@ -1,26 +0,0 @@ -registered('laravel.'.$key)) - { - return IoC::container()->resolve('laravel.'.$key); - } - elseif (IoC::container()->registered($key)) - { - return IoC::container()->resolve($key); - } - - throw new \Exception("Attempting to access undefined property [$key]."); - } - -} \ No newline at end of file diff --git a/laravel/view.php b/laravel/view.php index 4447e716..59c66d72 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -14,13 +14,6 @@ class View_Facade extends Facade { */ class View_Composer { - /** - * The application instance. - * - * @var Application - */ - protected $application; - /** * The view composers. * @@ -31,12 +24,11 @@ class View_Composer { /** * Create a new view composer instance. * - * @param array $composers + * @param array $composers * @return void */ - public function __construct(Application $application, $composers) + public function __construct($composers) { - $this->application = $application; $this->composers = $composers; } @@ -66,7 +58,7 @@ public function compose(View $view) { foreach ((array) $this->composers[$view->view] as $key => $value) { - if ($value instanceof \Closure) return call_user_func($value, $this->application, $view); + if ($value instanceof \Closure) return call_user_func($value, $view); } } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..5fcbc244 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,7 @@ + + + + tests + + + \ No newline at end of file diff --git a/tests/ArrTest.php b/tests/ArrTest.php new file mode 100644 index 00000000..7db6b07f --- /dev/null +++ b/tests/ArrTest.php @@ -0,0 +1,51 @@ +assertEquals(Arr::get($array, 'email'), $array['email']); + $this->assertEquals(Arr::get($array, 'names.uncle'), $array['names']['uncle']); + } + + /** + * @dataProvider getArray + */ + public function testGetMethodReturnsDefaultWhenItemDoesntExist($array) + { + $this->assertNull(Arr::get($array, 'names.aunt')); + $this->assertEquals(Arr::get($array, 'names.aunt', 'Tammy'), 'Tammy'); + $this->assertEquals(Arr::get($array, 'names.aunt', function() {return 'Tammy';}), 'Tammy'); + } + + /** + * @dataProvider getArray + */ + public function testSetMethodSetsItemsInArray($array) + { + Arr::set($array, 'name', 'Taylor'); + Arr::set($array, 'names.aunt', 'Tammy'); + Arr::set($array, 'names.friends.best', 'Abigail'); + + $this->assertEquals($array['name'], 'Taylor'); + $this->assertEquals($array['names']['aunt'], 'Tammy'); + $this->assertEquals($array['names']['friends']['best'], 'Abigail'); + + } + + public function getArray() + { + return array(array( + array( + 'email' => 'taylorotwell@gmail.com', + 'names' => array( + 'uncle' => 'Mike', + ), + ) + )); + } + +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..76001e09 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,34 @@ + + * @link http://laravel.com + */ + +/* +|-------------------------------------------------------------------------- +| Installation Paths +|-------------------------------------------------------------------------- +| +| Here you may specify the location of the various Laravel framework +| directories for your installation. +| +| Of course, these are already set to the proper default values, so you do +| not need to change them if you have not modified the directory structure. +| +*/ + +$application = 'application'; + +$laravel = 'laravel'; + +$packages = 'packages'; + +$storage = 'storage'; + +$public = 'public'; + +require realpath($laravel).'/bootstrap.php'; \ No newline at end of file