protected function resolveValue(NodeInterface $nodeValue)
 {
     if ($nodeValue instanceof MagicConst) {
         return $nodeValue->getName();
     }
     $subModules = $nodeValue->getSubNodeNames();
     if (!is_array($subModules) || empty($subModules)) {
         return;
     }
     $subModule = reset($subModules);
     $value = $nodeValue->{$subModule};
     if (is_object($value) && method_exists($value, 'toString')) {
         $value = $value->toString();
     } elseif (is_object($value) && property_exists($value, 'value')) {
         $value = $value->value;
     }
     if (is_array($value)) {
         $newValues = [];
         foreach ($value as $key => $node) {
             $newValues[$this->resolveValue($node->key)] = $this->resolveValue($node->value);
         }
         return $newValues;
     }
     if ($value === 'true') {
         return true;
     } elseif ($value === 'false') {
         return false;
     } elseif ($value === 'null') {
         return;
     }
     return $value;
 }
Exemplo n.º 2
0
 /** Test the current PhpParser_Node node to see if it is a magic constant, and return the name if it is and null if it is not
  *
  * @param   Node   $node          The sandboxed $node to test
  *
  * @return  string|null       Return string name of node, or null if it is not a magic constant
  */
 protected function isMagicConst(Node $node)
 {
     return $node instanceof Node\Scalar\MagicConst ? $node->getName() : null;
 }
Exemplo n.º 3
0
 /**
  * Returns the value from a node
  *
  * @param Node $node
  * @return mixed
  */
 private function getExpression(Node $node)
 {
     if ($node instanceof ConstFetch) {
         $const = $node->name->parts[0];
         if (isset($this->constMap[$const])) {
             return $this->constMap[$const];
         }
         return $const;
     }
     if ($node instanceof ClassConstFetch) {
         return $node->class->parts[0] . '::' . $node->name;
     }
     if ($node instanceof MagicConst) {
         return $node->getName();
     }
     if ($node instanceof Array_) {
         $prettyPrinter = new PrettyPrinter();
         return $prettyPrinter->prettyPrintExpr($node);
     }
 }