Skip to content

Commit

Permalink
First attempt at lazy loading helpers done. Plugin support not complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 11, 2010
1 parent ab815a5 commit 98982a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions cake/libs/view/helper.php
Expand Up @@ -142,6 +142,13 @@ class Helper extends Object {
*/
private $__cleaned = null;

/**
* undocumented class variable
*
* @var string
*/
public $View;

/**
* Default Constructor
*
Expand All @@ -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.
*
Expand Down
13 changes: 12 additions & 1 deletion cake/tests/cases/libs/view/helper.test.php
Expand Up @@ -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');

Expand All @@ -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);
}
}

0 comments on commit 98982a6

Please sign in to comment.