1 頁 (共 1 頁)

Resource Watcher

發表於 : 2018-08-24 13:10:20
yehlu
https://github.com/jasonlewis/resource-watcher

config/app.php

代碼: 選擇全部

        JasonLewis\ResourceWatcher\Integration\LaravelServiceProvider::class,

代碼: 選擇全部

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use JasonLewis\ResourceWatcher\Watcher;

class WatchNewFile extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'WatchNewFile';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
/*
      $files = new \Illuminate\Filesystem\Filesystem;
      $tracker = new \JasonLewis\ResourceWatcher\Tracker;
      $watcher = new \JasonLewis\ResourceWatcher\Watcher($tracker, $files);
      $listener = $watcher->watch(public_path('jpg'));
*/
      $watcher = app('watcher');
      $listener = $watcher->watch(public_path('jpg'));
      $listener->create(function($resource, $path) {
          echo "{$path} has been created.".PHP_EOL;
      });
      $listener->modify(function($resource, $path) {
          echo "{$path} has been modified.".PHP_EOL;
      });
      $listener->delete(function($resource, $path) {
          echo "{$path} has been deleted.".PHP_EOL;
      });
      $watcher->start();
    }
}