2016-02-04 23:04:53 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Libraries\WatchRecord;
|
|
|
|
|
2018-08-24 17:27:19 +02:00
|
|
|
abstract class WatchRecord implements WatchRecordInterface
|
2016-02-04 23:04:53 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Array of the occurred events.
|
|
|
|
*/
|
2021-06-05 12:47:56 +02:00
|
|
|
protected array $events;
|
2016-02-04 23:04:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Full path of the file/directory on which the event occurred.
|
|
|
|
*/
|
2021-06-05 12:47:56 +02:00
|
|
|
protected string $path;
|
2016-02-04 23:04:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The input of the watch record.
|
2016-02-16 00:39:13 +08:00
|
|
|
* For example, an inotifywatch record should have an input similar to
|
2016-02-04 23:04:53 +08:00
|
|
|
* "DELETE /var/www/media/song.mp3".
|
|
|
|
*/
|
2021-06-05 12:47:56 +02:00
|
|
|
protected string $input;
|
2016-02-04 23:04:53 +08:00
|
|
|
|
|
|
|
/**
|
2018-09-03 19:41:49 +07:00
|
|
|
* @param string $input The output from a watcher command (which is an input for our script)
|
2016-02-04 23:04:53 +08:00
|
|
|
*/
|
2018-08-24 17:27:19 +02:00
|
|
|
public function __construct(string $input)
|
2016-02-04 23:04:53 +08:00
|
|
|
{
|
|
|
|
$this->input = $input;
|
|
|
|
}
|
|
|
|
|
2018-08-24 17:27:19 +02:00
|
|
|
public function isFile(): bool
|
2016-02-04 23:04:53 +08:00
|
|
|
{
|
|
|
|
return !$this->isDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given event name exists in the event array.
|
|
|
|
*/
|
2018-08-24 17:27:19 +02:00
|
|
|
protected function eventExists(string $event): bool
|
2016-02-04 23:04:53 +08:00
|
|
|
{
|
2016-08-03 18:42:11 +08:00
|
|
|
return in_array($event, $this->events, true);
|
2016-02-04 23:04:53 +08:00
|
|
|
}
|
|
|
|
|
2018-08-24 17:27:19 +02:00
|
|
|
public function getPath(): string
|
|
|
|
{
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
2020-12-22 21:11:22 +01:00
|
|
|
public function __toString(): string
|
2016-02-04 23:04:53 +08:00
|
|
|
{
|
|
|
|
return $this->input;
|
|
|
|
}
|
|
|
|
}
|