Ejemplo n.º 1
0
 /**
  * Evaluate this node and return the correct object.
  *
  * Handles each part (denoted by .) in $this->objectPath in the following order:
  * - call appropriate getter
  * - call public property, if exists
  * - fail
  *
  * The first part of the object path has to be a variable in the
  * VariableProvider.
  *
  * @param RenderingContextInterface $renderingContext
  * @return mixed The evaluated object, can be any object type.
  */
 public function evaluate(RenderingContextInterface $renderingContext)
 {
     $objectPath = strtolower($this->objectPath);
     $variableProvider = $renderingContext->getVariableProvider();
     if ($objectPath === '_all') {
         return $variableProvider->getAll();
     }
     return VariableExtractor::extract($variableProvider, $this->objectPath, $this->accessors);
 }
Ejemplo n.º 2
0
 /**
  * @param mixed $variable
  * @retrurn array
  */
 protected static function getValuesOfNonScalarVariable($variable)
 {
     if ($variable instanceof \ArrayObject || is_array($variable)) {
         return (array) $variable;
     } elseif ($variable instanceof \Iterator) {
         return iterator_to_array($variable);
     } elseif (is_resource($variable)) {
         return stream_get_meta_data($variable);
     } elseif ($variable instanceof \DateTimeInterface) {
         return ['class' => get_class($variable), 'ISO8601' => $variable->format(\DateTime::ISO8601), 'UNIXTIME' => (int) $variable->format('U')];
     } else {
         $reflection = new \ReflectionObject($variable);
         $properties = $reflection->getProperties();
         $output = array();
         foreach ($properties as $property) {
             $propertyName = $property->getName();
             $output[$propertyName] = VariableExtractor::extract($variable, $propertyName);
         }
         return $output;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param mixed $subject
  * @param string $path
  * @param string $accessor
  * @param mixed $expected
  * @test
  * @dataProvider getExtractRedectAccessorTestValues
  */
 public function testExtractRedetectsAccessorIfUnusableAccessorPassed($subject, $path, $accessor, $expected)
 {
     $result = VariableExtractor::extract($subject, 'test', array($accessor));
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 4
0
 /**
  * Evaluate this node and return the correct object.
  *
  * Handles each part (denoted by .) in $this->objectPath in the following order:
  * - call appropriate getter
  * - call public property, if exists
  * - fail
  *
  * The first part of the object path has to be a variable in the
  * VariableProvider.
  *
  * @param RenderingContextInterface $renderingContext
  * @return object The evaluated object, can be any object type.
  */
 public function evaluate(RenderingContextInterface $renderingContext)
 {
     $variableProvider = $renderingContext->getVariableProvider();
     switch (strtolower($this->objectPath)) {
         case '_all':
             return $variableProvider->getAll();
         case 'true':
         case 'on':
         case 'yes':
             return TRUE;
         case 'false':
         case 'off':
         case 'no':
             return FALSE;
         default:
             return VariableExtractor::extract($variableProvider, $this->objectPath, $this->accessors);
     }
 }