示例#1
0
 /**
  * {@inheritdoc}
  */
 public function installResource(Resource $resource, InstallationParams $params)
 {
     $targetPath = Path::makeAbsolute($params->getTargetLocation(), $params->getRootDirectory());
     if (!file_exists($targetPath)) {
         mkdir($targetPath, 0777, true);
     }
     $repoPath = $params->getWebPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($targetPath, $this->symlinks, $relative);
     if ('/' === $repoPath) {
         foreach ($resource->listChildren() as $child) {
             $name = $child->getName();
             // If the resource is not attached, the name is empty
             if (!$name && $child instanceof FilesystemResource) {
                 $name = Path::getFilename($child->getFilesystemPath());
             }
             if ($name) {
                 $filesystemRepo->remove($repoPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($repoPath);
     }
     $filesystemRepo->add($repoPath, $resource);
 }
 public function testCreate()
 {
     $installer = new TestInstaller();
     $descriptor = new InstallerDescriptor('test', get_class($installer), null, array(new InstallerParameter('param1', InstallerParameter::OPTIONAL, 'default1'), new InstallerParameter('param2', InstallerParameter::OPTIONAL, 'default2')));
     $resources = new ArrayResourceCollection();
     $mapping = new AssetMapping('/path/to/{css,js}', 'target', '/demo');
     $target = new InstallTarget('target', 'symlink', 'public_html', '/%s', array('param2' => 'custom'));
     $params = new InstallationParams($installer, $descriptor, $resources, $mapping, $target, '/root');
     $this->assertSame($installer, $params->getInstaller());
     $this->assertSame($descriptor, $params->getInstallerDescriptor());
     $this->assertSame($resources, $params->getResources());
     $this->assertSame('/root', $params->getRootDirectory());
     $this->assertSame('/path/to', $params->getBasePath());
     $this->assertSame('public_html', $params->getTargetLocation());
     $this->assertSame('/demo', $params->getWebPath());
     $this->assertSame(array('param1' => 'default1', 'param2' => 'custom'), $params->getParameterValues());
 }