|
1 | 1 | <?php |
| 2 | +declare(strict_types=1); |
2 | 3 |
|
3 | 4 | namespace LogReader; |
4 | 5 |
|
5 | 6 | use Cake\Core\BasePlugin; |
| 7 | +use Cake\Core\ContainerInterface; |
| 8 | +use Cake\Core\PluginApplicationInterface; |
| 9 | +use Cake\Http\MiddlewareQueue; |
| 10 | +use Cake\Routing\RouteBuilder; |
| 11 | +use Cake\Console\CommandCollection; |
6 | 12 |
|
7 | 13 | /** |
8 | 14 | * Plugin for LogReader |
9 | 15 | */ |
10 | 16 | class Plugin extends BasePlugin |
11 | 17 | { |
| 18 | + /** |
| 19 | + * Load all the plugin configuration and bootstrap logic. |
| 20 | + * |
| 21 | + * The host application is provided as an argument. This allows you to load |
| 22 | + * additional plugin dependencies, or attach events. |
| 23 | + * |
| 24 | + * @param \Cake\Core\PluginApplicationInterface $app The host application |
| 25 | + * @return void |
| 26 | + */ |
| 27 | + public function bootstrap(PluginApplicationInterface $app): void |
| 28 | + { |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Add routes for the plugin. |
| 33 | + * |
| 34 | + * If your plugin has many routes and you would like to isolate them into a separate file, |
| 35 | + * you can create `$plugin/config/routes.php` and delete this method. |
| 36 | + * |
| 37 | + * @param \Cake\Routing\RouteBuilder $routes The route builder to update. |
| 38 | + * @return void |
| 39 | + */ |
| 40 | + public function routes(RouteBuilder $routes): void |
| 41 | + { |
| 42 | + $routes->plugin( |
| 43 | + 'LogReader', |
| 44 | + ['path' => '/log-reader'], |
| 45 | + function (RouteBuilder $builder) { |
| 46 | + $builder->connect('/', ['controller' => 'LogReader', 'action' => 'index'])->setExtensions(['json']); |
| 47 | + |
| 48 | + $builder->prefix('api', function (RouteBuilder $builder) { |
| 49 | + $builder->prefix('v1', function (RouteBuilder $builder) { |
| 50 | + $builder->connect('/files', ['controller' => 'LogReader', 'action' => 'files'])->setExtensions(['json']); |
| 51 | + $builder->connect('/types', ['controller' => 'LogReader', 'action' => 'types'])->setExtensions(['json']); |
| 52 | + $builder->connect('/logs', ['controller' => 'LogReader', 'action' => 'logs'])->setExtensions(['json']); |
| 53 | + // // $builder->connect('/:controller'); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + $builder->fallbacks(); |
| 58 | + } |
| 59 | + ); |
| 60 | + parent::routes($routes); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Add middleware for the plugin. |
| 65 | + * |
| 66 | + * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update. |
| 67 | + * @return \Cake\Http\MiddlewareQueue |
| 68 | + */ |
| 69 | + public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue |
| 70 | + { |
| 71 | + // Add your middlewares here |
| 72 | + |
| 73 | + return $middlewareQueue; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Add commands for the plugin. |
| 78 | + * |
| 79 | + * @param \Cake\Console\CommandCollection $commands The command collection to update. |
| 80 | + * @return \Cake\Console\CommandCollection |
| 81 | + */ |
| 82 | + public function console(CommandCollection $commands) : CommandCollection |
| 83 | + { |
| 84 | + // Add your commands here |
| 85 | + |
| 86 | + $commands = parent::console($commands); |
| 87 | + |
| 88 | + return $commands; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Register application container services. |
| 93 | + * |
| 94 | + * @param \Cake\Core\ContainerInterface $container The Container to update. |
| 95 | + * @return void |
| 96 | + * @link https://book.cakephp.org/4/en/development/dependency-injection.html#dependency-injection |
| 97 | + */ |
| 98 | + public function services(ContainerInterface $container): void |
| 99 | + { |
| 100 | + // Add your services here |
| 101 | + } |
12 | 102 | } |
0 commit comments