Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Two small improvements

- allow define() without arguments to create an unregistered DefinitionNode
- allow run() to take a $value argument to separate definition from value processing.
  • Loading branch information...
commit 393ebca70bdd25220dbf792aa1c7c35747b43efa 1 parent 05f5f7a
@arjan arjan authored
View
6 src/Structr/Structr.php
@@ -38,9 +38,11 @@ public static function clearAll() {
self::$_definitions = array();
}
- public static function define($name) {
+ public static function define($name = null) {
$node = new DefinitionNode();
- self::$_definitions[$name] = $node;
+ if (!empty($name)) {
+ self::$_definitions[$name] = $node;
+ }
return $node;
}
View
8 src/Structr/Tree/Base/Node.php
@@ -75,12 +75,14 @@ public function end() {
return $this->parent();
}
- public function run() {
+ public function run($value = null) {
if ($this->_parent !== null) {
- return $this->root()->run();
+ return $this->root()->run($value);
}
- $value = $this->getValue();
+ if ($value === null) {
+ $value = $this->getValue();
+ }
$return = $this->_walk_value($value);
View
17 tests/Structr/Test/DefinitionTest.php
@@ -57,4 +57,21 @@ public function testDefinitionClosure() {
$this->assertSame($expected, $result);
}
+
+ public function testEmptyDefinition() {
+ Structr::clearAll();
+
+ $structr = Structr::define()->isInteger()->end();
+ $this->assertInstanceOf('Structr\Tree\DefinitionNode', $structr);
+ }
+
+
+ public function testRunWithValue() {
+ Structr::clearAll();
+ $structr = Structr::define()->isInteger()->end();
+
+ $expected = 2;
+ $this->assertSame($expected, $structr->run(2));
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.