milan-miscevic / inert
带有基本MVC和服务容器支持的微型PHP框架
0.14
2022-04-01 06:57 UTC
Requires
- php: ^7.4 || ^8
- psr/container: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8.0
- infection/infection: ^0.26.6
- phpstan/phpstan: ^1.5.2
- phpstan/phpstan-strict-rules: ^1.1
- phpunit/phpunit: ^9.5.19
- vimeo/psalm: ^4.22.0
- dev-master
- 0.14
- 0.13
- 0.12
- 0.11
- 0.10
- 0.9
- 0.8
- 0.7
- 0.6
- 0.5.1
- 0.5
- 0.4
- 0.3
- 0.2
- 0.1
- dev-renovate/vimeo-psalm-5.x-lockfile
- dev-renovate/shivammathur-setup-php-2.x
- dev-renovate/infection-infection-0.x
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/phpstan-packages
- dev-renovate/friendsofphp-php-cs-fixer-3.x-lockfile
- dev-renovate/phpunit-phpunit-9.x-lockfile
- dev-renovate/actions-checkout-4.x
- dev-deps
This package is auto-updated.
Last update: 2024-09-11 09:45:51 UTC
README
此仓库提供了一个带有基本MVC和服务容器支持的微型PHP框架。其名称来源于其目标项目类型 - 小型(几乎)非动态项目,或称惯性项目。
在大型项目中使用完整的框架后,使用纯PHP(通过require)且没有控制器和动作的工作方式可能会显得有些奇怪。主要想法是将控制器和动作引入小型私有项目以组织代码,同时保持纯PHP的配置简单性以及最小化依赖。这就是这个框架的诞生原因。后来,在开发过程中,添加了服务定位器。
最小安装
通过Composer安装Inert
composer require milan-miscevic/inert
index.php
<?php use Mmm\Inert\ActionContainer; use Mmm\Inert\Application; use Mmm\Inert\ServiceContainer; require '../vendor/autoload.php'; $actions = [ 'index' => IndexAction::class, ]; $actionContainer = new ActionContainer( $actions, new ServiceContainer([]) ); echo (new Application($actionContainer))->run()->getContent();
IndexAction.php:
<?php use Mmm\Inert\Action; use Mmm\Inert\Response; class IndexAction implements Action { public function run(): Response { return new Response('Hello, world!'); } }