Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / consolidation / robo / src / Task / Base / Watch.php
index d7940ac94b3283073389ae73fb76d9b14376036c..3b2152d96fe48a94ebe7f19c3ec4b87e7c24ba34 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace Robo\Task\Base;
 
-use Lurker\Event\FilesystemEvent;
 use Lurker\ResourceWatcher;
 use Robo\Result;
 use Robo\Task\BaseTask;
@@ -9,15 +8,33 @@ use Robo\Task\BaseTask;
 /**
  * Runs task when specified file or dir was changed.
  * Uses Lurker library.
+ * Monitor third parameter takes Lurker filesystem events types to watch.
+ * By default its set to MODIFY event.
  *
  * ``` php
  * <?php
  * $this->taskWatch()
- *  ->monitor('composer.json', function() {
- *      $this->taskComposerUpdate()->run();
- * })->monitor('src', function() {
- *      $this->taskExec('phpunit')->run();
- * })->run();
+ *      ->monitor(
+ *          'composer.json',
+ *          function() {
+ *              $this->taskComposerUpdate()->run();
+ *          }
+ *      )->monitor(
+ *          'src',
+ *          function() {
+ *              $this->taskExec('phpunit')->run();
+ *          },
+ *          \Lurker\Event\FilesystemEvent::ALL
+ *      )->monitor(
+ *          'migrations',
+ *          function() {
+ *              //do something
+ *          },
+ *          [
+ *              \Lurker\Event\FilesystemEvent::CREATE,
+ *              \Lurker\Event\FilesystemEvent::DELETE
+ *          ]
+ *      )->run();
  * ?>
  * ```
  */
@@ -49,15 +66,13 @@ class Watch extends BaseTask
     /**
      * @param string|string[] $paths
      * @param \Closure $callable
+     * @param int|int[] $events
      *
      * @return $this
      */
-    public function monitor($paths, \Closure $callable)
+    public function monitor($paths, \Closure $callable, $events = 2)
     {
-        if (!is_array($paths)) {
-            $paths = [$paths];
-        }
-        $this->monitor[] = [$paths, $callable];
+        $this->monitor[] = [(array)$paths, $callable, (array)$events];
         return $this;
     }
 
@@ -77,9 +92,11 @@ class Watch extends BaseTask
             $closure = $monitor[1];
             $closure->bindTo($this->bindTo);
             foreach ($monitor[0] as $i => $dir) {
-                $watcher->track("fs.$k.$i", $dir, FilesystemEvent::MODIFY);
+                foreach ($monitor[2] as $j => $event) {
+                    $watcher->track("fs.$k.$i.$j", $dir, $event);
+                    $watcher->addListener("fs.$k.$i.$j", $closure);
+                }
                 $this->printTaskInfo('Watching {dir} for changes...', ['dir' => $dir]);
-                $watcher->addListener("fs.$k.$i", $closure);
             }
         }