コード例 #1
0
 /**
  * @param string $message
  *
  * @return string
  */
 public function ask($message)
 {
     $runAgainText = "Press <Enter> to reexecute, press any other key and <Enter> to stop...";
     if ($message != $runAgainText) {
         return parent::ask($message);
     }
     /** @var \mageekguy\atoum\writers\std\out $outputWriter */
     $outputWriter = $this->getOutputWriter();
     $watcher = new ResourceWatcher();
     $onEvent = function (FilesystemEvent $event) use($watcher, $outputWriter) {
         $outputWriter->write($event->getResource()->getId() . " has been modified." . PHP_EOL);
         $watcher->stop();
     };
     foreach ($this->configuration->getWatchedFiles() as $watchedFile) {
         $watcher->track($watchedFile, $watchedFile);
         $watcher->addListener($watchedFile, $onEvent);
     }
     foreach ($this->getRunner()->getTestPaths() as $path) {
         $watcher->track($path, $path);
         $watcher->addListener($path, $onEvent);
     }
     $outputWriter->write('Waiting for a file to change to run the test(s)... (Use CTRL+C to stop)' . PHP_EOL);
     $watcher->start();
     return '';
 }
コード例 #2
0
ファイル: watcher.php プロジェクト: atoum/autoloop-extension
 /**
  * @return string
  */
 public function runAgain()
 {
     /** @var \mageekguy\atoum\writers\std\out $outputWriter */
     $outputWriter = $this->runner->getOutputWriter();
     $watcher = new ResourceWatcher();
     $onEvent = function (FilesystemEvent $event) use($watcher, $outputWriter) {
         $outputWriter->write((string) $event->getResource() . " has been modified." . PHP_EOL);
         $watcher->stop();
     };
     foreach ($this->configuration->getWatchedFiles() as $watchedFile) {
         $watcher->track($watchedFile, $watchedFile);
         $watcher->addListener($watchedFile, $onEvent);
     }
     foreach ($this->runner->getRunner()->getTestPaths() as $path) {
         $watcher->track($path, $path);
         $watcher->addListener($path, $onEvent);
     }
     $outputWriter->write('Waiting for a file to change to run the test(s)... (Use CTRL+C to stop)' . PHP_EOL);
     $watcher->start();
     return '';
 }
コード例 #3
0
ファイル: Watch.php プロジェクト: lamenath/fbp
 public function run()
 {
     $watcher = new ResourceWatcher();
     foreach ($this->monitor as $k => $monitor) {
         $closure = $monitor[1];
         $closure->bindTo($this->bindTo);
         foreach ($monitor[0] as $i => $dir) {
             $watcher->track("fs.{$k}.{$i}", $dir, FilesystemEvent::MODIFY);
             $this->printTaskInfo("watching <info>{$dir}</info> for changes...");
             $watcher->addListener("fs.{$k}.{$i}", $closure);
         }
     }
     $watcher->start();
     return Result::success($this);
 }
コード例 #4
0
ファイル: Watch.php プロジェクト: greg-1-anderson/Robo
 public function run()
 {
     if (!class_exists('Lurker\\ResourceWatcher')) {
         return Result::errorMissingPackage($this, 'ResourceWatcher', 'henrikbjorn/lurker');
     }
     $watcher = new ResourceWatcher();
     foreach ($this->monitor as $k => $monitor) {
         $closure = $monitor[1];
         $closure->bindTo($this->bindTo);
         foreach ($monitor[0] as $i => $dir) {
             $watcher->track("fs.{$k}.{$i}", $dir, FilesystemEvent::MODIFY);
             $this->printTaskInfo('Watching {dir} for changes...', ['dir' => $dir]);
             $watcher->addListener("fs.{$k}.{$i}", $closure);
         }
     }
     $watcher->start();
     return Result::success($this);
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->app = $this->getApplication()->getApplication();
     $this->input = $input;
     $this->output = $output;
     if (false == ($themes = $this->getThemes())) {
         $output->writeln("<error>No valid theme to install.</error>");
         exit(1);
     }
     $staticDir = $this->getStaticDir();
     $output->writeln("<comment>The static folder will be '{$staticDir}'</comment>");
     $output->writeln('');
     $themeData = [];
     $filesystem = new Filesystem();
     $doMirror = function ($sourceDir, $destDir) use($filesystem, $themeData) {
         $filesystem->mirror($sourceDir, $destDir, null, ['override' => true, 'delete' => true]);
     };
     foreach ($themes as $theme) {
         $destDir = $staticDir . DIRECTORY_SEPARATOR . $theme->getName();
         if (!is_dir($destDir) && !mkdir($destDir, 0777, true)) {
             $output->writeln("<error>Unable to read or create the folder '{$destDir}'</error>");
         }
         $sourceDir = $theme->getStaticDir();
         if (!is_dir($sourceDir)) {
             continue;
         }
         $doMirror($sourceDir, $destDir);
         $output->writeln("  <info>Theme '{$theme->getName()}' is successfully installed.</info>");
         $themeData[$theme->getName()] = ['source_dir' => $sourceDir, 'dest_dir' => $destDir];
     }
     if ($input->getOption('watch')) {
         $watcher = new ResourceWatcher();
         $output->writeln('');
         $output->writeln('<comment>Started watching static resources...</comment>');
         $callback = function (FilesystemEvent $event) use($themeData, $doMirror, $output) {
             $themeName = $event->getTrackedResource()->getTrackingId();
             $typeLabel = self::$watcherTypes[$event->getType()];
             $data = $themeData[$themeName];
             $doMirror($data['source_dir'], $data['dest_dir']);
             $output->writeln("  - {$event->getResource()} {$typeLabel}: <info>updated {$themeName} static resources.<info>");
         };
         foreach ($themeData as $name => $data) {
             $watcher->track($name, $data['source_dir'], FilesystemEvent::ALL);
             $watcher->addListener($name, $callback);
         }
         $watcher->start();
     }
     return 0;
 }
コード例 #6
0
ファイル: ResourceWatcherTest.php プロジェクト: lamenath/fbp
 /**
  * @expectedException Lurker\Exception\InvalidArgumentException
  * @expectedExceptionMessage "all" is a reserved keyword and can not be used as tracking id
  */
 public function testTrackReservedKeyword()
 {
     $watcher = new ResourceWatcher($this->tracker, $this->dispatcher);
     $watcher->track('all', __FILE__);
 }
コード例 #7
0
ファイル: watcher.php プロジェクト: dev-lucid/lucid
use Lurker\Event\FilesystemEvent;
use Lurker\ResourceWatcher;
define('BIN_PATH', dirname($_SERVER['PWD'] . '/' . $_SERVER['SCRIPT_FILENAME']));
define('ROOT_PATH', realpath(BIN_PATH . '/../'));
include ROOT_PATH . '/bootstrap.php';
ob_end_clean();
$scssConfig = (include ROOT_PATH . '/config/scss.php');
$jsConfig = (include ROOT_PATH . '/config/javascript.php');
$watcher = new ResourceWatcher();
$scssEvent = function (FilesystemEvent $event) {
    $cmd = ' php bin/lucid.php compile-sass';
    app('logger')->info('Recompiling scss: ' . $cmd);
    shell_exec($cmd);
};
for ($i = 0; $i < count($scssConfig['importPaths']); $i++) {
    $watcher->track('scss' . strval($i), $scssConfig['importPaths'][$i]);
    $watcher->addListener('scss' . strval($i), $scssEvent);
}
$jsEvent = function (FilesystemEvent $event) {
    $cmd = 'php bin/lucid.php compile-javascript';
    app('logger')->info('Recompiling javascript: ' . $cmd);
    shell_exec($cmd);
};
$jsPaths = array_keys($jsConfig['include']);
for ($i = 0; $i < count($jsPaths); $i++) {
    $watcher->track('js' . strval($i), $jsPaths[$i]);
    $watcher->addListener('js' . strval($i), $jsEvent);
}
$docsEvent = function (FilesystemEvent $event) {
    $fileInfo = pathinfo($event->getResource());
    if ($fileInfo['extension'] != 'pdf') {