diff --git a/spec/drupol/phptree/Node/AttributeNodeSpec.php b/spec/drupol/phptree/Node/AttributeNodeSpec.php new file mode 100644 index 0000000..68c054a --- /dev/null +++ b/spec/drupol/phptree/Node/AttributeNodeSpec.php @@ -0,0 +1,34 @@ + 'bar', + ]; + + $attributes = new \ArrayObject($attributes); + + $this + ->setAttributes($attributes) + ->getAttributes() + ->shouldReturn($attributes); + + $this + ->setAttribute('bar', 'foo') + ->getAttribute('bar') + ->shouldReturn('foo'); + } + public function it_is_initializable() + { + $this->shouldHaveType(AttributeNode::class); + } +} diff --git a/src/Node/AttributeNode.php b/src/Node/AttributeNode.php new file mode 100644 index 0000000..2f8fa4a --- /dev/null +++ b/src/Node/AttributeNode.php @@ -0,0 +1,68 @@ +storage()->set('attributes', new \ArrayObject($attributes)); + } + + /** + * {@inheritdoc} + */ + public function getAttribute($key) + { + return $this->getAttributes()[$key] ?? null; + } + + /** + * {@inheritdoc} + */ + public function getAttributes(): \Traversable + { + return $this->storage()->get('attributes'); + } + + /** + * {@inheritdoc} + */ + public function setAttribute(string $key, $value): AttributeNodeInterface + { + $this->getAttributes()[$key] = $value; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function setAttributes(\Traversable $attributes): AttributeNodeInterface + { + $this->storage()->set('attributes', $attributes); + + return $this; + } +} diff --git a/src/Node/AttributeNodeInterface.php b/src/Node/AttributeNodeInterface.php new file mode 100644 index 0000000..1f86a56 --- /dev/null +++ b/src/Node/AttributeNodeInterface.php @@ -0,0 +1,30 @@ +