Merge remote-tracking branch 'origin/master'

This commit is contained in:
Taylor Otwell 2013-04-06 20:27:07 -05:00
commit 9c9b6eed10
9 changed files with 110 additions and 24 deletions

View File

@ -97,4 +97,14 @@ public function forget($key)
if (file_exists($this->path.$key)) @unlink($this->path.$key); if (file_exists($this->path.$key)) @unlink($this->path.$key);
} }
} /**
* Flush the entire cache.
*
* @return void
*/
public function flush()
{
array_map('unlink', glob($this->path.'*'));
}
}

View File

@ -87,15 +87,15 @@ public function forget($key)
{ {
$this->redis->del($key); $this->redis->del($key);
} }
/** /**
* Flush the entire cache. * Flush the entire cache.
* *
* @return void * @return void
*/ */
public function flush() public function flush()
{ {
$this->redis->flushdb(); $this->redis->flushdb();
} }
} }

View File

@ -43,7 +43,8 @@
} }
catch (\Exception $e) catch (\Exception $e)
{ {
echo $e->getMessage(); echo $e->getMessage().PHP_EOL;
exit(1);
} }
echo PHP_EOL; echo PHP_EOL;

View File

@ -517,7 +517,7 @@ public function get_dirty()
foreach ($this->attributes as $key => $value) foreach ($this->attributes as $key => $value)
{ {
if ( ! array_key_exists($key, $this->original) or $value != $this->original[$key]) if ( ! array_key_exists($key, $this->original) or $value !== $this->original[$key])
{ {
$dirty[$key] = $value; $dirty[$key] = $value;
} }
@ -795,4 +795,4 @@ public static function __callStatic($method, $parameters)
return call_user_func_array(array(new $model, $method), $parameters); return call_user_func_array(array(new $model, $method), $parameters);
} }
} }

View File

@ -39,6 +39,25 @@ class Table {
*/ */
public $commands = array(); public $commands = array();
/**
* The registered custom macros.
*
* @var array
*/
public static $macros = array();
/**
* Registers a custom macro.
*
* @param string $name
* @param Closure $macro
* @return void
*/
public static function macro($name, $macro)
{
static::$macros[$name] = $macro;
}
/** /**
* Create a new schema table instance. * Create a new schema table instance.
* *
@ -422,4 +441,22 @@ protected function column($type, $parameters = array())
return $this->columns[] = new Fluent($parameters); return $this->columns[] = new Fluent($parameters);
} }
} /**
* Dynamically handle calls to custom macros.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
if (isset(static::$macros[$method]))
{
array_unshift($parameters, $this);
return call_user_func_array(static::$macros[$method], $parameters);
}
throw new \Exception("Method [$method] does not exist.");
}
}

View File

@ -46,4 +46,13 @@ ## Resolving Objects
$mailer = IoC::resolve('mailer'); $mailer = IoC::resolve('mailer');
> **Note:** You may also [register controllers in the container](/docs/controllers#dependency-injection). > **Note:** You may also [register controllers in the container](/docs/controllers#dependency-injection).
<a name="unregister"></a>
## Unregister an existing instance
For test purposes sometimes you need to unregister some container.
#### Unregister example mail class:
IoC::unregister('mailer');

View File

@ -328,7 +328,7 @@ function head($array)
*/ */
function url($url = '', $https = null) function url($url = '', $https = null)
{ {
return Laravel\URL::to($url, $https); return URL::to($url, $https);
} }
/** /**
@ -340,7 +340,7 @@ function url($url = '', $https = null)
*/ */
function asset($url, $https = null) function asset($url, $https = null)
{ {
return Laravel\URL::to_asset($url, $https); return URL::to_asset($url, $https);
} }
/** /**
@ -360,7 +360,7 @@ function asset($url, $https = null)
*/ */
function action($action, $parameters = array()) function action($action, $parameters = array())
{ {
return Laravel\URL::to_action($action, $parameters); return URL::to_action($action, $parameters);
} }
/** /**
@ -380,7 +380,7 @@ function action($action, $parameters = array())
*/ */
function route($name, $parameters = array()) function route($name, $parameters = array())
{ {
return Laravel\URL::to_route($name, $parameters); return URL::to_route($name, $parameters);
} }
/** /**
@ -523,7 +523,7 @@ function view($view, $data = array())
{ {
if (is_null($view)) return ''; if (is_null($view)) return '';
return Laravel\View::make($view, $data); return View::make($view, $data);
} }
/** /**
@ -537,7 +537,7 @@ function render($view, $data = array())
{ {
if (is_null($view)) return ''; if (is_null($view)) return '';
return Laravel\View::make($view, $data)->render(); return View::make($view, $data)->render();
} }
/** /**
@ -551,7 +551,7 @@ function render($view, $data = array())
*/ */
function render_each($partial, array $data, $iterator, $empty = 'raw|') function render_each($partial, array $data, $iterator, $empty = 'raw|')
{ {
return Laravel\View::render_each($partial, $data, $iterator, $empty); return View::render_each($partial, $data, $iterator, $empty);
} }
/** /**
@ -562,7 +562,7 @@ function render_each($partial, array $data, $iterator, $empty = 'raw|')
*/ */
function yield($section) function yield($section)
{ {
return Laravel\Section::yield($section); return Section::yield($section);
} }
/** /**

View File

@ -31,6 +31,19 @@ public static function register($name, $resolver = null, $singleton = false)
static::$registry[$name] = compact('resolver', 'singleton'); static::$registry[$name] = compact('resolver', 'singleton');
} }
/**
* Unregister an object
*
* @param string $name
*/
public static function unregister($name)
{
if (array_key_exists($name, static::$registry)) {
unset(static::$registry[$name]);
unset(static::$singletons[$name]);
}
}
/** /**
* Determine if an object has been registered in the container. * Determine if an object has been registered in the container.
* *
@ -141,6 +154,7 @@ public static function resolve($type, $parameters = array())
* @param string $type * @param string $type
* @param array $parameters * @param array $parameters
* @return mixed * @return mixed
* @throws \Exception
*/ */
protected static function build($type, $parameters = array()) protected static function build($type, $parameters = array())
{ {
@ -193,7 +207,7 @@ protected static function dependencies($parameters, $arguments)
$dependency = $parameter->getClass(); $dependency = $parameter->getClass();
// If the person passed in some parameters to the class // If the person passed in some parameters to the class
// then we should probably use those instead of trying // then we should probably use those instead of trying
// to resolve a new instance of the class // to resolve a new instance of the class
if (count($arguments) > 0) if (count($arguments) > 0)
{ {
@ -205,7 +219,7 @@ protected static function dependencies($parameters, $arguments)
} }
else else
{ {
$dependencies[] = static::resolve($dependency->name); $dependencies[] = static::resolve($dependency->name);
} }
} }
@ -218,6 +232,7 @@ protected static function dependencies($parameters, $arguments)
* *
* @param ReflectionParameter * @param ReflectionParameter
* @return default value * @return default value
* @throws \Exception
*/ */
protected static function resolveNonClass($parameter) protected static function resolveNonClass($parameter)
{ {
@ -229,6 +244,6 @@ protected static function resolveNonClass($parameter)
{ {
throw new \Exception("Unresolvable dependency resolving [$parameter]."); throw new \Exception("Unresolvable dependency resolving [$parameter].");
} }
} }
} }

View File

@ -28,6 +28,7 @@ public function __construct(TestClassOneForIoC $class_one)
} }
} }
use \Laravel\IoC as IoC;
class IoCTest extends PHPUnit_Framework_TestCase { class IoCTest extends PHPUnit_Framework_TestCase {
@ -150,4 +151,17 @@ public function testClassTwoResolvesClassOneWithArgument()
$this->assertEquals(42, $class_two->class_one->test_variable); $this->assertEquals(42, $class_two->class_one->test_variable);
} }
public function testCanUnregisterRegistered()
{
$testClass = 'test';
IoC::register($testClass, function() {});
$this->assertTrue(IoC::registered($testClass));
IoC::unregister($testClass);
$this->assertFalse(IoC::registered($testClass));
}
} }