123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- /*
- * This file is part of the Sylius package.
- *
- * (c) Paweł Jędrzejewski
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sylius\Component\Attribute\Model;
- /**
- * Attribute to subject relation.
- *
- * @author Paweł Jędrzejewski <pawel@sylius.org>
- */
- class AttributeValue implements AttributeValueInterface
- {
- /**
- * Id.
- *
- * @var integer
- */
- protected $id;
- /**
- * Subject.
- *
- * @var AttributeSubjectInterface
- */
- protected $subject;
- /**
- * Attribute.
- *
- * @var AttributeInterface
- */
- protected $attribute;
- /**
- * Attribute value.
- *
- * @var mixed
- */
- protected $value;
- /**
- * {@inheritdoc}
- */
- public function __toString()
- {
- return $this->value;
- }
- /**
- * {@inheritdoc}
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * {@inheritdoc}
- */
- public function getSubject()
- {
- return $this->subject;
- }
- /**
- * {@inheritdoc}
- */
- public function setSubject(AttributeSubjectInterface $subject = null)
- {
- $this->subject = $subject;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function getAttribute()
- {
- return $this->attribute;
- }
- /**
- * {@inheritdoc}
- */
- public function setAttribute(AttributeInterface $attribute)
- {
- $this->attribute = $attribute;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function getValue()
- {
- if ($this->attribute && AttributeTypes::CHECKBOX === $this->attribute->getType()) {
- return (Boolean) $this->value;
- }
- return $this->value;
- }
- /**
- * {@inheritdoc}
- */
- public function setValue($value)
- {
- $this->value = $value;
- return $this;
- }
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- $this->assertAttributeIsSet();
- return $this->attribute->getName();
- }
- /**
- * {@inheritdoc}
- */
- public function getPresentation()
- {
- $this->assertAttributeIsSet();
- return $this->attribute->getPresentation();
- }
- /**
- * {@inheritdoc}
- */
- public function getType()
- {
- $this->assertAttributeIsSet();
- return $this->attribute->getType();
- }
- /**
- * {@inheritdoc}
- */
- public function getConfiguration()
- {
- $this->assertAttributeIsSet();
- return $this->attribute->getConfiguration();
- }
- /**
- * @throws \BadMethodCallException When attribute is not set
- */
- protected function assertAttributeIsSet()
- {
- if (null === $this->attribute) {
- throw new \BadMethodCallException('The attribute is undefined, so you cannot access proxy methods.');
- }
- }
- }
|