for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Borobudur-Config package.
*
* (c) Hexacodelabs <http://hexacodelabs.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Borobudur\Config\Definition;
use Borobudur\Config\Exception\InvalidArgumentException;
use Borobudur\Config\Exception\InvalidConfigurationException;
/**
* @author Iqbal Maulana <[email protected]>
* @created 8/10/15
class EnumNode extends ScalarNode
{
* @var array
protected $values = array();
* Constructor.
* @param string $name
* @param NodeInterface|null $parent
* @param array $values
public function __construct($name, NodeInterface $parent = null, array $values = array())
$values = array_unique($values);
if (count($values) < 2) {
throw new InvalidArgumentException('Enum values should contain at least two elements.');
}
parent::__construct($name, $parent);
$this->values = $values;
* @return array
public function getValue()
return $this->values;
* {@inheritdoc}
protected function finalizeValue($value)
if (!in_array($value, $this->values)) {
throw new InvalidConfigurationException(sprintf(
'Value "%s" is not accepted for path "%s". Acceptable values: "%s"',
$value,
$this->getPath(),
implode(', ', $this->values)
));
return $value;