koel/app/Libraries/WatchRecord/WatchRecord.php

55 lines
1.1 KiB
PHP
Raw Normal View History

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