-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79f45de
commit 3c1363c
Showing
4 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |