1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 19:24:04 +00:00
This commit is contained in:
Samuel Štancl 2022-02-20 20:58:57 +01:00
parent f9fe9e5cab
commit 41b423da38
11 changed files with 146 additions and 91 deletions

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

View file

@ -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');
}
}