/** * Loads the binding descriptor. * * @param Package $containingPackage The package that contains * the descriptor. * @param BindingTypeDescriptor $typeDescriptor The type descriptor. * * @throws AlreadyLoadedException If the descriptor is already loaded. */ public function load(Package $containingPackage, BindingTypeDescriptor $typeDescriptor = null) { if (null !== $this->state) { throw new AlreadyLoadedException('The binding descriptor is already loaded.'); } if ($typeDescriptor && $this->typeName !== $typeDescriptor->getName()) { throw new InvalidArgumentException(sprintf('The passed type "%s" does not match the stored type name "%s".', $typeDescriptor->getName(), $this->typeName)); } $this->violations = array(); if ($typeDescriptor && $typeDescriptor->isLoaded() && $typeDescriptor->isEnabled()) { $validator = new SimpleParameterValidator(); $bindingType = $typeDescriptor->toBindingType(); $this->violations = $validator->validate($this->parameterValues, $bindingType); } $this->containingPackage = $containingPackage; $this->typeDescriptor = $typeDescriptor; $this->refreshState(); }
/** * @dataProvider getValidNames */ public function testToBindingType($name) { // Check that valid names are also accepted by BindingType $descriptor = new BindingTypeDescriptor($name, 'The description.', array($param = new BindingParameterDescriptor('param'))); $type = $descriptor->toBindingType(); $this->assertInstanceOf('Puli\\Discovery\\Api\\Binding\\BindingType', $type); $this->assertSame($name, $type->getName()); $this->assertCount(1, $type->getParameters()); $this->assertInstanceOf('Puli\\Discovery\\Api\\Binding\\BindingParameter', $type->getParameter('param')); }
private function syncTypeName(BindingTypeDescriptor $enabledTypeBefore = null, BindingTypeDescriptor $enabledTypeAfter = null) { if ($enabledTypeBefore && !$enabledTypeAfter) { $this->discovery->undefineType($this->typeName); } elseif (!$enabledTypeBefore && $enabledTypeAfter) { $this->discovery->defineType($enabledTypeAfter->toBindingType()); } elseif ($enabledTypeBefore !== $enabledTypeAfter) { $this->discovery->undefineType($this->typeName); $this->discovery->defineType($enabledTypeAfter->toBindingType()); } }
public function testBuildDiscoveryOnlyIncludesEnabledBindingsOfInstalledPackages() { $this->initDefaultManager(); $this->packageFile1->addBindingDescriptor($binding1 = new BindingDescriptor('/path1', 'my/type')); $this->packageFile1->addBindingDescriptor($binding2 = new BindingDescriptor('/path2', 'my/type')); $this->packageFile1->addBindingDescriptor($binding3 = new BindingDescriptor('/path3', 'my/type')); $this->installInfo1->addEnabledBindingUuid($binding2->getUuid()); $this->installInfo1->addDisabledBindingUuid($binding3->getUuid()); $this->packageFile1->addTypeDescriptor($bindingType = new BindingTypeDescriptor('my/type')); $this->discovery->expects($this->once())->method('defineType')->with($bindingType->toBindingType()); $this->discovery->expects($this->once())->method('bind')->with('/path2', 'my/type', array(), 'glob'); $this->manager->buildDiscovery(); }
/** * {@inheritdoc} */ public function execute() { $this->discovery->defineType($this->typeDescriptor->toBindingType()); }