mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-03-13 01:30:11 +01:00
93 lines
2.0 KiB
PHP
93 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use ReflectionClass;
|
|
use function dirname;
|
|
use function in_array;
|
|
|
|
abstract class ModuleServiceProvider extends ServiceProvider
|
|
{
|
|
public static string $name = '';
|
|
|
|
public static string $slug = '';
|
|
|
|
public static string $author = '';
|
|
|
|
public static string $description = '';
|
|
|
|
public static string $version = '';
|
|
|
|
public static string $url = '';
|
|
|
|
public static function name(): string
|
|
{
|
|
return static::$name;
|
|
}
|
|
|
|
public static function description(): string
|
|
{
|
|
return static::$description;
|
|
}
|
|
|
|
/**
|
|
* @psalm-suppress InvalidNullableReturnType
|
|
*/
|
|
public static function slug(): string
|
|
{
|
|
$slug = static::$slug;
|
|
if (empty($slug)) {
|
|
/**
|
|
* @psalm-suppress UnresolvableInclude
|
|
*/
|
|
$cached_packages = require app()->getCachedPackagesPath();
|
|
$slug = array_key_first(
|
|
Arr::where(
|
|
$cached_packages,
|
|
static fn (array $package) => in_array(static::class, $package['providers'], true)
|
|
)
|
|
);
|
|
static::$slug = $slug;
|
|
}
|
|
|
|
/**
|
|
* @psalm-suppress NullableReturnStatement
|
|
*/
|
|
return $slug;
|
|
}
|
|
|
|
public static function author(): string
|
|
{
|
|
$author = static::$author;
|
|
if (empty($author)) {
|
|
$slug = static::slug();
|
|
$author = explode('/', $slug)[0] ?? '';
|
|
static::$author = $author;
|
|
}
|
|
|
|
return $author;
|
|
}
|
|
|
|
public static function version(): string
|
|
{
|
|
return static::$version;
|
|
}
|
|
|
|
public static function url(): string
|
|
{
|
|
return static::$url;
|
|
}
|
|
|
|
public static function modulePath(): string
|
|
{
|
|
return dirname((new ReflectionClass(static::class))->getFileName(), 2);
|
|
}
|
|
|
|
public static function namespace(): string
|
|
{
|
|
return (new ReflectionClass(static::class))->getNamespaceName();
|
|
}
|
|
}
|