-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
4032687
commit 72febd9
Showing
17 changed files
with
235 additions
and
5 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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,4 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore |
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,3 @@ | ||
composer.lock | ||
phpunit.xml | ||
vendor/ |
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 |
---|---|---|
|
@@ -8,9 +8,11 @@ | |
use SonsOfPHP\Contract\Attribute\AttributeTypeInterface; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class Attribute implements AttributeInterface, \Stringable | ||
{ | ||
protected ?string $code = null; | ||
protected ?string $name = null; | ||
protected int $position = 0; | ||
protected ?AttributeTypeInterface $type = null; | ||
|
@@ -20,6 +22,11 @@ public function __toString(): string | |
return (string) $this->getName(); | ||
} | ||
|
||
public function getCode(): ?string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function setCode(?string $code): static | ||
{ | ||
// Normalize value | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
|
||
use SonsOfPHP\Contract\Attribute\AttributeTypeInterface; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
enum AttributeType: string implements AttributeTypeInterface | ||
{ | ||
case TYPE_TEXT = 'text'; | ||
|
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
use SonsOfPHP\Contract\Attribute\AttributeValueInterface; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
class AttributeValue implements AttributeValueInterface | ||
{ | ||
|
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,19 @@ | ||
Copyright 2022 to Present Joshua Estes | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,16 @@ | ||
Sons of PHP - Attribute | ||
======================= | ||
|
||
## Learn More | ||
|
||
* [Documentation][docs] | ||
* [Contributing][contributing] | ||
* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo] | ||
* Get Help & Support using [Discussions][discussions] | ||
|
||
[discussions]: https://github.com/orgs/SonsOfPHP/discussions | ||
[mother-repo]: https://github.com/SonsOfPHP/sonsofphp | ||
[contributing]: https://docs.sonsofphp.com/contributing/ | ||
[docs]: https://docs.sonsofphp.com/components/attribute/ | ||
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AAttribute | ||
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AAttribute |
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Component\Attribute\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SonsOfPHP\Component\Attribute\Attribute; | ||
use SonsOfPHP\Contract\Attribute\AttributeInterface; | ||
|
||
/** | ||
* @coversDefaultClass \SonsOfPHP\Component\Attribute\Attribute | ||
*/ | ||
final class AttributeTest extends TestCase | ||
{ | ||
private $model; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->model = new Attribute(); | ||
} | ||
|
||
/** | ||
* @coversNothing | ||
*/ | ||
public function testItHasTheCorrectInterfaces(): void | ||
{ | ||
$this->assertInstanceOf(AttributeInterface::class, $this->model); | ||
} | ||
|
||
/** | ||
* @covers ::getCode | ||
* @covers ::setCode | ||
*/ | ||
public function testCode(): void | ||
{ | ||
$this->assertNull($this->model->getCode()); | ||
$this->model->setCode('sku'); | ||
$this->assertSame('sku', $this->model->getCode()); | ||
} | ||
|
||
/** | ||
* @covers ::getName | ||
* @covers ::setName | ||
*/ | ||
public function testName(): void | ||
{ | ||
$this->assertNull($this->model->getName()); | ||
$this->model->setName('Test Attribute'); | ||
$this->assertSame('Test Attribute', $this->model->getName()); | ||
} | ||
|
||
/** | ||
* @covers ::getPosition | ||
* @covers ::setPosition | ||
*/ | ||
public function testPosition(): void | ||
{ | ||
$this->assertSame(0, $this->model->getPosition()); | ||
$this->model->setPosition(100); | ||
$this->assertSame(100, $this->model->getPosition()); | ||
} | ||
} |
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,54 @@ | ||
{ | ||
"name": "sonsofphp/attribute", | ||
"type": "library", | ||
"description": "Attribute library for PHP", | ||
"keywords": [ | ||
"attribute" | ||
], | ||
"homepage": "https://github.com/SonsOfPHP/attribute", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Joshua Estes", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/SonsOfPHP/sonsofphp/issues", | ||
"forum": "https://github.com/orgs/SonsOfPHP/discussions", | ||
"docs": "https://docs.sonsofphp.com" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SonsOfPHP\\Component\\Attribute\\": "" | ||
}, | ||
"exclude-from-classmap": [ | ||
"/Tests/" | ||
] | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": ">=8.2", | ||
"sonsofphp/attribute-contract": "0.3.x-dev" | ||
}, | ||
"provide": { | ||
"sonsofphp/attribute-implementation": "0.3.x-dev" | ||
}, | ||
"extra": { | ||
"sort-packages": true, | ||
"branch-alias": { | ||
"dev-main": "0.3.x-dev" | ||
} | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/JoshuaEstes" | ||
}, | ||
{ | ||
"type": "tidelift", | ||
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" | ||
} | ||
] | ||
} |
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 |
---|---|---|
|
@@ -5,24 +5,66 @@ | |
namespace SonsOfPHP\Contract\Attribute; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
interface AttributeInterface | ||
{ | ||
public function getCode(): ?string; | ||
|
||
/** | ||
* The code is unique, no two attributes should have the same code. The code | ||
* should ONLY consist of letters, numbers, underscores, and periods. | ||
* | ||
* Example Code: sku | ||
* | ||
* @throws InvalidArgumentException | ||
* - When the code is invalid or contains invalid characters | ||
*/ | ||
public function setCode(?string $code): static; | ||
|
||
public function getName(): ?string; | ||
|
||
/** | ||
* The name of the attribute. This could be displayed on the frontend to | ||
* users or used anywhere. This is the friendly version of the code. This | ||
* does not have to be unique. | ||
* | ||
* @throws InvalidArgumentException | ||
* - When the name is invalid for any reason | ||
*/ | ||
public function setName(?string $name): static; | ||
|
||
public function getType(): ?AttributeTypeInterface; | ||
|
||
/** | ||
* The attribute type such as Text, Textarea, Select, etc. | ||
*/ | ||
public function setType(AttributeTypeInterface $type): static; | ||
|
||
public function getPosition(): int; | ||
|
||
/** | ||
* The position helps with ordering. When returning the list of attributes, the position | ||
* should determine what order they are listed in. | ||
*/ | ||
public function setPosition(int $position): static; | ||
|
||
public function getType(): ?AttributeTypeInterface; | ||
|
||
/** | ||
* Is this a system attribute? System attributes should not be editable by | ||
* a user. | ||
*/ | ||
//public function isSystem(): bool; | ||
|
||
/** | ||
* If the attribute is unique, the values should be checked. An example of | ||
* a unique value would be an email address. This will help avoid duplicate | ||
* resources. | ||
*/ | ||
//public function isUnique(): bool; | ||
|
||
/** | ||
* Similar to a system attribute, this means that the name and code should | ||
* not be modified by users | ||
*/ | ||
//public function isLocked(): bool; | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
/** | ||
* Classes should implement this is they want to use attributes. For example, the Product | ||
* class would implement this | ||
* | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
interface AttributeSubjectInterface | ||
{ | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
|
||
namespace SonsOfPHP\Contract\Attribute; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
interface AttributeTypeInterface | ||
{ | ||
public function getDisplayName(): string; | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
namespace SonsOfPHP\Contract\Attribute; | ||
|
||
/** | ||
* @author Joshua Estes <[email protected]> | ||
*/ | ||
interface AttributeValueInterface | ||
{ | ||
|
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 |
---|---|---|
|
@@ -51,4 +51,4 @@ | |
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" | ||
} | ||
] | ||
} | ||
} |