function let(AdapterInterface $adapter, Listener $listener, TrackedObject $tracked, ResourceInterface $resource) { MFS::mkdir(MFS::$tmpDir); touch($this->testFile = MFS::$tmpDir . '/test.txt'); $listener->getPaths()->willReturn(array(MFS::$tmpDir)); $listener->getIgnores()->willReturn(array()); $listener->getPatterns()->willReturn(array()); $listener->hasPath(Argument::any())->willReturn(true); $tracked->getID()->willReturn(PathUtil::createPathID($this->testFile)); $tracked->getResource()->willReturn($resource); $tracked->getResource()->willReturn($resource); $resource->getResource()->willReturn(PathUtil::createSplFileInfo(MFS::$tmpDir, $this->testFile)); $resource->__toString()->willReturn($this->testFile); $this->beConstructedWith($adapter); $this->fileOnly(false); $this->add($tracked); $this->initialize($listener); }
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; }
/** * @param $path * @throws \PhpGuard\Listen\Exception\InvalidArgumentException * @internal param \Symfony\Component\Finder\SplFileInfo $spl */ public function checkPath($path) { $id = PathUtil::createPathID($path); if (!$this->has($id)) { if (!is_readable($path)) { return; } if (!$path instanceof SplFileInfo) { $absPath = realpath($path); foreach ($this->listener->getPaths() as $baseDir) { $baseDir = realpath($baseDir); $baseDirLen = strlen($baseDir); if ($baseDir === substr($absPath, 0, $baseDirLen)) { $path = PathUtil::createSplFileInfo($baseDir, $absPath); break; } } } if (!$path instanceof SplFileInfo) { throw new InvalidArgumentException(sprintf('Path "%s" can not registered', $path)); } if (!$this->listener->hasPath($path)) { return; } // path is new if ($path->isFile()) { $resource = new FileResource($path); } else { $resource = new DirectoryResource($path); } $tracked = $this->createTrackedObject($resource); $this->add($tracked); $this->addChangeSet($tracked, FilesystemEvent::CREATE); return; } $tracked = $this->get($id); $origin = $tracked->getResource(); if ($tracked->getChecksum() !== $origin->getChecksum() && $origin->isExists()) { // path is modified $this->addChangeSet($tracked, FilesystemEvent::MODIFY); $tracked->setChecksum($origin->getChecksum()); unset($this->unchecked[$id]); return; } if (!$origin->isExists()) { // path is deleted $this->addChangeSet($tracked, FilesystemEvent::DELETE); $this->remove($tracked); } }
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; }
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); }
/** * 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; }
/** * @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; }