php-vfxapply/src/Preset.php

70 lines
1.7 KiB
PHP

<?php
namespace VfxApply;
use Symfony\Component\Yaml\Yaml;
class Preset
{
/** @var string Preset name */
protected $name;
/** @var string The group this preset belong to, for organizing */
protected $group;
/** @var string The plugin this preset uses */
protected $plugin;
/** @var array The properties are used by the plugin */
protected $props = [];
/** @var array The params can be assigned from user data */
protected $params = [];
public static function createFromFile($filename)
{
$body = file_get_contents($filename);
$conf = Yaml::parse($body);
if (!array_key_exists('preset',$conf)) {
throw new \Exception("File does not appear to be a valid preset");
}
return new Preset($conf['preset']);
}
public function __construct(array $preset)
{
$this->name = $preset['name'];
$this->group = empty($preset['group'])?null:$preset['group'];
$this->plugin = $preset['plugin'];
$this->props = $preset['props'];
$this->params = empty($preset['params'])?null:$preset['params'];
}
public function getName()
{
return $this->name;
}
public function getGroup()
{
return $this->group;
}
public function getPlugin()
{
return $this->plugin;
}
public function get($prop)
{
if (!array_key_exists($prop, $this->props)) {
return null;
}
return $this->props[$prop];
}
public function getParam($param)
{
if (!array_key_exists($param, $this->params)) {
throw new \Exception("No such param defined in preset: {$param}");
}
return $this->params[$param];
}
}