HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/douven.komma.pro/app/KommaApp/Kms/Core/Sections/AbstractAttributeKey.php
<?php
namespace App\KommaApp\Kms\Core\Sections;

/**
 * Class AbstractAttributeKey
 * @package App\KommaApp\Kms\Core\Sections
 *
 * Represents an attribute key that is used for tracking an attribute.
 * You can for example have to "title" attributes that look exactly the same
 * but internally they have a different Attribute key which enables you to select the one that
 * you want to manipulate.
 */
abstract class AbstractAttributeKey
{
    /** @var string $valuePart A string that either refers to the value of an attribute via it's attribute with the same name OR the value itself if it is not linked to any model value*/
    protected $valuePart;

    /** @var string the class name without FQCN from the attribute this key is meant for*/
    protected $attributeShortClassName;

    /** @var string the iso 2 code of the translation of the attribute this key belongs to*/
    protected $translationIso2;

    /**
     * @var string The delimiter that seperates values
     */
    protected static $delimiter = '-';

    /**
     * AbstractAttributeKey constructor.
     */
    public function __construct()
    {
        $this->valuePart = '';
        $this->attributeShortClassName = '';
        $this->translationIso2 = '';
    }

    /**
     * Returns the Attribute key as you must use it in a form.
     */
    abstract public function __toString(): string;

    /**
     * Creates an instance from a string
     *
     * @param string $string
     * @return AbstractAttributeKey
     */
    abstract static public function createInstanceFromString(string $string): self;

    /**
     * @return string
     */
    public function getValuePart(): string
    {
        return $this->valuePart;
    }

    /**
     * @param string $valuePart
     * @return AbstractAttributeKey
     */
    public function setValuePart(string $valuePart): AbstractAttributeKey
    {
        if(strpos($valuePart, static::$delimiter) !== false) throw new \InvalidArgumentException("The valuePart must not contain an '".static::$delimiter."': ".$valuePart);
        $this->valuePart = $valuePart;
        return $this;
    }

    /**
     * @return string
     */
    public function getAttributeShortClassName(): string
    {
        return $this->attributeShortClassName;
    }

    /**
     * @param string $attributeShortClassName
     * @return AbstractAttributeKey
     */
    public function setAttributeShortClassName(string $attributeShortClassName): AbstractAttributeKey
    {
        if(strpos($attributeShortClassName, static::$delimiter) !== false) throw new \InvalidArgumentException("The valuePart must not contain an '".static::$delimiter."': ".$attributeShortClassName);
        $this->attributeShortClassName = $attributeShortClassName;
        return $this;
    }

    /**
     * @return string
     */
    public function getTranslationIso2(): string
    {
        return $this->translationIso2;
    }

    /**
     * @param string $translationIso2
     * @return AbstractAttributeKey
     */
    public function setTranslationIso2(string $translationIso2): AbstractAttributeKey
    {
        if(strpos($translationIso2, static::$delimiter) !== false) throw new \InvalidArgumentException("The valuePart must not contain an '".static::$delimiter."': ".$translationIso2);
        $this->translationIso2 = $translationIso2;
        return $this;
    }
}