Пример #1
0
 /**
  * Test the create method
  *
  * @param string $val       The value to construct modifier with
  * @param string $expected  Expected type of created modifier
  * @dataProvider createProvider
  */
 public function testCreate($val, $expected)
 {
     // Given known options ...
     $options = new Options(['openingTag' => '{', 'closingTag' => '}']);
     // ... when we create a modifier from a given value ...
     $modifier = ModifierFactory::create($val, $options);
     // ... it should be of the expected type
     $this->assertSame($expected, get_class($modifier));
 }
Пример #2
0
 /**
  * Parse the passed transform JSON objects into transform nodes
  *
  * @param  object $t A transform object from within the spec JSON
  * @return Node[]
  */
 protected function parseTransform($t)
 {
     $nodes = [];
     // Determine if we're dealing with an array or an object
     if (is_object($t)) {
         // Iterate the object props ...
         foreach ($t as $key => $val) {
             // ... determining their selector type
             $tSelector = SelectorFactory::create($key, $this->options);
             $node = new Node($tSelector);
             // ... and values
             if (is_object($val)) {
                 // If it's an object, we need to recurse down another level
                 $node->setChildNodes($this->parseTransform($val));
             } else {
                 // If not an object, we should apply a value modifier
                 $valModifier = ModifierFactory::create($val, $this->options);
                 $node->setValueModifier($valModifier);
             }
             $nodes[] = $node;
         }
     }
     return $nodes;
 }