@@ -21,12 +21,14 @@ discard block |
||
21 | 21 | static $scopeHook; |
22 | 22 | |
23 | 23 | static function add($model, $name = null) { |
24 | - if (!$model instanceOf Model) |
|
25 | - throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
26 | - if ($name) |
|
27 | - self::$namedScopes[$name] = $model; |
|
28 | - else |
|
29 | - self::$scopes[] = $model; |
|
24 | + if (!$model instanceOf Model) { |
|
25 | + throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
26 | + } |
|
27 | + if ($name) { |
|
28 | + self::$namedScopes[$name] = $model; |
|
29 | + } else { |
|
30 | + self::$scopes[] = $model; |
|
31 | + } |
|
30 | 32 | if(self::$scopeHook) { |
31 | 33 | (self::$scopeHook)($model); |
32 | 34 | } |
@@ -47,15 +49,21 @@ discard block |
||
47 | 49 | */ |
48 | 50 | static function get($id = 0) { |
49 | 51 | if (0 == $id) { |
50 | - if ($scope = end(self::$scopes)) |
|
51 | - return $scope; |
|
52 | + if ($scope = end(self::$scopes)) { |
|
53 | + return $scope; |
|
54 | + } |
|
52 | 55 | throw new OutOfScope("Unable to find Scope ($id)"); |
53 | 56 | } |
54 | 57 | $key = $id - 1; |
55 | - if ($id < 0) $key = count(self::$scopes) + $id - 1; |
|
56 | - if ($id == 0) $key = count(self::$scopes) - 1; |
|
57 | - if (!isset(self::$scopes[$key])) |
|
58 | - throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
58 | + if ($id < 0) { |
|
59 | + $key = count(self::$scopes) + $id - 1; |
|
60 | + } |
|
61 | + if ($id == 0) { |
|
62 | + $key = count(self::$scopes) - 1; |
|
63 | + } |
|
64 | + if (!isset(self::$scopes[$key])) { |
|
65 | + throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
66 | + } |
|
59 | 67 | return self::$scopes[$key]; |
60 | 68 | } |
61 | 69 | |
@@ -73,8 +81,9 @@ discard block |
||
73 | 81 | self::$namedScopes[$name]->rewind(); |
74 | 82 | return self::$namedScopes[$name]; |
75 | 83 | } else |
76 | - if(self::$returnZeroOnNoScope) |
|
77 | - return new Model\Zero(); |
|
84 | + if(self::$returnZeroOnNoScope) { |
|
85 | + return new Model\Zero(); |
|
86 | + } |
|
78 | 87 | throw new RunTime("Unable to find scope ($name)"); |
79 | 88 | } |
80 | 89 |