Created
September 16, 2016 13:05
-
-
Save dantleech/b91546d4cbe60e1327fa914ad4923724 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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