/** {@inheritdoc} */ public function defineProperty(string $propertyName) : PropertyBuilderInterface { if (array_key_exists($propertyName, $this->propertiesCollection)) { throw new PropertyDefinitionAlreadyExistsException(); } $propertyDefinition = new PropertyDefinition($this); $propertyDefinition->setPropertyName($propertyName); $this->propertiesCollection[$propertyName] = $propertyDefinition; return $propertyDefinition; }
public function testInitDependencyReferenceIsUndefined() { $definition = new PropertyDefinition(); static::assertInstanceOf(UndefinedReference::class, $definition->getDependency()); }
public function testException() { $this->expectException(ParentDefinitionNotFoundException::class); $propertyDefinition = new PropertyDefinition(); $propertyDefinition->end(); }
/** * Generate property for class * * @param PropertyDefinition $propertyDefinition * @param ClassDefinition $classDefinition * @return string * @throws ReferenceNotImplementsException */ protected function generateProperty(ClassDefinition $classDefinition, PropertyDefinition $propertyDefinition) : string { $dependencyValue = $this->resolveDependency($propertyDefinition->getDependency()); $propertyName = $propertyDefinition->getPropertyName(); $className = $classDefinition->getClassName(); if ($propertyDefinition->isPublic()) { return "\t\$temp->{$propertyName} = {$dependencyValue};"; // Use reflection to setting the value } else { return "\t\$property = (new \\ReflectionClass('{$className}'))->getProperty('{$propertyName}');" . "\n\t\t\t\$property->setAccessible(true);" . "\n\t\t\t\$property->setValue(\$temp, {$dependencyValue});" . "\n\t\t\t\$property->setAccessible(false);"; } }