for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Bavix\Router;
use Bavix\Exceptions\Runtime;
trait Attachable
{
/**
* @var string
*/
protected $_name;
* Attachable constructor.
*
* @param string $key
* @param array $storage
protected function initializer(string $key, array $storage): void
$this->_name = $key;
$this->attached($storage);
}
* @return array
protected function filter(array $storage): array
return \array_filter($storage, function (string $key) {
$this->checkProperty($key);
return $key{0} !== '@'; // for xml
}, \ARRAY_FILTER_USE_KEY);
* @throws
protected function checkProperty(string $key): void
if ($key{0} === '_' || !\property_exists($this, $key)) {
throw new Runtime(\sprintf('The key `%s` is not registered', $key));
protected function attached(array $storage): void
foreach ($this->filter($storage) as $key => $value) {
$this->$key = $value;