/** * Parse a class to located and modify one of its properties. * * @param Stmt_Namespace $node contains a php namespace container * @param string $name, name of the attribute * @param Expr_Array $templateNode, key, value pairs from Template file * @param bool $front, set location to the front of the array * * @return Stmt_Namespace */ public function parseClassProperty(&$node, $name, $templateNode, $front = fales) { $array = $this->node2Array($templateNode); foreach ($node->stmts as $block) { if ($block->getType() === 'Stmt_Class') { $matchKey = null; foreach ($block->stmts as $key => $property) { if ($property->getType() === 'Stmt_Property' && $name === $property->props[0]->name) { $matchKey = $key; $array = $front ? array_merge($array, $this->node2Array($property->props[0]->default)) : array_merge($this->node2Array($property->props[0]->default), $array); break; } } // Append merged array, $prop = new Property($name); $prop->setDefault($array); $prop->makeProtected(); if (!is_null($matchKey)) { $block->stmts[$matchKey] = $prop->getNode(); } else { $block->stmts[] = $prop->getNode(); } } } return $node; }
/** * Create an AST PropertyNode given a reflection * * Note that we don't copy across DocBlock, protected, private or static * because runtime properties can't have these attributes. * * @param \ReflectionProperty $property * @param object $instance * @return PropertyNode */ private function createPropertyNodeFromReflection(\ReflectionProperty $property, $instance) { $builder = new PropertyNodeBuilder($property->getName()); $builder->setDefault($property->getValue($instance)); if ($property->isPublic()) { $builder->makePublic(); } return $builder->getNode(); }