koel/app/Libraries/WatchRecord/WatchRecord.php

61 lines
1.2 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.
*
* @var array
*/
protected $events;
/**
* Full path of the file/directory on which the event occurred.
*
* @var string
*/
protected $path;
/**
* 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".
*
* @var string
*/
protected $input;
/**
2016-02-15 16:39:13 +00:00
* @param $input string 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;
}
2016-02-04 15:04:53 +00:00
public function __toString()
{
return $this->input;
}
}