first commit
This commit is contained in:
20
modules/Options/Http/OptionController.php
Normal file
20
modules/Options/Http/OptionController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Options\Http;
|
||||
|
||||
use Exception;
|
||||
use Modules\Options\Repository\Factory;
|
||||
|
||||
class OptionController
|
||||
{
|
||||
/**
|
||||
* @param $name
|
||||
* @param Factory $factory
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function index($name, Factory $factory): array
|
||||
{
|
||||
return $factory->make($name)->get();
|
||||
}
|
||||
}
|
2
modules/Options/README.md
Normal file
2
modules/Options/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
## 介绍
|
||||
这是一个公共模块,不耦合其他项目,用于给前端提供统一 select options 数据接口
|
38
modules/Options/Repository/DataRange.php
Normal file
38
modules/Options/Repository/DataRange.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Options\Repository;
|
||||
|
||||
use Modules\Permissions\Enums\DataRange as DataRangeEnum;
|
||||
|
||||
class DataRange implements OptionInterface
|
||||
{
|
||||
public function get(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'label' => DataRangeEnum::All_Data->name(),
|
||||
'value' => DataRangeEnum::All_Data->value()
|
||||
],
|
||||
|
||||
[
|
||||
'label' => DataRangeEnum::Personal_Choose->name(),
|
||||
'value' => DataRangeEnum::Personal_Choose->value()
|
||||
],
|
||||
|
||||
[
|
||||
'label' => DataRangeEnum::Personal_Data->name(),
|
||||
'value' => DataRangeEnum::Personal_Data->value()
|
||||
],
|
||||
|
||||
[
|
||||
'label' => DataRangeEnum::Department_Data->name(),
|
||||
'value' => DataRangeEnum::Department_Data->value()
|
||||
],
|
||||
|
||||
[
|
||||
'label' => DataRangeEnum::Department_DOWN_Data->name(),
|
||||
'value' => DataRangeEnum::Department_DOWN_Data->value()
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
28
modules/Options/Repository/Factory.php
Normal file
28
modules/Options/Repository/Factory.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Options\Repository;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Factory
|
||||
{
|
||||
/**
|
||||
* make
|
||||
* @param string $optionName
|
||||
* @return OptionInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function make(string $optionName): OptionInterface
|
||||
{
|
||||
$className = __NAMESPACE__.'\\'.Str::of($optionName)->ucfirst()->toString();
|
||||
|
||||
$class = new $className();
|
||||
|
||||
if (! $class instanceof OptionInterface) {
|
||||
throw new Exception('option must be implement [OptionInterface]');
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
}
|
25
modules/Options/Repository/Modules.php
Normal file
25
modules/Options/Repository/Modules.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Options\Repository;
|
||||
|
||||
use Catch\Support\Module\ModuleRepository;
|
||||
|
||||
class Modules implements OptionInterface
|
||||
{
|
||||
public function get(): array
|
||||
{
|
||||
$modules = [];
|
||||
|
||||
app(ModuleRepository::class)->all([])
|
||||
|
||||
->each(function ($module) use (&$modules) {
|
||||
$modules[] = [
|
||||
'label' => $module['name'],
|
||||
|
||||
'value' => $module['path']
|
||||
];
|
||||
});
|
||||
|
||||
return $modules;
|
||||
}
|
||||
}
|
11
modules/Options/Repository/OptionInterface.php
Normal file
11
modules/Options/Repository/OptionInterface.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Options\Repository;
|
||||
|
||||
interface OptionInterface
|
||||
{
|
||||
/**
|
||||
* @return array{label: string, value: string|number }
|
||||
*/
|
||||
public function get(): array;
|
||||
}
|
23
modules/Options/Repository/Status.php
Normal file
23
modules/Options/Repository/Status.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Options\Repository;
|
||||
|
||||
use Catch\Enums\Status as StatusEnum;
|
||||
|
||||
class Status implements OptionInterface
|
||||
{
|
||||
public function get(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'label' => StatusEnum::Enable->name(),
|
||||
'value' => StatusEnum::Enable->value()
|
||||
],
|
||||
|
||||
[
|
||||
'label' => StatusEnum::Disable->name(),
|
||||
'value' => StatusEnum::Disable->value()
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user