Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,203 @@
<?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;
use Sylius\Component\Translation\Model\AbstractTranslatable;
/**
* Model for object attributes.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
class Attribute extends AbstractTranslatable implements AttributeInterface
{
/**
* Attribute id.
*
* @var mixed
*/
protected $id;
/**
* Type.
*
* @var string
*/
protected $type = AttributeTypes::TEXT;
/**
* Internal name.
*
* @var string
*/
protected $name;
/**
* Attribute configuration.
*
* @var array
*/
protected $configuration = array();
/**
* Creation time.
*
* @var \DateTime
*/
protected $createdAt;
/**
* Last update time.
*
* @var \DateTime
*/
protected $updatedAt;
public function __construct()
{
parent::__construct();
$this->createdAt = new \DateTime();
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* {@inheritdoc}
*/
public function getPresentation()
{
return $this->translate()->getPresentation();
}
/**
* {@inheritdoc}
*/
public function setPresentation($presentation)
{
$this->translate()->setPresentation($presentation);
return $this;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return $this->type;
}
/**
* {@inheritdoc}
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* {@inheritdoc}
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration)
{
$this->configuration = $configuration;
return $this;
}
/**
* {@inheritdoc}
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* {@inheritdoc}
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* {@inheritdoc}
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* {@inheritdoc}
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* {@inheritdoc}
*/
protected function getTranslationEntityClass()
{
return get_class().'Translation';
}
}

View File

@@ -0,0 +1,65 @@
<?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;
use Sylius\Component\Resource\Model\TimestampableInterface;
/**
* Attribute interface.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
interface AttributeInterface extends TimestampableInterface, AttributeTranslationInterface
{
/**
* Get internal name.
*
* @return string
*/
public function getName();
/**
* Set internal name.
*
* @param string $name
*/
public function setName($name);
/**
* The type of the attribute.
*
* @return string
*/
public function getType();
/**
* Set type of the attribute.
*
* @param string $type
*/
public function setType($type);
/**
* Get attribute configuration.
*
* @return array
*/
public function getConfiguration();
/**
* Set attribute configuration.
*
* @param array $configuration
*/
public function setConfiguration(array $configuration);
}

View File

@@ -0,0 +1,78 @@
<?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;
use Doctrine\Common\Collections\Collection;
/**
* Interface implemented by object which can be characterized
* using the attributes.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface AttributeSubjectInterface
{
/**
* Returns all attributes of the subject.
*
* @return Collection|AttributeValueInterface[]
*/
public function getAttributes();
/**
* Sets all attributes of the subject.
*
* @param Collection $attributes Array of AttributeValueInterface
*/
public function setAttributes(Collection $attributes);
/**
* Adds an attribute to the subject.
*
* @param AttributeValueInterface $attribute
*/
public function addAttribute(AttributeValueInterface $attribute);
/**
* Removes an attribute from the subject.
*
* @param AttributeValueInterface $attribute
*/
public function removeAttribute(AttributeValueInterface $attribute);
/**
* Checks whether the subject has a given attribute.
*
* @param AttributeValueInterface $attribute
*
* @return Boolean
*/
public function hasAttribute(AttributeValueInterface $attribute);
/**
* Checks whether the subject has a given attribute, access by name.
*
* @param string $attributeName
*
* @return Boolean
*/
public function hasAttributeByName($attributeName);
/**
* Returns an attribute of the subject by its name.
*
* @param string $attributeName
*
* @return AttributeValueInterface
*/
public function getAttributeByName($attributeName);
}

View File

@@ -0,0 +1,63 @@
<?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;
use Sylius\Component\Translation\Model\AbstractTranslation;
/**
* Model for object attributes translation.
*
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
class AttributeTranslation extends AbstractTranslation implements AttributeTranslationInterface
{
/**
* Attribute id.
*
* @var mixed
*/
protected $id;
/**
* Presentation.
* Displayed to user.
*
* @var string
*/
protected $presentation;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getPresentation()
{
return $this->presentation;
}
/**
* {@inheritdoc}
*/
public function setPresentation($presentation)
{
$this->presentation = $presentation;
return $this;
}
}

View File

@@ -0,0 +1,32 @@
<?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;
/**
* @author Gonzalo Vilaseca <gvilaseca@reiss.co.uk>
*/
interface AttributeTranslationInterface
{
/**
* The name displayed to user.
*
* @return string
*/
public function getPresentation();
/**
* Set presentation.
*
* @param string $presentation
*/
public function setPresentation($presentation);
}

View File

@@ -0,0 +1,39 @@
<?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;
/**
* Default attribute types.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
class AttributeTypes
{
const CHECKBOX = 'checkbox';
const CHOICE = 'choice';
const MONEY = 'money';
const NUMBER = 'number';
const PERCENTAGE = 'percent';
const TEXT = 'text';
public static function getChoices()
{
return array(
self::CHECKBOX => 'Checkbox',
self::CHOICE => 'Choice',
self::MONEY => 'Money',
self::NUMBER => 'Number',
self::PERCENTAGE => 'Percentage',
self::TEXT => 'Text',
);
}
}

View File

@@ -0,0 +1,172 @@
<?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.');
}
}
}

View File

@@ -0,0 +1,92 @@
<?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 value model.
*
* This model associates the attribute with its value on the object.
*
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
interface AttributeValueInterface
{
/**
* Get subject.
*
* @return AttributeSubjectInterface
*/
public function getSubject();
/**
* Set subject.
*
* @param AttributeSubjectInterface|null $subject
*/
public function setSubject(AttributeSubjectInterface $subject = null);
/**
* Get attribute.
*
* @return AttributeInterface
*/
public function getAttribute();
/**
* Set attribute.
*
* @param AttributeInterface $attribute
*/
public function setAttribute(AttributeInterface $attribute);
/**
* Get attribute value.
*
* @return mixed
*/
public function getValue();
/**
* Set attribute value.
*
* @param mixed $value
*/
public function setValue($value);
/**
* Proxy method to access the name from real attribute.
*
* @return string
*/
public function getName();
/**
* Proxy method to access the presentation from real attribute.
*
* @return string
*/
public function getPresentation();
/**
* The type of the attribute.
*
* @return string
*/
public function getType();
/**
* Get attribute configuration.
*
* @return array
*/
public function getConfiguration();
}