Skip to content
This repository
Browse code

Making lazy loader throw an exception for missing helpers

  • Loading branch information...
commit 18b843467fbf2b24b7a842ed9a3210db0cfa88ca 1 parent 5a41024
José Lorenzo Rodríguez authored March 28, 2012
10  lib/Cake/Test/Case/View/HelperCollectionTest.php
@@ -87,6 +87,16 @@ public function testLazyLoad() {
87 87
 	}
88 88
 
89 89
 /**
  90
+ * test lazy loading of helpers
  91
+ *
  92
+ * @expectedException MissingHelperException
  93
+ * @return void
  94
+ */
  95
+	public function testLazyLoadException() {
  96
+		$result = $this->Helpers->NotAHelper;
  97
+	}
  98
+
  99
+/**
90 100
  * Tests loading as an alias
91 101
  *
92 102
  * @return void
32  lib/Cake/View/HelperCollection.php
@@ -55,9 +55,20 @@ public function __isset($helper) {
55 55
 		if (parent::__isset($helper)) {
56 56
 			return true;
57 57
 		}
58  
-		if (!$this->_loadSandbox($helper)) {
59  
-			return $this->_View->plugin && $this->_loadSandbox($this->_View->plugin . '.' . $helper);
  58
+
  59
+		try {
  60
+			$this->load($helper);
  61
+		} catch (MissingHelperException $exception) {
  62
+			if ($this->_View->plugin) {
  63
+				$this->load($this->_View->plugin . '.' . $helper);
  64
+				return true;
  65
+			}
  66
+		}
  67
+
  68
+		if (!empty($exception)) {
  69
+			throw $exception;
60 70
 		}
  71
+
61 72
 		return true;
62 73
 	}
63 74
 
@@ -78,23 +89,6 @@ public function __get($name) {
78 89
 	}
79 90
 
80 91
 /**
81  
- * Auxiliary function used for lazy loading helpers
82  
- * catches any MissingHelperException and converts it into
83  
- * a boolean return
84  
- *
85  
- * @param string $helper The helper name to be loaded
86  
- * @return boolean wheter the helper could be loaded or not
87  
- **/
88  
-	protected function _loadSandbox($helper) {
89  
-		try {
90  
-			$this->load($helper);
91  
-		} catch (MissingHelperException $e) {
92  
-			return false;
93  
-		}
94  
-		return true;
95  
-	}
96  
-
97  
-/**
98 92
  * Loads/constructs a helper.  Will return the instance in the registry if it already exists.
99 93
  * By setting `$enable` to false you can disable callbacks for a helper.  Alternatively you
100 94
  * can set `$settings['enabled'] = false` to disable callbacks.  This alias is provided so that when

0 notes on commit 18b8434

Please sign in to comment.
Something went wrong with that request. Please try again.