ConfigProvider.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://doc.hyperf.io
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Ycbl\AdminAuth;
  12. use Hyperf\Utils\Collection;
  13. use Hyperf\Utils\Filesystem\Filesystem;
  14. class ConfigProvider
  15. {
  16. public function __invoke(): array
  17. {
  18. return [
  19. 'dependencies' => [
  20. ],
  21. 'commands' => [
  22. ],
  23. 'annotations' => [
  24. 'scan' => [
  25. 'paths' => [
  26. __DIR__,
  27. ],
  28. ],
  29. ],
  30. 'publish' => [
  31. [
  32. 'id' => 'config',
  33. 'description' => 'admin_auth 组件配置.', // 描述
  34. // 建议默认配置放在 publish 文件夹中,文件命名和组件名称相同
  35. 'source' => __DIR__ . '/../publish/config/admin_auth.php', // 对应的配置文件路径
  36. 'destination' => BASE_PATH . '/config/autoload/admin_auth.php', // 复制为这个路径下的该文件
  37. ],
  38. [
  39. 'id' => 'database',
  40. 'description' => 'admin_auth 数据库迁移工具.', // 描述
  41. // 建议默认配置放在 publish 文件夹中,文件命名和组件名称相同
  42. 'source' => __DIR__ . '/../publish/database/create_auth_tables.php.stub', // 对应的配置文件路径
  43. 'destination' => $this->getMigrationFileName(), // 复制为这个路径下的该文件
  44. ],
  45. ],
  46. ];
  47. }
  48. protected function getMigrationFileName(): string
  49. {
  50. $timestamp = date('Y_m_d_His');
  51. $filesystem = new Filesystem();
  52. return Collection::make(BASE_PATH . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR)
  53. ->flatMap(function ($path) use ($filesystem) {
  54. return $filesystem->glob($path . '*_create_auth_tables.php');
  55. })->push(BASE_PATH . "/migrations/{$timestamp}_create_auth_tables.php")
  56. ->first();
  57. }
  58. }