PhpBench\PhpBench::normalizePath PHP 메소드

normalizePath() 공개 정적인 메소드

If the path is relative we need to use the current working path because otherwise it will be the script path, which is wrong in the context of a PHAR.
public static normalizePath ( string $path ) : string
$path string
리턴 string
    public static function normalizePath($path)
    {
        if (substr($path, 0, 1) == DIRECTORY_SEPARATOR) {
            return $path;
        }
        return getcwd() . DIRECTORY_SEPARATOR . $path;
    }

Usage Example

예제 #1
0
 /**
  * Build the BenchmarkMetadata collection.
  *
  * @param string $path
  * @param array $subjectFilter
  * @param array $groupFilter
  */
 public function findBenchmarks($path, array $subjectFilter = [], array $groupFilter = [])
 {
     $finder = new Finder();
     $path = PhpBench::normalizePath($path);
     if (!file_exists($path)) {
         throw new \InvalidArgumentException(sprintf('File or directory "%s" does not exist (cwd: %s)', $path, getcwd()));
     }
     if (is_dir($path)) {
         $finder->in($path)->name('*.php');
     } else {
         // the path is already a file, just restrict the finder to that.
         $finder->in(dirname($path))->depth(0)->name(basename($path));
     }
     $benchmarks = [];
     foreach ($finder as $file) {
         if (!is_file($file)) {
             continue;
         }
         $benchmark = $this->factory->getMetadataForFile($file->getPathname());
         if (null === $benchmark) {
             continue;
         }
         if ($groupFilter) {
             $benchmark->filterSubjectGroups($groupFilter);
         }
         if ($subjectFilter) {
             $benchmark->filterSubjectNames($subjectFilter);
         }
         if (false === $benchmark->hasSubjects()) {
             continue;
         }
         $benchmarks[] = $benchmark;
     }
     return $benchmarks;
 }
All Usage Examples Of PhpBench\PhpBench::normalizePath