/** * Add properties, constants and methods from the given * class to this. * * @param CodeBase $code_base * A reference to the code base in which the ancestor exists * * @param Clazz $class * A class to import from * * @param Option<Type>|None $type_option * A possibly defined ancestor type used to define template * parameter types when importing ancestor properties and * methods * * @return void */ public function importAncestorClass(CodeBase $code_base, Clazz $class, $type_option) { if (!$this->isFirstExecution(__METHOD__ . ':' . (string) $class->getFQSEN())) { return; } $class->addReference($this->getContext()); // Make sure that the class imports its parents first $class->hydrate($code_base); // Copy properties foreach ($class->getPropertyMap($code_base) as $property) { $this->addProperty($code_base, $property, $type_option); } // Copy constants foreach ($class->getConstantMap($code_base) as $constant) { $this->addConstant($code_base, $constant); } // Copy methods foreach ($class->getMethodMap($code_base) as $method) { $this->addMethod($code_base, $method, $type_option); } }
/** * Add properties, constants and methods from the given * class to this. * * @param Clazz $superclazz * A class to import from * * @return null */ public function importAncestorClass(CodeBase $code_base, Clazz $superclazz) { $this->memoize((string) $superclazz->getFQSEN(), function () use($code_base, $superclazz) { $superclazz->addReference($this->getContext()); // Copy properties foreach ($superclazz->getPropertyMap($code_base) as $property) { $this->addProperty($code_base, $property); } // Copy constants foreach ($superclazz->getConstantMap($code_base) as $constant) { $this->addConstant($code_base, $constant); } // Copy methods foreach ($superclazz->getMethodMap($code_base) as $method) { $this->addMethod($code_base, $method); } }); }