コード例 #1
0
ファイル: BasicAdapterSpec.php プロジェクト: phpguard/listen
 function let(Listener $listener)
 {
     MFS::mkdir(MFS::$tmpDir);
     $listener->hasPath(Argument::any())->willReturn(true);
     $listener->getPatterns()->willReturn(array());
     $listener->getIgnores()->willReturn(array());
 }
コード例 #2
0
ファイル: Listen.php プロジェクト: phpguard/listen
 /**
  * Create a new listener
  *
  * @param       $paths
  * @return      Listener
  */
 public static function to($paths)
 {
     // listeners maybe not fully defined yet
     // so we should not added listener to adapter
     $listener = new Listener();
     $listener->to($paths);
     return $listener;
 }
コード例 #3
0
 function it_should_listen_to_file_system_delete_event(Listener $listener)
 {
     $newFile = MFS::$tmpDir . '/delete.txt';
     touch($newFile);
     $listener->getPaths()->shouldBeCalled()->willReturn(array(MFS::$tmpDir));
     $listener->hasPath(Argument::any())->shouldBeCalled()->willReturn(true);
     $this->beConstructedWith(null);
     $this->initialize($listener);
     unlink($newFile);
     $this->evaluate();
     $this->getChangeSet()->shouldHaveCount(1);
 }
コード例 #4
0
ファイル: ListenerTest.php プロジェクト: phpguard/listen
 public function testShouldStartProperly()
 {
     $this->isCallbackCalled = false;
     self::cleanDir($dir = self::$tmpDir);
     self::mkdir($dir);
     $listener = new Listener();
     $listener->to($dir)->latency(0.01)->callback(array($this, 'listenerCallback'));
     $listener->alwaysNotify(true);
     $listener->start();
     $this->assertTrue($this->isCallbackCalled);
     $this->assertEquals(2, $this->callbackCount);
 }
コード例 #5
0
ファイル: AdapterTest.php プロジェクト: phpguard/listen
 public function start()
 {
     $this->latency(1000);
     $this->alwaysNotify(true);
     $this->callback(function (ChangeSetEvent $event) {
         // always stop after each start
         $event->getListener()->stop();
     });
     parent::start();
 }
コード例 #6
0
ファイル: Tracker.php プロジェクト: phpguard/listen
 /**
  * @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);
     }
 }
コード例 #7
0
ファイル: BasicAdapter.php プロジェクト: phpguard/listen
 /**
  * Initialize a listener
  *
  * @param   Listener $listener
  * @return  void
  */
 public function initialize(Listener $listener)
 {
     $this->listener = $listener;
     $this->topDirs = array_merge($this->topDirs, $listener->getPaths());
     $this->tracker->initialize($listener);
 }
コード例 #8
0
ファイル: TrackerSpec.php プロジェクト: phpguard/listen
 function its_checkPath_should_track_on_filesystem_create_event(AdapterInterface $adapter, Listener $listener)
 {
     $newFile = MFS::$tmpDir . '/new.txt';
     $listener->hasPath($newFile)->shouldBeCalled()->willReturn(true);
     $adapter->watch(Argument::any())->shouldBeCalled();
     $this->beConstructedWith($adapter);
     $this->initialize($listener);
     touch($newFile);
     $this->checkPath($newFile);
     $this->getChangeSet()->shouldHaveCount(1);
 }