Compare commits

..

9 Commits

Author SHA1 Message Date
749bac4a1e Add methods 2025-10-25 16:27:41 -04:00
b1e7bff20f Add methods 2025-10-25 16:24:57 -04:00
36552f2edb Add NAME const 2025-10-25 16:24:09 -04:00
69305db69a Implement Aware 2025-10-25 16:23:25 -04:00
2a1edb96c8 Create NameableTrait 2025-10-25 16:22:07 -04:00
5c0d22f716 Create NameableInterface 2025-10-25 16:21:58 -04:00
4f6f0c3c1a composer init 2025-10-25 16:20:43 -04:00
0b4400588e Add first name to Copyright 2025-10-25 16:19:56 -04:00
jay
42d9ad8cb1 Add composer.lock and /nbproject/ 2025-10-25 16:19:36 -04:00
5 changed files with 94 additions and 8 deletions

8
.gitignore vendored
View File

@@ -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

View File

@@ -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
View 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"
}

View 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;
}

View 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);
}
}