Exemple #1
0
 /**
  * Formats the name of the resource.
  *
  * Resources with children are colored.
  *
  * @param Resource $resource The resource.
  *
  * @return string The formatted name.
  */
 private function formatName(Resource $resource)
 {
     $name = $resource->getName();
     if ($resource->hasChildren()) {
         return '<c1>' . $name . '</c1>';
     }
     return $name;
 }
 private function addResource($path, Resource $resource, $checkParentsForSymlinks = true)
 {
     $pathInBaseDir = $this->baseDir . $path;
     $hasChildren = $resource->hasChildren();
     $hasBody = $resource instanceof BodyResource;
     if ($hasChildren && $hasBody) {
         throw new UnsupportedResourceException(sprintf('Instances of BodyResource do not support child resources in ' . 'FilesystemRepository. Tried to add a BodyResource with ' . 'children at %s.', $path));
     }
     if ($this->symlink && $checkParentsForSymlinks) {
         $this->replaceParentSymlinksByCopies($path);
     }
     if ($resource instanceof FilesystemResource) {
         if ($this->symlink) {
             $this->symlinkMirror($resource->getFilesystemPath(), $pathInBaseDir);
         } elseif ($hasBody) {
             $this->filesystem->copy($resource->getFilesystemPath(), $pathInBaseDir);
         } else {
             $this->filesystem->mirror($resource->getFilesystemPath(), $pathInBaseDir);
         }
         return;
     }
     if ($hasBody) {
         file_put_contents($pathInBaseDir, $resource->getBody());
         return;
     }
     if (is_file($pathInBaseDir)) {
         $this->filesystem->remove($pathInBaseDir);
     }
     if (!file_exists($pathInBaseDir)) {
         mkdir($pathInBaseDir, 0777, true);
     }
     foreach ($resource->listChildren() as $child) {
         $this->addResource($path . '/' . $child->getName(), $child, false);
     }
 }