Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function installResource(Resource $resource, InstallationParams $params)
 {
     $documentRoot = Path::makeAbsolute($params->getDocumentRoot(), $params->getRootDirectory());
     if (!file_exists($documentRoot)) {
         mkdir($documentRoot, 0777, true);
     }
     $serverPath = $params->getServerPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($documentRoot, $this->symlinks, $relative);
     if ('/' === $serverPath) {
         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($serverPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($serverPath);
     }
     $filesystemRepo->add($serverPath, $resource);
 }
Exemplo n.º 2
0
 public function testGetServerPathForResourceInRoot()
 {
     $installer = new TestInstaller();
     $descriptor = new InstallerDescriptor('test', get_class($installer));
     $resources = new ArrayResourceCollection(array($resource1 = new GenericResource('/acme/blog/public')));
     $mapping = new AssetMapping('/acme/blog/public', 'localhost', '/');
     $server = new Server('localhost', 'symlink', 'public_html');
     $params = new InstallationParams($installer, $descriptor, $resources, $mapping, $server, '/root');
     $this->assertSame('/', $params->getServerPathForResource($resource1));
 }