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 testPreBuildRepositoryEventSupportsSkipping()
 {
     $testResource = new FileResource(__FILE__);
     $this->initEnvironment($this->homeDir, $this->rootDir, false);
     $this->initDefaultManager();
     $this->packageFile1->addPathMapping(new PathMapping('/path', 'resources'));
     $this->repo->expects($this->never())->method('add');
     $this->dispatcher->addListener(PuliEvents::PRE_BUILD_REPOSITORY, function (BuildRepositoryEvent $event) {
         $event->skipBuild();
     });
     $this->dispatcher->addListener(PuliEvents::POST_BUILD_REPOSITORY, function (BuildRepositoryEvent $event) use($testResource) {
         // The post event is not executed if the build is skipped
         $event->getRepositoryManager()->getRepository()->add('/post', $testResource);
     });
     $this->manager->buildRepository();
 }
 public function testWriteResourcesWithMultipleLocalPaths()
 {
     $packageFile = new PackageFile();
     $packageFile->setPackageName('my/application');
     $packageFile->addPathMapping(new PathMapping('/app', array('res', 'assets')));
     $this->writer->writePackageFile($packageFile, $this->tempFile);
     $this->assertFileExists($this->tempFile);
     $this->assertJsonFileEquals(__DIR__ . '/Fixtures/json/multi-resources.json', $this->tempFile);
 }
    public function testSerializePathMappingsWithMultipleLocalPaths()
    {
        $packageFile = new PackageFile();
        $packageFile->setPackageName('my/application');
        $packageFile->addPathMapping(new PathMapping('/app', array('res', 'assets')));
        $json = <<<JSON
{
    "version": "1.0",
    "name": "my/application",
    "path-mappings": {
        "/app": [
            "res",
            "assets"
        ]
    }
}

JSON;
        $this->assertJsonEquals($json, $this->serializer->serializePackageFile($packageFile));
    }
示例#5
0
 public function testRemovePathMapping()
 {
     $packageFile = new PackageFile();
     $packageFile->addPathMapping(new PathMapping('/path', 'res'));
     $packageFile->removePathMapping('/path');
     $this->assertFalse($packageFile->hasPathMapping('/path'));
 }
示例#6
0
 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);
     }
 }