removed application and resolver classes. added phpunit tests.
This commit is contained in:
parent
d35e2abd77
commit
cb8e8194ce
|
@ -39,7 +39,7 @@
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'home.index' => array('name' => 'home', function($laravel, $view)
|
'home.index' => array('name' => 'home', function($view)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
'Arr' => 'Laravel\\Arr',
|
||||||
'Asset' => 'Laravel\\Asset',
|
'Asset' => 'Laravel\\Asset',
|
||||||
'Auth' => 'Laravel\\Security\\Authenticator_Facade',
|
'Auth' => 'Laravel\\Security\\Authenticator_Facade',
|
||||||
'Benchmark' => 'Laravel\\Benchmark',
|
'Benchmark' => 'Laravel\\Benchmark',
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?php namespace Laravel;
|
|
||||||
|
|
||||||
class Application extends Resolver {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The IoC container instance for the application.
|
|
||||||
*
|
|
||||||
* @var Container
|
|
||||||
*/
|
|
||||||
public $container;
|
|
||||||
|
|
||||||
}
|
|
|
@ -32,14 +32,6 @@
|
||||||
define('SYS_LANG_PATH', SYS_PATH.'language/');
|
define('SYS_LANG_PATH', SYS_PATH.'language/');
|
||||||
define('VIEW_PATH', APP_PATH.'views/');
|
define('VIEW_PATH', APP_PATH.'views/');
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
|
||||||
// Bootstrap the application instance.
|
|
||||||
// --------------------------------------------------------------
|
|
||||||
require SYS_PATH.'resolver'.EXT;
|
|
||||||
require SYS_PATH.'application'.EXT;
|
|
||||||
|
|
||||||
$application = new Application;
|
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Load the configuration manager and its dependencies.
|
// Load the configuration manager and its dependencies.
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
@ -65,16 +57,11 @@
|
||||||
$dependencies = array_merge($dependencies, require $path);
|
$dependencies = array_merge($dependencies, require $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
$application->container = new Container($dependencies);
|
$container = new Container($dependencies);
|
||||||
|
|
||||||
IoC::$container = $application->container;
|
IoC::$container = $container;
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Load the auto-loader.
|
// Load the auto-loader.
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
spl_autoload_register(array($application->loader, 'load'));
|
spl_autoload_register(array($container->loader, 'load'));
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
|
||||||
// Register the application in the container.
|
|
||||||
// --------------------------------------------------------------
|
|
||||||
IoC::container()->instance('laravel.application', $application);
|
|
|
@ -202,7 +202,7 @@
|
||||||
|
|
||||||
'laravel.view.composer' => array('resolver' => function($container)
|
'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);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -141,4 +141,21 @@ public function resolve($name)
|
||||||
return $object;
|
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].");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,13 @@
|
||||||
<?php namespace Laravel;
|
<?php namespace Laravel;
|
||||||
|
|
||||||
abstract class Controller extends Resolver {
|
abstract class Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The IoC container instance.
|
||||||
|
*
|
||||||
|
* @var Container
|
||||||
|
*/
|
||||||
|
public $container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A stub method that will be called before every request to the controller.
|
* A stub method that will be called before every request to the controller.
|
||||||
|
@ -21,7 +28,7 @@ public function before() {}
|
||||||
*/
|
*/
|
||||||
public function __call($method, $parameters)
|
public function __call($method, $parameters)
|
||||||
{
|
{
|
||||||
return $this->response->error('404');
|
return $this->container->resolve('laravel.response')->error('404');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,51 +15,51 @@
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Register the error / exception handlers.
|
// 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);
|
$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()))
|
if ( ! is_null($error = error_get_last()))
|
||||||
{
|
{
|
||||||
$exception = new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']);
|
$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.
|
// 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.
|
// 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.
|
// 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)
|
if (count($packages) > 0)
|
||||||
{
|
{
|
||||||
$application->package->load($packages);
|
$container->package->load($packages);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($packages);
|
unset($packages);
|
||||||
|
@ -67,17 +67,17 @@
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Route the request and get the response from the route.
|
// 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))
|
if ( ! is_null($route))
|
||||||
{
|
{
|
||||||
$route->filters = require APP_PATH.'filters'.EXT;
|
$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
|
else
|
||||||
{
|
{
|
||||||
$response = $application->response->error('404');
|
$response = $container->response->error('404');
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
@ -88,9 +88,9 @@
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Close the session.
|
// 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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
|
@ -13,14 +13,14 @@ class Loader {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $paths;
|
protected $paths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All of the class aliases.
|
* All of the class aliases.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $aliases;
|
protected $aliases;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap the auto-loader.
|
* Bootstrap the auto-loader.
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
<?php namespace Laravel;
|
|
||||||
|
|
||||||
abstract class Resolver {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Magic Method for resolving classes out of the IoC container.
|
|
||||||
*
|
|
||||||
* This allows the derived class to provide access to all of the Laravel libraries
|
|
||||||
* registered in the container. Currently, this class is derived by the Application
|
|
||||||
* and Controller classes.
|
|
||||||
*/
|
|
||||||
public function __get($key)
|
|
||||||
{
|
|
||||||
if (IoC::container()->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].");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -14,13 +14,6 @@ class View_Facade extends Facade {
|
||||||
*/
|
*/
|
||||||
class View_Composer {
|
class View_Composer {
|
||||||
|
|
||||||
/**
|
|
||||||
* The application instance.
|
|
||||||
*
|
|
||||||
* @var Application
|
|
||||||
*/
|
|
||||||
protected $application;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The view composers.
|
* The view composers.
|
||||||
*
|
*
|
||||||
|
@ -34,9 +27,8 @@ class View_Composer {
|
||||||
* @param array $composers
|
* @param array $composers
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(Application $application, $composers)
|
public function __construct($composers)
|
||||||
{
|
{
|
||||||
$this->application = $application;
|
|
||||||
$this->composers = $composers;
|
$this->composers = $composers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +58,7 @@ public function compose(View $view)
|
||||||
{
|
{
|
||||||
foreach ((array) $this->composers[$view->view] as $key => $value)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<phpunit colors="true" backupGlobals="false" bootstrap="tests/bootstrap.php">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Laravel Framework Tests">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ArrTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getArray
|
||||||
|
*/
|
||||||
|
public function testGetMethodReturnsItemsFromArray($array)
|
||||||
|
{
|
||||||
|
$this->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',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Laravel - A clean and classy framework for PHP web development.
|
||||||
|
*
|
||||||
|
* @package Laravel
|
||||||
|
* @version 2.0.0
|
||||||
|
* @author Taylor Otwell <taylorotwell@gmail.com>
|
||||||
|
* @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';
|
Loading…
Reference in New Issue