Puli\Repository\FilesystemRepository::add PHP Method

add() public method

public add ( $path, $resource )
    public function add($path, $resource)
    {
        $path = $this->sanitizePath($path);
        if ($resource instanceof ResourceCollection) {
            $this->ensureDirectoryExists($path);
            foreach ($resource as $child) {
                $this->addResource($path . '/' . $child->getName(), $child);
            }
            return;
        }
        if ($resource instanceof PuliResource) {
            $this->ensureDirectoryExists(Path::getDirectory($path));
            $this->addResource($path, $resource);
            return;
        }
        throw new UnsupportedResourceException(sprintf('The passed resource must be a PuliResource or ResourceCollection. Got: %s', is_object($resource) ? get_class($resource) : gettype($resource)));
    }

Usage Example

示例#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);
 }
All Usage Examples Of Puli\Repository\FilesystemRepository::add