Puli\Repository\AbstractJsonRepository::addFilesystemResource PHP Méthode

addFilesystemResource() protected méthode

Adds a filesystem resource to the JSON file.
protected addFilesystemResource ( string $path, Puli\Repository\Api\Resource\FilesystemResource $resource )
$path string The Puli path.
$resource Puli\Repository\Api\Resource\FilesystemResource The resource to add.
    protected function addFilesystemResource($path, FilesystemResource $resource)
    {
        $resource = clone $resource;
        $resource->attachTo($this, $path);
        $relativePath = Path::makeRelative($resource->getFilesystemPath(), $this->baseDirectory);
        $this->insertReference($path, $relativePath);
        $this->storeVersion($resource);
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 protected function addFilesystemResource($path, FilesystemResource $resource)
 {
     // Read children before attaching the resource to this repository
     $children = $resource->listChildren();
     parent::addFilesystemResource($path, $resource);
     // Recursively add all child resources
     $basePath = '/' === $path ? $path : $path . '/';
     foreach ($children as $name => $child) {
         $this->addFilesystemResource($basePath . $name, $child);
     }
 }