https://github.com/mezzio/mezzio-tooling
Migration and development tooling for Mezzio
https://github.com/mezzio/mezzio-tooling
cli mezzio tooling
Last synced: about 1 year ago
JSON representation
Migration and development tooling for Mezzio
- Host: GitHub
- URL: https://github.com/mezzio/mezzio-tooling
- Owner: mezzio
- License: bsd-3-clause
- Created: 2019-12-31T21:03:25.000Z (over 6 years ago)
- Default Branch: 2.10.x
- Last Pushed: 2024-10-21T11:16:17.000Z (over 1 year ago)
- Last Synced: 2024-10-21T16:22:07.962Z (over 1 year ago)
- Topics: cli, mezzio, tooling
- Language: PHP
- Homepage: https://docs.mezzio.dev/mezzio/
- Size: 1.25 MB
- Stars: 16
- Watchers: 12
- Forks: 11
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# mezzio-tooling
[](https://github.com/mezzio/mezzio-tooling/actions/workflows/continuous-integration.yml)
> ## π·πΊ Π ΡΡΡΠΊΠΈΠΌ Π³ΡΠ°ΠΆΠ΄Π°Π½Π°ΠΌ
>
> ΠΡ, ΡΡΠ°ΡΡΠ½ΠΈΠΊΠΈ Laminas, ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ ΠΈ ΠΆΠΈΠ²Π΅ΠΌ Π² ΡΠ°Π·Π½ΡΡ
ΡΡΡΠ°Π½Π°Ρ
. Π£ ΠΌΠ½ΠΎΠ³ΠΈΡ
ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΠΊΠΈ ΠΈ ΠΊΠΎΠ»Π»Π΅Π³ΠΈ ΠΊΠ°ΠΊ Π² Π ΠΎΡΡΠΈΠΈ, ΡΠ°ΠΊ ΠΈ Π² Π£ΠΊΡΠ°ΠΈΠ½Π΅. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΡΠΎΠ΄ΠΈΠ»ΠΈΡΡ Π² Π ΠΎΡΡΠΈΠΈ. ΠΠ΅ΠΊΠΎΡΠΎΡΡΠ΅ ΠΈΠ· Π½Π°Ρ ΠΆΠΈΠ²ΡΡ Π² Π ΠΎΡΡΠΈΠΈ. Π£ Π½Π΅ΠΊΠΎΡΠΎΡΡΡ
Π±Π°Π±ΡΡΠΊΠΈ ΠΈ Π΄Π΅Π΄ΡΡΠΊΠΈ ΡΡΠ°ΠΆΠ°Π»ΠΈΡΡ Ρ ΡΠ°ΡΠΈΡΡΠ°ΠΌΠΈ Π²ΠΎ ΠΡΠΎΡΠΎΠΉ ΠΌΠΈΡΠΎΠ²ΠΎΠΉ Π²ΠΎΠΉΠ½Π΅. ΠΠ΄Π΅ΡΡ Π½ΠΈΠΊΡΠΎ Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ ΡΠ°ΡΠΈΠ·ΠΌ.
>
> Π£ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π½Π°Ρ Π΅ΡΡΡ ΡΠΊΡΠ°ΠΈΠ½ΡΠΊΠ°Ρ ΡΠΎΠ΄ΡΡΠ²Π΅Π½Π½ΠΈΡΠ°, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΏΠ°ΡΠ»Π°ΡΡ ΠΈΠ· Π΄ΠΎΠΌΠ° Π²ΠΌΠ΅ΡΡΠ΅ Ρ ΡΡΠ½ΠΎΠΌ. ΠΠΎΠ΅Π·Π΄ Π·Π°Π΄Π΅ΡΠΆΠ°Π»ΡΡ ΠΈΠ·-Π·Π° Π±ΠΎΠΌΠ±Π΅ΠΆΠΊΠΈ Π½Π° Π΄ΠΎΡΠΎΠ³Π΅ Π²ΠΏΠ΅ΡΠ΅Π΄ΠΈ. Π£ Π½Π°Ρ Π΅ΡΡΡ Π΄ΡΡΠ·ΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΏΡΡΡΡΡΡΡ Π² Π±ΠΎΠΌΠ±ΠΎΡΠ±Π΅ΠΆΠΈΡΠ°Ρ
. ΠΡ Ρ ΡΡΠ΅Π²ΠΎΠ³ΠΎΠΉ ΠΆΠ΄Π΅ΠΌ Π²Π΅ΡΡΠΎΡΠΊΠΈ ΠΎΡ Π½ΠΈΡ
ΠΏΠΎΡΠ»Π΅ Π²ΠΎΠ·Π΄ΡΡΠ½ΡΡ
Π½Π°Π»Π΅ΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π±Π΅ΡΠΏΠΎΡΡΠ΄ΠΎΡΠ½ΠΎ Π½Π°Π½ΠΎΡΡΡ ΡΠ΄Π°ΡΡ ΠΈ ΠΏΠΎΠΏΠ°Π΄Π°ΡΡ ΠΏΠΎ Π±ΠΎΠ»ΡΠ½ΠΈΡΠ°ΠΌ, ΡΠΊΠΎΠ»Π°ΠΌ, Π΄Π΅ΡΡΠΊΠΈΠΌ ΡΠ°Π΄Π°ΠΌ ΠΈ Π΄ΠΎΠΌΠ°ΠΌ. ΠΡ Π½Π΅ Π±Π΅ΡΠ΅ΠΌ ΡΡΠΎ ΠΈΠ· ΠΊΠ°ΠΊΠΈΡ
-Π»ΠΈΠ±ΠΎ Π‘ΠΠ. ΠΡ Π½Π°Π±Π»ΡΠ΄Π°Π΅ΠΌ ΡΡΠΎ Π½Π°ΠΏΡΡΠΌΡΡ.
>
> ΠΡ Π΄ΠΎΠ²Π΅ΡΡΠ΅ΡΠ΅ Π½Π°ΠΌ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ, ΡΡΠΎΠ± ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ Π½Π°ΡΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ, ΠΈ ΠΌΡ ΠΏΡΠΎΡΠΈΠΌ Π²Π°Ρ Π΄ΠΎΠ²Π΅ΡΠΈΡΡΡΡ Π½Π°ΠΌ Π²Π½ΠΎΠ²Ρ. ΠΡ Π½ΡΠΆΠ΄Π°Π΅ΠΌΡΡ Π² ΠΏΠΎΠΌΠΎΡΠΈ. ΠΡΡ
ΠΎΠ΄ΠΈΡΠ΅ ΠΈ ΠΏΡΠΎΡΠ΅ΡΡΡΠΉΡΠ΅ ΠΏΡΠΎΡΠΈΠ² ΡΡΠΎΠΉ Π±Π΅ΡΠΏΠΎΠ»Π΅Π·Π½ΠΎΠΉ Π²ΠΎΠΉΠ½Ρ. ΠΡΡΠ°Π½ΠΎΠ²ΠΈΡΠ΅ ΠΊΡΠΎΠ²ΠΎΠΏΡΠΎΠ»ΠΈΡΠΈΠ΅. Π‘ΠΊΠ°ΠΆΠΈΡΠ΅ "ΠΠ΅Ρ Π²ΠΎΠΉΠ½Π΅!"
>
> ## πΊπΈ To Citizens of Russia
>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
*Migration and development tools for Mezzio.*
## Installation
Install via composer:
```bash
$ composer require --dev mezzio/mezzio-tooling
```
## Command line tooling
This package exposes commands for [laminas-cli](https://docs.laminas.dev/laminas-cli), and may be invoked via `vendor/bin/laminas`.
- `mezzio:action:create`: Create an action class file; this is an alias for the `mezzio:handler:create` command, listed below.
- `mezzio:factory:create`: Create a factory class file for the named class.
The class file is created in the same directory as the class specified.
- `mezzio:handler:create`: Create a PSR-15 request handler class file.
Also generates a factory for the generated class, and, if a template renderer is registered with the application container, generates a template and modifies the class to render it into a laminas-diactoros `HtmlResponse`.
- `mezzio:middleware:create`: Create a PSR-15 middleware class file.
- `mezzio:middleware:migrate-from-interop`: Migrate interop middlewares and delegators to PSR-15 middlewares and request handlers.
- `mezzio:middleware:to-request-handler`: Migrate PSR-15 middleware to request handlers.
- `mezzio:module:create`: Create and register a middleware module with the application.
- `mezzio:module:deregister`: Deregister a middleware module from the application.
- `mezzio:module:register`: Register a middleware module with the application.
- `mezzio:routes:list`: List the application's routing table.
### Routes
#### mezzio:routes:list
This command lists the application's routing table.
For each route, it prints its name, path, middleware, and any additional options, in a tabular format to the terminal.
The routes are listed in no particular order, by default.
The command supports several options, listed in the table below.
| Command Long | Command Short | Description |
|---------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--format` | `-f` | Set the format of the command's output. The supported values are `table`, which is the default, and `json`. If you set the format to json, then we recommend using [jq](https://stedolan.github.io/jq/manual/) to query/filter the command's output. |
| `--sort` | `-s` | Sort the command's output. The supported values are `name` and `path`. |
| `--supports-method` | `-m` | Accepts a comma-separated list of one or more HTTP methods, and filters out routes which don't support those methods. |
| `--has-path` | `-p` | Accepts a comma-separated list of one or more paths, and filters out routes with paths that don't match. The paths can be a regular expression, supported by the `preg_*` functions. For example, "/,/api/ping,*/ping". |
| `--has-name` | `-n` | Accepts a comma-separated list of one or more names, and filters out routes with names that don't match. The names can be fixed strings, or regular expressions supported by the `preg_*` functions. For example, "user,user.register,*.register,user*". |
| `--has-middleware` | `-w` | Accepts a comma-separated list of one or more middleware classes, and filters out routes that do not require those classes. The classes can be fully-qualified, unqualified, or a regular expression, supported by the preg_* functions. For example, "\Mezzio\Middleware\LazyLoadingMiddleware,LazyLoadingMiddleware,\Mezzio*". |
##### Configuration
By default, `Mezzio\Tooling\Routes\DefaultRoutesConfigLoaderFactory` registers a `ConfigLoaderInterface` service with the application's DI container, which retrieves the application's routes from two sources:
- `config/routes.php`
- Routes registered by any loaded `ConfigProvider` class
However, this is a default/fallback implementation.
If you don't store any routes in `config/routes.php` or need a custom implementation, then you need to do two things:
1. Write a custom loader implementation that implements `Mezzio\Tooling\Routes\ConfigLoaderInterface`
2. Register it with the application's DI container as an alias for `Mezzio\Tooling\Routes\ConfigLoaderInterface`
##### Usage Example
Here is an example of what you can expect from running the command.
```bash
$ mezzio:routes:list
+----------+-----------+---------+ Routes ---------------------------------+
| Name | Path | Methods | Middleware |
+----------+-----------+---------+-----------------------------------------+
| api.ping | /api/ping | GET | Mezzio\Middleware\LazyLoadingMiddleware |
| home | / | GET | Mezzio\Middleware\LazyLoadingMiddleware |
+----------+-----------+---------+-----------------------------------------+
```
Here is an example of what you can expect from running the command and setting the format to `json` (formatted with [jq][jq_url]).
```bash
$ mezzio:routes:list --format=json | jq
[
{
"name": "api.ping",
"path": "/api/ping",
"methods": "GET",
"middleware": "Mezzio\\Middleware\\LazyLoadingMiddleware"
},
{
"name": "home",
"path": "/",
"methods": "GET",
"middleware": "Mezzio\\Middleware\\LazyLoadingMiddleware"
}
]
```
> [!NOTE]
> Versions of mezzio/mezzio-tooling prior to v2.0 exposed a `vendor/bin/mezzio` binary, and the various commands exposed all lacked the `mezzio:` prefix, with the following more specific changes:
>
> - `mezzio:middleware:migrate-from-interop` was previously `migrate:interop-middleware`
> - `mezzio:middleware:to-request-handler` was previously `migrate:middleware-to-request-handler`
## Configurable command option values
If the `--modules-path` of your project is not under `src`, you can either provide the path via the `--modules-path` command-line option, or configure it within your application configuration.
By adding the changed path to your application configuration, you can omit the need to use the `--modules-path` option during cli execution for the various `mezzio:module:*` commands.
```php
// In config/autoload/application.global.php:
[
'--modules-path' => 'custom-directory',
],
];
```
[jq_url]: https://jqlang.github.io/jq/