2016-02-04 15:04:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Libraries\WatchRecord;
|
|
|
|
|
|
|
|
class WatchRecord
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WatchRecord constructor.
|
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
public function __construct($input)
|
|
|
|
{
|
|
|
|
$this->input = $input;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the object is a directory.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isDirectory()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPath()
|
|
|
|
{
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if the object is a file.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isFile()
|
|
|
|
{
|
|
|
|
return !$this->isDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given event name exists in the event array.
|
|
|
|
*
|
|
|
|
* @param $event string
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function eventExists($event)
|
|
|
|
{
|
2016-08-03 10:42:11 +00:00
|
|
|
return in_array($event, $this->events, true);
|
2016-02-04 15:04:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->input;
|
|
|
|
}
|
|
|
|
}
|