private function populateConfig(PackageFile $packageFile, \stdClass $jsonData)
 {
     if (isset($jsonData->name)) {
         $packageFile->setPackageName($jsonData->name);
     }
     if (isset($jsonData->{'path-mappings'})) {
         foreach ($jsonData->{'path-mappings'} as $path => $relativePaths) {
             $packageFile->addPathMapping(new PathMapping($path, (array) $relativePaths));
         }
     }
     if (isset($jsonData->bindings)) {
         foreach ($jsonData->bindings as $uuid => $bindingData) {
             $packageFile->addBindingDescriptor(new BindingDescriptor($bindingData->query, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), isset($bindingData->language) ? $bindingData->language : 'glob', Uuid::fromString($uuid)));
         }
     }
     if (isset($jsonData->{'binding-types'})) {
         foreach ((array) $jsonData->{'binding-types'} as $typeName => $data) {
             $parameters = array();
             if (isset($data->parameters)) {
                 foreach ((array) $data->parameters as $paramName => $paramData) {
                     $required = isset($paramData->required) ? $paramData->required : false;
                     $parameters[] = new BindingParameterDescriptor($paramName, $required ? BindingParameterDescriptor::REQUIRED : BindingParameterDescriptor::OPTIONAL, isset($paramData->default) ? $paramData->default : null, isset($paramData->description) ? $paramData->description : null);
                 }
             }
             $packageFile->addTypeDescriptor(new BindingTypeDescriptor($typeName, isset($data->description) ? $data->description : null, $parameters));
         }
     }
     if (isset($jsonData->override)) {
         $packageFile->setOverriddenPackages((array) $jsonData->override);
     }
     if (isset($jsonData->extra)) {
         $packageFile->setExtraKeys((array) $jsonData->extra);
     }
 }
 public function testBuildDiscoveryOnlyIncludesEnabledBindingsOfInstalledPackages()
 {
     $this->initDefaultManager();
     $this->packageFile1->addBindingDescriptor($binding1 = new BindingDescriptor('/path1', 'my/type'));
     $this->packageFile1->addBindingDescriptor($binding2 = new BindingDescriptor('/path2', 'my/type'));
     $this->installInfo1->addDisabledBindingUuid($binding2->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('/path1', 'my/type', array(), 'glob');
     $this->manager->buildDiscovery();
 }
 public function testWriteBindingWithCustomLanguage()
 {
     $baseConfig = new Config();
     $packageFile = new PackageFile(null, null, $baseConfig);
     $packageFile->addBindingDescriptor(new BindingDescriptor('//resource[name="config.yml"]', 'my/type', array(), 'xpath', Uuid::fromString(self::BINDING_UUID1)));
     $this->writer->writePackageFile($packageFile, $this->tempFile);
     $this->assertFileExists($this->tempFile);
     $this->assertJsonFileEquals(__DIR__ . '/Fixtures/json/binding-language.json', $this->tempFile);
 }
    public function testSerializeBindingWithCustomLanguage()
    {
        $baseConfig = new Config();
        $packageFile = new PackageFile(null, null, $baseConfig);
        $packageFile->addBindingDescriptor(new BindingDescriptor('//resource[name="config.yml"]', 'my/type', array(), 'xpath', Uuid::fromString(self::BINDING_UUID1)));
        $json = <<<JSON
{
    "version": "1.0",
    "bindings": {
        "2438256b-c2f5-4a06-a18f-f79755e027dd": {
            "query": "//resource[name=\\"config.yml\\"]",
            "language": "xpath",
            "type": "my/type"
        }
    }
}

JSON;
        $this->assertJsonEquals($json, $this->serializer->serializePackageFile($packageFile));
    }
Beispiel #5
0
 public function testHasBindingDescriptor()
 {
     $packageFile = new PackageFile();
     $binding = new BindingDescriptor('/path', 'my/type');
     $this->assertFalse($packageFile->hasBindingDescriptor($binding->getUuid()));
     $packageFile->addBindingDescriptor($binding);
     $this->assertTrue($packageFile->hasBindingDescriptor($binding->getUuid()));
 }
 private function jsonToPackageFile(stdClass $jsonData, PackageFile $packageFile)
 {
     if (isset($jsonData->name)) {
         $packageFile->setPackageName($jsonData->name);
     }
     if (isset($jsonData->{'path-mappings'})) {
         foreach ($jsonData->{'path-mappings'} as $path => $relativePaths) {
             $packageFile->addPathMapping(new PathMapping($path, (array) $relativePaths));
         }
     }
     if (isset($jsonData->bindings)) {
         foreach ($jsonData->bindings as $uuid => $bindingData) {
             $binding = null;
             $class = isset($bindingData->_class) ? $bindingData->_class : 'Puli\\Discovery\\Binding\\ResourceBinding';
             // Move this code to external classes to allow use of custom
             // bindings
             switch ($class) {
                 case 'Puli\\Discovery\\Binding\\ClassBinding':
                     $binding = new ClassBinding($bindingData->class, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), Uuid::fromString($uuid));
                     break;
                 case 'Puli\\Discovery\\Binding\\ResourceBinding':
                     $binding = new ResourceBinding($bindingData->query, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), isset($bindingData->language) ? $bindingData->language : 'glob', Uuid::fromString($uuid));
                     break;
                 default:
                     continue;
             }
             $packageFile->addBindingDescriptor(new BindingDescriptor($binding));
         }
     }
     if (isset($jsonData->{'binding-types'})) {
         foreach ((array) $jsonData->{'binding-types'} as $typeName => $data) {
             $parameters = array();
             $parameterDescriptions = array();
             if (isset($data->parameters)) {
                 foreach ((array) $data->parameters as $parameterName => $parameterData) {
                     $required = isset($parameterData->required) ? $parameterData->required : false;
                     $parameters[] = new BindingParameter($parameterName, $required ? BindingParameter::REQUIRED : BindingParameter::OPTIONAL, isset($parameterData->default) ? $parameterData->default : null);
                     if (isset($parameterData->description)) {
                         $parameterDescriptions[$parameterName] = $parameterData->description;
                     }
                 }
             }
             $packageFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType($typeName, $parameters), isset($data->description) ? $data->description : null, $parameterDescriptions));
         }
     }
     if (isset($jsonData->override)) {
         $packageFile->setOverriddenPackages((array) $jsonData->override);
     }
     if (isset($jsonData->extra)) {
         $packageFile->setExtraKeys((array) $jsonData->extra);
     }
 }