Compare commits
9 Commits
9c5051b9e8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 749bac4a1e | |||
| b1e7bff20f | |||
| 36552f2edb | |||
| 69305db69a | |||
| 2a1edb96c8 | |||
| 5c0d22f716 | |||
| 4f6f0c3c1a | |||
| 0b4400588e | |||
|
|
42d9ad8cb1 |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,8 +1,4 @@
|
||||
# ---> Composer
|
||||
composer.lock
|
||||
composer.phar
|
||||
/nbproject/
|
||||
/vendor/
|
||||
|
||||
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
|
||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||
# composer.lock
|
||||
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Potter
|
||||
Copyright (c) 2025 Jay Potter
|
||||
|
||||
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
|
||||
|
||||
21
composer.json
Normal file
21
composer.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "potter/nameable",
|
||||
"type": "library",
|
||||
"require": {
|
||||
"php": "^8.4",
|
||||
"potter/aware": "dev-main"
|
||||
},
|
||||
"license": "MIT",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Potter\\Nameable\\": "src/Potter/Nameable/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jay Potter",
|
||||
"email": "j@ypotter.ca"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
15
src/Potter/Nameable/NameableInterface.php
Normal file
15
src/Potter/Nameable/NameableInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Potter\Nameable;
|
||||
|
||||
use \Potter\Aware\AwareInterface;
|
||||
|
||||
interface NameableInterface extends AwareInterface
|
||||
{
|
||||
public function getName(): string;
|
||||
public function hasName(): bool;
|
||||
public function withName(string $name): self;
|
||||
public function withoutName(): self;
|
||||
}
|
||||
54
src/Potter/Nameable/NameableTrait.php
Normal file
54
src/Potter/Nameable/NameableTrait.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Potter\Nameable;
|
||||
|
||||
use \Potter\Aware\AwareInterface;
|
||||
|
||||
trait NameableTrait
|
||||
{
|
||||
private const string NAME = 'name';
|
||||
|
||||
abstract public function get(string $key): mixed;
|
||||
|
||||
final public function getName(): string
|
||||
{
|
||||
return $this->get(self::NAME);
|
||||
}
|
||||
|
||||
abstract public function has(string $key): bool;
|
||||
|
||||
final public function hasName(): bool
|
||||
{
|
||||
return $this->has(self::NAME);
|
||||
}
|
||||
|
||||
abstract protected function set(string $key, mixed $value): mixed;
|
||||
|
||||
final protected function setName(string $name): string
|
||||
{
|
||||
return $this->set(self::NAME, $name);
|
||||
}
|
||||
|
||||
abstract protected function unset(string $key): void;
|
||||
|
||||
final protected function unsetName(): void
|
||||
{
|
||||
$this->unset(self::NAME);
|
||||
}
|
||||
|
||||
abstract public function with(string $key, mixed $value): AwareInterface;
|
||||
|
||||
final public function withName(string $name): NameableInterface
|
||||
{
|
||||
return $this->with(self::NAME, $name);
|
||||
}
|
||||
|
||||
abstract public function without(string $key): AwareInterface;
|
||||
|
||||
final public function withoutName(): NameableInterface
|
||||
{
|
||||
return $this->without(self::NAME);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user