From 0d99d13298f123acf86b48967e6fe8af8ea4b721 Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Fri, 29 Mar 2013 11:02:26 +1100 Subject: [PATCH 1/7] Ability to flush file-based cache storage --- laravel/cache/drivers/file.php | 12 +++++++++++- laravel/cache/drivers/redis.php | 12 ++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/laravel/cache/drivers/file.php b/laravel/cache/drivers/file.php index c37520ea..31ef9a4e 100644 --- a/laravel/cache/drivers/file.php +++ b/laravel/cache/drivers/file.php @@ -97,4 +97,14 @@ public function forget($key) if (file_exists($this->path.$key)) @unlink($this->path.$key); } -} \ No newline at end of file + /** + * Flush the entire cache. + * + * @return void + */ + public function flush() + { + array_map('unlink', glob($this->path.'*')); + } + +} diff --git a/laravel/cache/drivers/redis.php b/laravel/cache/drivers/redis.php index f0a71d07..ebc1c08f 100644 --- a/laravel/cache/drivers/redis.php +++ b/laravel/cache/drivers/redis.php @@ -87,15 +87,15 @@ public function forget($key) { $this->redis->del($key); } - + /** * Flush the entire cache. - * + * * @return void */ - public function flush() - { - $this->redis->flushdb(); - } + public function flush() + { + $this->redis->flushdb(); + } } From bc6b786973326606ada43d87aaff81624ac4f80d Mon Sep 17 00:00:00 2001 From: Pavel Puchkin Date: Fri, 29 Mar 2013 12:27:09 +1100 Subject: [PATCH 2/7] Exit with non-zero if command fails, useful in scripting and CI --- laravel/cli/artisan.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/laravel/cli/artisan.php b/laravel/cli/artisan.php index e7bd130e..90f29801 100644 --- a/laravel/cli/artisan.php +++ b/laravel/cli/artisan.php @@ -43,7 +43,8 @@ } catch (\Exception $e) { - echo $e->getMessage(); + echo $e->getMessage().PHP_EOL; + exit(1); } -echo PHP_EOL; \ No newline at end of file +echo PHP_EOL; From 4086d130d1305f8ab6e9d59c9d13a5c402886506 Mon Sep 17 00:00:00 2001 From: Steven Klar Date: Tue, 2 Apr 2013 11:09:40 +0200 Subject: [PATCH 3/7] Add unregister to IoC-Contrainer Signed-off-by: Steven Klar --- laravel/documentation/ioc.md | 11 ++++++++++- laravel/ioc.php | 21 ++++++++++++++++++--- laravel/tests/cases/ioc.test.php | 14 ++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/laravel/documentation/ioc.md b/laravel/documentation/ioc.md index 7df9572b..5d44ba8b 100644 --- a/laravel/documentation/ioc.md +++ b/laravel/documentation/ioc.md @@ -46,4 +46,13 @@ ## Resolving Objects $mailer = IoC::resolve('mailer'); -> **Note:** You may also [register controllers in the container](/docs/controllers#dependency-injection). \ No newline at end of file +> **Note:** You may also [register controllers in the container](/docs/controllers#dependency-injection). + + +## Unregister an existing instance + +For test purposes sometimes you need to unregister some container. + +#### Unregister example mail class: + + IoC::unregister('mailer'); \ No newline at end of file diff --git a/laravel/ioc.php b/laravel/ioc.php index 31a1b6a5..e1075ae2 100644 --- a/laravel/ioc.php +++ b/laravel/ioc.php @@ -31,6 +31,19 @@ public static function register($name, $resolver = null, $singleton = false) 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. * @@ -141,6 +154,7 @@ public static function resolve($type, $parameters = array()) * @param string $type * @param array $parameters * @return mixed + * @throws \Exception */ protected static function build($type, $parameters = array()) { @@ -193,7 +207,7 @@ protected static function dependencies($parameters, $arguments) $dependency = $parameter->getClass(); // 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 if (count($arguments) > 0) { @@ -205,7 +219,7 @@ protected static function dependencies($parameters, $arguments) } else { - $dependencies[] = static::resolve($dependency->name); + $dependencies[] = static::resolve($dependency->name); } } @@ -218,6 +232,7 @@ protected static function dependencies($parameters, $arguments) * * @param ReflectionParameter * @return default value + * @throws \Exception */ protected static function resolveNonClass($parameter) { @@ -229,6 +244,6 @@ protected static function resolveNonClass($parameter) { throw new \Exception("Unresolvable dependency resolving [$parameter]."); } - } + } } \ No newline at end of file diff --git a/laravel/tests/cases/ioc.test.php b/laravel/tests/cases/ioc.test.php index 61190a03..805e1876 100644 --- a/laravel/tests/cases/ioc.test.php +++ b/laravel/tests/cases/ioc.test.php @@ -28,6 +28,7 @@ public function __construct(TestClassOneForIoC $class_one) } } +use \Laravel\IoC as IoC; class IoCTest extends PHPUnit_Framework_TestCase { @@ -150,4 +151,17 @@ public function testClassTwoResolvesClassOneWithArgument() $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)); + } + } From 906d0d851e182ee832100af207a555e6919acf65 Mon Sep 17 00:00:00 2001 From: Colin Viebrock Date: Wed, 3 Apr 2013 18:26:15 -0500 Subject: [PATCH 4/7] add macros to tables --- laravel/database/schema/table.php | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/laravel/database/schema/table.php b/laravel/database/schema/table.php index c728260c..84b64dcf 100644 --- a/laravel/database/schema/table.php +++ b/laravel/database/schema/table.php @@ -39,6 +39,25 @@ class Table { */ 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. * @@ -422,4 +441,22 @@ protected function column($type, $parameters = array()) return $this->columns[] = new Fluent($parameters); } -} \ No newline at end of file + /** + * 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."); + } + +} From d46e19214bd66c54b7daec62d4bc62b70c74d031 Mon Sep 17 00:00:00 2001 From: Bernardo Rittmeyer Date: Thu, 4 Apr 2013 12:50:59 +0300 Subject: [PATCH 5/7] get_dirty() comparison is not type safe get_dirty() must compare using Not Identical (!==) on place of Not Equal (!=). For example, changing null to false don't make the model dirty. --- laravel/database/eloquent/model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index cb555de4..23d25b02 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -517,7 +517,7 @@ public function get_dirty() 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; } @@ -795,4 +795,4 @@ public static function __callStatic($method, $parameters) return call_user_func_array(array(new $model, $method), $parameters); } -} \ No newline at end of file +} From 3cd624eac8bc5f50473087dabd5a917e95a15fbe Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 5 Apr 2013 09:18:51 +0200 Subject: [PATCH 6/7] Changed Laravel\ namespace prefix in some classes calls in helpers to global, to allow aliases to work, and allow class extending. --- laravel/helpers.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/laravel/helpers.php b/laravel/helpers.php index 513e3baa..22f57a7f 100644 --- a/laravel/helpers.php +++ b/laravel/helpers.php @@ -328,7 +328,7 @@ function head($array) */ 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) { - 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()) { - 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()) { - 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 ''; - 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 ''; - 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|') { - 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) { - return Laravel\Section::yield($section); + return Section::yield($section); } /** @@ -574,7 +574,7 @@ function yield($section) */ function get_cli_option($option, $default = null) { - foreach (Laravel\Request::foundation()->server->get('argv') as $argument) + foreach (Request::foundation()->server->get('argv') as $argument) { if (starts_with($argument, "--{$option}=")) { From e4080c02f56881a8682d913db4904ef486669b16 Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 5 Apr 2013 09:48:49 +0200 Subject: [PATCH 7/7] get_cli_option() is called outside Laravel app, so namespace prefix must be left there --- laravel/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laravel/helpers.php b/laravel/helpers.php index 22f57a7f..4d4f3003 100644 --- a/laravel/helpers.php +++ b/laravel/helpers.php @@ -574,7 +574,7 @@ function yield($section) */ function get_cli_option($option, $default = null) { - foreach (Request::foundation()->server->get('argv') as $argument) + foreach (Laravel\Request::foundation()->server->get('argv') as $argument) { if (starts_with($argument, "--{$option}=")) {