mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-04 11:45:00 +02:00
32 lines
654 B
PHP
32 lines
654 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Scope;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
class ScopeParser
|
|
{
|
|
/**
|
|
* Parse scope instance from string.
|
|
*/
|
|
public static function parse(string $scope): Scope
|
|
{
|
|
if (blank($scope)) {
|
|
return new GlobalScope();
|
|
}
|
|
|
|
if (Str::contains($scope, '.')) {
|
|
return new RelationScope(
|
|
Str::of($scope)
|
|
->explode('.')
|
|
->map(fn (string $scopePart) => Str::singular($scopePart))
|
|
->join('.')
|
|
);
|
|
}
|
|
|
|
return new TypeScope(Str::singular($scope));
|
|
}
|
|
}
|