First attempt at lazy loading helpers done. Plugin support not complete.

This commit is contained in:
mark_story 2010-07-03 01:15:00 -04:00
parent ab815a53ba
commit 98982a6f7a
2 changed files with 31 additions and 1 deletions

View file

@ -142,6 +142,13 @@ class Helper extends Object {
*/ */
private $__cleaned = null; private $__cleaned = null;
/**
* undocumented class variable
*
* @var string
*/
public $View;
/** /**
* Default Constructor * Default Constructor
* *
@ -161,6 +168,18 @@ class Helper extends Object {
trigger_error(sprintf(__('Method %1$s::%2$s does not exist'), get_class($this), $method), E_USER_WARNING); 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. * Parses tag templates into $this->tags.
* *

View file

@ -771,7 +771,7 @@ class HelperTest extends CakeTestCase {
* @return void * @return void
*/ */
function testParseAttributeCompact() { function testParseAttributeCompact() {
$helper =& new TestHelper($this->View); $helper = new TestHelper($this->View);
$compact = array('compact', 'checked', 'declare', 'readonly', 'disabled', $compact = array('compact', 'checked', 'declare', 'readonly', 'disabled',
'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize'); 'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
@ -783,4 +783,15 @@ class HelperTest extends CakeTestCase {
} }
} }
} }
/**
* test lazy loading helpers is seamless
*
* @return void
*/
function testLazyLoadingHelpers() {
$this->Helper->helpers = array('Test', 'Html');
$result = $this->Helper->Test;
$this->assertType('TestHelper', $result);
}
} }