intellect-web-development/symfony-entry-contract-bundle
最新稳定版本:1.1.0
Composer 安装命令:
composer require intellect-web-development/symfony-entry-contract-bundle
包简介
SymfonyEntryContract Symfony bundle for pretty contracts
README 文档
README
HTTP Entry:
InputContract:
<?php declare(strict_types=1); namespace App\Entry\Http\Root; use IWD\SymfonyEntryContract\Interfaces\InputContractInterface; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotNull; class InputContract implements InputContractInterface { #[NotNull] #[Length(min: 3, max: 255)] public string $name; }
Http Action/Controller:
<?php declare(strict_types=1); namespace App\Entry\Http\Root; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class Action { #[Route(path: '', methods: ['GET'])] public function action( InputContract $inputContract ): Response { return new Response($inputContract->name); } }
CLI Entry:
InputContract:
<?php declare(strict_types=1); namespace App\Entry\Console\Demo; use IWD\SymfonyEntryContract\Interfaces\InputContractInterface; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotNull; class InputContract implements InputContractInterface { /** User email */ #[NotNull] #[NotBlank] public string $email = 'user@dev.com'; /** User name */ #[NotNull] #[NotBlank] #[Length(min: 1)] public string $name = 'Foo'; /** Root user password */ #[NotNull] #[NotBlank] #[Length(min: 4)] public string $password = 'bar'; }
CliCommand:
<?php declare(strict_types=1); namespace App\Entry\Console\Demo; use IWD\SymfonyEntryContract\Attribute\CliContract; use IWD\SymfonyEntryContract\Console\CliCommand; use IWD\SymfonyEntryContract\Interfaces\InputContractInterface; use IWD\SymfonyEntryContract\Service\CliContractResolver; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Style\SymfonyStyle; #[AsCommand( name: 'app:demo', description: 'Demo CLI', )] #[CliContract(class: InputContract::class)] class DemoCommand extends CliCommand { public function __construct( CliContractResolver $cliContractResolver, ) { parent::__construct($cliContractResolver); } /** * @param InputContract $inputContract */ protected function handle(SymfonyStyle $io, InputContractInterface $inputContract): int { $io->success( sprintf( '%, %, %', $inputContract->name, $inputContract->email, $inputContract->password ) ); return self::SUCCESS; } }
Command help:
php bin/console app:demo -h
Result:
Description:
Demo CLI
Usage:
app:demo [options]
Options:
--email=EMAIL User email [default: "user@dev.com"]
--name=NAME User name [default: "Foo"]
--password=PASSWORD Root user password [default: "bar"]
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-e, --env=ENV The Environment name. [default: "dev"]
--no-debug Switch off debug mode.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
统计信息
- 总下载量: 2.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-03