mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 19:24:04 +00:00
initial
This commit is contained in:
parent
f9fe9e5cab
commit
41b423da38
11 changed files with 146 additions and 91 deletions
16
src/Exceptions/UndefinedCaseError.php
Normal file
16
src/Exceptions/UndefinedCaseError.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Enums\Exceptions;
|
||||
|
||||
use Error;
|
||||
|
||||
class UndefinedCaseError extends Error
|
||||
{
|
||||
public function __construct(string $enum, string $case)
|
||||
{
|
||||
// Matches the error message of invalid Foo::BAR access
|
||||
parent::__construct("Undefined constant $enum::$case");
|
||||
}
|
||||
}
|
||||
28
src/InvokableCases.php
Normal file
28
src/InvokableCases.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Enums;
|
||||
|
||||
trait InvokableCases
|
||||
{
|
||||
/** Return the enum's value when it's $invoked(). */
|
||||
public function __invoke()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/** Return the enum's value when it's called ::STATICALLY(). */
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
$cases = static::cases();
|
||||
|
||||
foreach ($cases as $case) {
|
||||
if ($case->name === $name) {
|
||||
return $case->value;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exceptions\UndefinedCaseError(static::class, $name);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\REPLACE;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class REPLACEServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
// $this->loadViewsFrom(__DIR__ . '/../assets/views', 'replace');
|
||||
|
||||
// $this->publishes([
|
||||
// __DIR__ . '/../assets/views' => resource_path('views/vendor/replace'),
|
||||
// ], 'replace-views');
|
||||
|
||||
// $this->mergeConfigFrom(
|
||||
// __DIR__ . '/../assets/replace.php',
|
||||
// 'replace'
|
||||
// );
|
||||
|
||||
// $this->publishes([
|
||||
// __DIR__ . '/../assets/replace.php' => config_path('replace.php'),
|
||||
// ], 'replace-config');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue