Exemple #1
0
 /**
  * @param DirectoryPath $relativeDirectoryPath
  *
  * @return DirectoryListing
  */
 public function listDirectory(DirectoryPath $relativeDirectoryPath)
 {
     $repositoryPath = $this->gitRepository->getRepositoryPath();
     /* @var PageFile[] $pages */
     $pages = array();
     /* @var Directory[] $subDirectories */
     $subDirectories = array();
     /* @var \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File[] $otherFiles */
     $otherFiles = array();
     $finder = new Finder();
     $finder->in($this->gitRepository->getAbsolutePathString($relativeDirectoryPath));
     $finder->depth(0);
     foreach ($finder->files() as $file) {
         /* @var \Symfony\Component\Finder\SplFileInfo $file */
         if ($file->getExtension() == "md") {
             $pages[] = $this->createPageFile($repositoryPath, $relativeDirectoryPath, $file);
         } else {
             if ($file->getExtension() != 'lock') {
                 $otherFile = new \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File($repositoryPath->toAbsoluteFileString(), $relativeDirectoryPath->toRelativeFileString(), $file->getRelativePathName());
                 $otherFiles[] = $otherFile;
             }
         }
     }
     $finder = new Finder();
     $finder->in($this->gitRepository->getAbsolutePathString($relativeDirectoryPath));
     $finder->depth(0);
     $finder->ignoreDotFiles(true);
     foreach ($finder->directories() as $directory) {
         /* @var \Symfony\Component\Finder\SplFileInfo $directory */
         $subDirectory = new Directory($repositoryPath->toAbsoluteFileString(), $relativeDirectoryPath->toRelativeFileString(), $directory->getRelativePathName() . DIRECTORY_SEPARATOR);
         $subDirectories[] = $subDirectory;
     }
     usort($pages, function (PageFile $a, PageFile $b) {
         return strcmp($a->getTitle(), $b->getTitle());
     });
     usort($subDirectories, function (Directory $a, Directory $b) {
         return strcmp($a->getFilename(), $b->getFilename());
     });
     usort($otherFiles, function (\Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File $a, \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File $b) {
         return strcmp($a->getFilename(), $b->getFilename());
     });
     return new DirectoryListing($relativeDirectoryPath, $pages, $subDirectories, $otherFiles);
 }