php-spark/plugins/com.noccy.watcher/Rule.php

53 lines
1.0 KiB
PHP
Raw Normal View History

<?php // "name":"Watch files and act when they are changed", "author":"Noccy"
namespace SparkPlug\Com\Noccy\Watcher;
class Rule
{
private array $filenames = [];
private array $actions = [];
private bool $initialTrigger = false;
private string $name;
public function __construct()
{
$this->name = "unnamed rule";
}
public static function createFromConfig(array $config)
{
$rule = new Rule();
$rule->filenames = (array)$config['watch'];
$rule->initialTrigger = ((bool)$config['initial-trigger'])??false;
$rule->actions = $config['actions']??[];
$rule->name = $config['name']??$rule->name;
return $rule;
}
public function getName(): string
{
return $this->name;
}
public function getInitialTrigger(): bool
{
return $this->initialTrigger;
}
public function getWatchedFiles(): array
{
return $this->filenames;
}
public function getActions(): array
{
return $this->actions;
}
}