Skip to content

Commit

Permalink
Updates to attribute stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Jul 30, 2024
1 parent 79f45de commit 3c1363c
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bard.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"path": "src/SonsOfPHP/Bard",
"repository": "git@github.com:SonsOfPHP/bard.git"
},
{
"path": "src/SonsOfPHP/Contract/Attribute",
"repository": "git@github.com:SonsOfPHP/attribute-contract.git"
},
{
"path": "src/SonsOfPHP/Component/Attribute",
"repository": "git@github.com:SonsOfPHP/attribute.git"
},
{
"path": "src/SonsOfPHP/Contract/Mailer",
"repository": "git@github.com:SonsOfPHP/mailer-contract.git"
Expand Down
66 changes: 66 additions & 0 deletions src/SonsOfPHP/Component/Attribute/Attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Component\Attribute;

use SonsOfPHP\Contract\Attribute\AttributeInterface;
use SonsOfPHP\Contract\Attribute\AttributeTypeInterface;

/**
*/
class Attribute implements AttributeInterface, \Stringable
{
protected ?string $name = null;
protected int $position = 0;
protected ?AttributeTypeInterface $type = null;

public function __toString(): string
{
return (string) $this->getName();
}

public function setCode(?string $code): static
{
// Normalize value
$this->code = strtolower((string) $code);

return $this;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(?string $name): static
{
$this->name = $name;

return $this;
}

public function getPosition(): int
{
return $this->position;
}

public function setPosition(int $position): static
{
$this->position = $position;

return $this;
}

public function getType(): ?AttributeTypeInterface
{
return $this->type;
}

public function setType(AttributeTypeInterface $type): static
{
$this->type = $type;

return $this;
}
}
37 changes: 37 additions & 0 deletions src/SonsOfPHP/Component/Attribute/AttributeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Component\Attribute;

use SonsOfPHP\Contract\Attribute\AttributeTypeInterface;

enum AttributeType: string implements AttributeTypeInterface
{
case TYPE_TEXT = 'text';
// -- OR --
case TextType = 'text';
// -- OR --
case Text = 'text';

//case TextareaType = 'textarea';
//case CheckboxType = 'checkbook';
//case IntegerType = 'integer';
//case FloatType = 'float';
//case DatetimeType = 'datetime';
//case DateType = 'date';
//case SelectType = 'select';

public function getDisplayName(): string
{
return match($this) {
self::TYPE_TEXT => 'Text',
default => 'Unknown',
};
}

public function getType()
{
return $this;
}
}
70 changes: 70 additions & 0 deletions src/SonsOfPHP/Component/Attribute/AttributeValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Component\Attribute;

use SonsOfPHP\Contract\Attribute\AttributeInterface;
use SonsOfPHP\Contract\Attribute\AttributeSubjectInterface;
use SonsOfPHP\Contract\Attribute\AttributeTypeInterface;
use SonsOfPHP\Contract\Attribute\AttributeValueInterface;

/**
*/
class AttributeValue implements AttributeValueInterface
{
protected ?AttributeSubjectInterface $subject = null;
protected ?AttributeInterface $attribute = null;
protected $value = null;

public function getSubject(): ?AttributeSubjectInterface
{
return $this->subject;
}

public function setSubject(?AttributeSubjectInterface $subject): static
{
$this->subject = $subject;

return $this;
}

public function getAttribute(): ?AttributeInterface
{
return $this->attribute;
}

public function setAttribute(?AttributeInterface $attribute): static
{
$this->attribute = $attribute;

return $this;
}

public function getType(): ?AttributeTypeInterface
{
return $this->getAttribute()?->getType();
}

public function getValue()
{
return $this->value;
}

public function setValue($value): static
{
$this->value = $value;

return $this;
}

public function getCode(): ?string
{
return $this->getAttribute()?->getCode();
}

public function getName(): ?string
{
return $this->getAttribute()?->getName();
}
}

0 comments on commit 3c1363c

Please sign in to comment.