Skip to content

Instantly share code, notes, and snippets.

@dantleech
Created September 16, 2016 13:05
Show Gist options
  • Select an option

  • Save dantleech/b91546d4cbe60e1327fa914ad4923724 to your computer and use it in GitHub Desktop.

Select an option

Save dantleech/b91546d4cbe60e1327fa914ad4923724 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Psi\Component\Description;
use Psi\Component\Description\DescriptorInterface;
use Psi\Component\Description\Descriptor\ScalarDescriptor;
use Psi\Component\Description\DescriptionInterface;
/**
* Descriptive metadata for objects.
*/
class Description implements DescriptionInterface
{
/**
* @var array
*/
private $descriptors = [];
st/**
* {@inheritdoc}
*/
public function get($descriptorKey): DescriptorInterface
{
if (!isset($this->descriptors[$descriptorKey])) {
throw new \InvalidArgumentException(sprintf(
'Descriptor "%s" is not supported',
$descriptorKey,
implode('", "', array_keys($this->descriptors))
));
}
return $this->descriptors[$descriptorKey];
}
/**
* {@inheritdoc}
*/
public function has($descriptor): bool
{
return isset($this->descriptors[$descriptor]);
}
/**
* {@inheritdoc}
*/
public function all(): array
{
return $this->descriptors;
}
/**
* {@inheritdoc}
*/
public function set(DescriptorInterface $descriptor)
{
$this->descriptors[$descriptor->getKey()] = $descriptor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment