From 98982a6f7a84f4e21db5e1331f695f3ee64f7ac5 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 3 Jul 2010 01:15:00 -0400 Subject: [PATCH] First attempt at lazy loading helpers done. Plugin support not complete. --- cake/libs/view/helper.php | 19 +++++++++++++++++++ cake/tests/cases/libs/view/helper.test.php | 13 ++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index a7452671ef9..d6a23cd05be 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -142,6 +142,13 @@ class Helper extends Object { */ private $__cleaned = null; +/** + * undocumented class variable + * + * @var string + */ + public $View; + /** * Default Constructor * @@ -161,6 +168,18 @@ public function __call($method, $params) { trigger_error(sprintf(__('Method %1$s::%2$s does not exist'), get_class($this), $method), E_USER_WARNING); } +/** + * Lazy loads helpers + * + * @return void + */ + public function __get($name) { + if (!empty($this->helpers) && in_array($name, $this->helpers)) { + $this->{$name} = $this->View->Helpers->load($name, array(), false); + return $this->{$name}; + } + } + /** * Parses tag templates into $this->tags. * diff --git a/cake/tests/cases/libs/view/helper.test.php b/cake/tests/cases/libs/view/helper.test.php index 8a750c9c1f1..a52a3b27027 100644 --- a/cake/tests/cases/libs/view/helper.test.php +++ b/cake/tests/cases/libs/view/helper.test.php @@ -771,7 +771,7 @@ function testWebrootPaths() { * @return void */ function testParseAttributeCompact() { - $helper =& new TestHelper($this->View); + $helper = new TestHelper($this->View); $compact = array('compact', 'checked', 'declare', 'readonly', 'disabled', 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'); @@ -783,4 +783,15 @@ function testParseAttributeCompact() { } } } + +/** + * test lazy loading helpers is seamless + * + * @return void + */ + function testLazyLoadingHelpers() { + $this->Helper->helpers = array('Test', 'Html'); + $result = $this->Helper->Test; + $this->assertType('TestHelper', $result); + } }