hasChildren() public method

Returns whether the resource has child resources.
public hasChildren ( ) : boolean
return boolean Returns `true` if the resource has child resources.
コード例 #1
0
ファイル: LsCommandHandler.php プロジェクト: webmozart/cli
 /**
  * Formats the name of the resource.
  *
  * Resources with children are colored.
  *
  * @param PuliResource $resource The resource.
  *
  * @return string|null The formatted name.
  */
 private function formatName(PuliResource $resource)
 {
     $name = $resource->getName();
     if ($resource->hasChildren()) {
         return '<c1>' . $name . '</c1>';
     }
     return $name;
 }
コード例 #2
0
 private function addResource($path, PuliResource $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));
     }
     $resource = clone $resource;
     $resource->attachTo($this, $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);
         }
         $this->storeVersion($resource);
         return;
     }
     if ($resource instanceof LinkResource) {
         if (!$this->symlink) {
             throw new UnsupportedResourceException(sprintf('LinkResource requires support of symbolic links in FilesystemRepository. ' . 'Tried to add a LinkResource at %s.', $path));
         }
         $this->filesystem->symlink($this->baseDir . $resource->getTargetPath(), $pathInBaseDir);
         $this->storeVersion($resource);
         return;
     }
     if ($hasBody) {
         file_put_contents($pathInBaseDir, $resource->getBody());
         $this->storeVersion($resource);
         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);
     }
     $this->storeVersion($resource);
 }