コード例 #1
0
ファイル: Tracker.php プロジェクト: phpguard/listen
 /**
  * Create new TrackedObject
  *
  * @param   ResourceInterface   $resource
  * @return  TrackedObject
  */
 public function createTrackedObject(ResourceInterface $resource)
 {
     $tracked = new TrackedObject();
     $tracked->setResource($resource);
     $tracked->setChecksum($resource->getChecksum());
     if (is_null($tracked->getID())) {
         $tracked->setID(PathUtil::createPathID($resource->getResource()));
     }
     return $tracked;
 }
コード例 #2
0
ファイル: Watcher.php プロジェクト: phpguard/phpguard
 public function matchFile($file)
 {
     if (!is_file($file)) {
         return false;
     }
     if ($file instanceof FileResource) {
         $file = (string) $file->getResource();
     }
     if (!$file instanceof SplFileInfo) {
         $file = PathUtil::createSplFileInfo(getcwd(), (string) $file);
     }
     $pattern = $this->options['pattern'];
     $retVal = false;
     if (preg_match($pattern, $file)) {
         $retVal = $file;
     } elseif (preg_match($pattern, $file->getRelativePathname())) {
         $retVal = $file;
     }
     if ($retVal && $this->options['transform']) {
         $transformed = preg_replace($pattern, $this->options['transform'], $file->getRelativePathname());
         $this->container->get('logger')->addDebug('Transform: ' . $file->getRelativePathname() . ' To ' . $transformed);
         if (file_exists($transformed)) {
             $retVal = PathUtil::createSplFileInfo(getcwd(), $transformed);
         } else {
             $retVal = false;
         }
     }
     return $retVal;
 }
コード例 #3
0
ファイル: Listener.php プロジェクト: phpguard/listen
 public function createResource($path)
 {
     if (!is_readable($path)) {
         throw new InvalidArgumentException(sprintf('The path "%s" is not exists or not readable.', $path));
     }
     foreach ($this->paths as $baseDir) {
         $baseDirLen = strlen($baseDir);
         if ($baseDir !== substr($path, 0, $baseDirLen)) {
             // not own this path, should continue
             continue;
         }
         $path = PathUtil::createSplFileInfo($baseDir, $path);
         return $path;
     }
     return false;
 }
コード例 #4
0
 public function run(array $paths = array())
 {
     $specFiles = array();
     foreach ($paths as $file) {
         $spl = PathUtil::createSplFileInfo(getcwd(), $file);
         $relative = $spl->getRelativePathname();
         if (!in_array($relative, $specFiles)) {
             $specFiles[] = $spl->getRelativePathname();
         }
     }
     $inspector = $this->container->get('phpspec.inspector');
     return $inspector->run($specFiles);
 }
コード例 #5
0
ファイル: TrackerSpec.php プロジェクト: phpguard/listen
 function its_checkPath_should_track_on_filesystem_modify_event(ResourceInterface $resource, TrackedObject $tracked)
 {
     $tracked->getResource()->willReturn($resource);
     $tracked->getID()->willReturn(PathUtil::createPathID($this->testFile));
     $tracked->getChecksum()->willReturn('old_checksum');
     $tracked->setChecksum('new_checksum')->shouldBeCalled();
     $resource->isExists()->shouldBeCalled()->willReturn(true);
     $resource->getChecksum()->shouldBeCalled()->willReturn('new_checksum');
     $this->checkPath($this->testFile);
     $this->getChangeSet()->shouldHaveCount(1);
 }
コード例 #6
0
ファイル: Locator.php プロジェクト: phpguard/phpguard
 /**
  * Find class file for class
  *
  * @param string $class   Class name
  * @param string $baseDir
  *
  * @return string The filename or false if file not found
  */
 public function findClassFile($class, $baseDir = null)
 {
     $baseDir = is_null($baseDir) ? getcwd() : $baseDir;
     $file = $this->mainLoader->findFile($class);
     if (is_file($file)) {
         $spl = PathUtil::createSplFileInfo($baseDir, $file);
         return $spl;
     }
     return false;
 }
コード例 #7
0
ファイル: Plugin.php プロジェクト: phpguard/phpguard
 /**
  * @param  EvaluateEvent $event
  * @return array
  */
 public function getMatchedFiles(EvaluateEvent $event)
 {
     $container = $this->container;
     $filtered = array();
     $files = $event->getFiles();
     foreach ($files as $file) {
         if ($file == $container->getParameter('config.file')) {
             continue;
         }
         if ($matched = $this->matchFile($file)) {
             if (!$matched instanceof SplFileInfo) {
                 $matched = PathUtil::createSplFileInfo(getcwd(), $matched);
             }
             $filtered[] = $matched;
         }
     }
     return $filtered;
 }