/**
  * find the folders in the result set from a RegexIterator
  *
  * @param  RegexIterator $iter
  *         the iterator to filter on
  * @return \Iterator
  */
 public static function fromRegexIterator(RegexIterator $iter)
 {
     foreach ($iter as $match) {
         if (IsFolder::checkString($match[0])) {
             (yield $match[0]);
         }
     }
 }
Example #2
0
 /**
  * are we looking at a valid Git repo?
  *
  * @param  string $repoDir
  *         path to the git repo to examine
  * @return boolean
  *         TRUE if we are
  *         FALSE otherwise
  */
 public static function check($repoDir)
 {
     // we're going to check for the existence of all of these folders
     $foldersToCheck = [$repoDir, $repoDir . '/.git/refs/heads'];
     foreach ($foldersToCheck as $folderToCheck) {
         if (!IsFolder::checkString($folderToCheck)) {
             return false;
         }
     }
     // if we get here, we've run out of ideas
     return true;
 }
 /**
  * throws an exception if $item isn't an absolute path to a folder,
  * and it isn't NULL
  *
  * @param  string|null $item
  *         the folder path to examine
  * @return void
  *
  * @throws E4xx_UnsupportedType
  */
 public static function check($item)
 {
     // defensive programming!!
     static $requirements = [[IsNull::class, 'check'], [IsStringy::class, 'check']];
     RequireAnyOneOf::check($requirements, [$item], E4xx_UnsupportedType::class);
     if ($item === null) {
         return;
     }
     // make sure we have what we need
     if (!IsFolder::check($item)) {
         throw new E4xx_InvalidPath($item);
     }
     if (!IsAbsoluteFolder::check($item)) {
         throw new E4xx_NotAbsoluteFolder($item);
     }
 }
 /**
  * return a list of matching files and / or folders inside a given folder
  *
  * @param  FilesystemPathData $fsData
  *         the folder to look inside
  * @param  string $pattern
  *         the regex to match
  * @param  string $matcher
  *         class name of the matcher to apply to the RegexIterator results
  * @return array<string>
  *         a list of the matching files / folders found
  *         will be empty if no matches found
  */
 public static function fromFilesystemPathData(FilesystemPathData $fsData, $pattern, $matcher)
 {
     // make sure we have a folder
     if (!IsFolder::checkFilesystemPathData($fsData)) {
         return [];
     }
     // at this point, we are happy that we have a folder
     //
     // let's find out what's in it
     $regIter = SplFolderIterator::fromFilesystemPathData($fsData, $pattern);
     // what happened?
     $filenames = iterator_to_array(call_user_func_array([$matcher, 'fromRegexIterator'], [$regIter]));
     // let's get the list into some semblance of order
     sort($filenames);
     // all done
     return $filenames;
 }