saeven/zf3-circlical-autowire
Composer 安装命令:
composer require saeven/zf3-circlical-autowire
包简介
Annotation based routing, and magic Controller creation for Laminas and ZF3.
README 文档
README
A laminas-mvc module that favors rapid development, it does two things:
- compiles routes to standard PHP arrays for production (and merges them automatically for you too). Does not compete with standard route declarations (both can be used in tandem).
- automatically applies DI into your controllers, do you don't need to write a ton of simple factories
Older versions support zend-mvc, check releases.
Use annotations right above your actions to automatically plug routes into the ZF3 Router. No more gear-switching to route files, or digging through route config arrays when you are refactoring.
This module also provides a reflection-based abstract factory to automatically wire your controllers using their constructors. Just define your constructors (as you should) and let the lazy factory do the rest!
##Installation
Install with:
composer require zf3-circlical-autowire
Then, add it near the top of your application.config.php
'CirclicalAutoWire',
Automatic Controller DI
Don't need to do anything. Excellently lazy, it's automatic. You can code Controllers, add dependencies to your constructor, and this module will inject classes from your service container right into your controller.
Automatic Routes
In any controller that should use this module, simply add this use statement:
use CirclicalAutoWire\Annotations\Route;
Method Annotations
On any action in a controller with the use statement, use these types of annotations:
<?php
/**
* Your usual stuff here
* @returns bool
* @Route("/freedom")
*/
public function anyOldNameAction(){
// this beats editing a route file each time!
}
/**
* This route has a parameter
* @Route("/freedom/:param")
*/
public function anyOldNameAction(){
$this->params()->fromRoute('param');
}
/**
* This route has a parameter and a constraint
* @Route("/freedom/:param", constraints={"param":"[a-zA-Z]"})
*/
public function anyOldNameAction(){
// ...
}
/**
* Route with parameter, constraint, and defaults
* @Route("/freedom/:param", constraints={"param":"[a-zA-Z]"}, defaults={"param":"index"})
*/
public function anyOldNameAction(){
// ...
}
/**
* Route with parameter, name, constraint, and defaults
* @Route("/freedom/:param", name="easy-as-pie", constraints={"param":"[a-zA-Z]"}, defaults={"param":"index"})
*/
public function anyOldNameAction(){
// ...
}
Child Routes
Child routes are simple to define. Define the parent by giving it a name, and whether or not it may terminate. Separately, tell the child routes that their parent is that first route (by way of name). Here's a complete example:
<?php
/**
* Class ChildRouteController
* @package Spec\CirclicalAutoWire\Controller
*/
class ChildRouteController extends AbstractActionController
{
/**
* @Route("/icecream", name="icecream", terminate=true)
*/
public function indexAction(){}
/**
* This is a sample docblock
*
* @Route("/eat", parent="icecream", name="eat")
*/
public function eatAction(){}
/**
* @Route("/select/:flavor", constraints={"flavor":"\d"}, name="select", parent="icecream")
*/
public function selectFlavorAction(){}
}
This will produce:
<?php
'router' => [
'routes' => [
'icecream' => [
'type' => Literal::class,
'options' => [
'route' => '/icecream',
'defaults' => [
'controller' => ChildRouteController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'eat' => [
'type' => Literal::class,
'options' => [
'route' => "/eat",
'defaults' => [
'controller' => ChildRouteController::class,
'action' => 'eat',
],
],
],
'select' => [
'type' => Segment::class,
'options' => [
'route' => "/select/:flavor",
'defaults' => [
'controller' => ChildRouteController::class,
'action' => 'selectFlavor',
],
'constraints' => [
'flavor' => '\d',
],
],
],
],
],
],
],
Controller Annotations
Provided as a convenience, these help you reach a higher level of lazy. If you know all your Controller routes will start
with /index/system, simply annotate your controller as such:
<?php
/**
* Controller Index
* @Route("/index/system")
*/
class IndexController extends AbstractActionController
{
/**
* @Route("/update")
*/
public function updateAction(){
}
/**
* @Route("/get/:id")
*/
public function getAction(){
}
}
In the example above, the following routes will be compiled:
- /index/system/update
- /index/system/get/:id
Two Modes
Mode is set, via config.
Development
In this mode, annotations are scanned and read. There's an incredibly small overhead to scanning Controller code. Each time you refresh, you will see the compiled routes file recreated in the location you have specified (see this Module's config file).
Production
In this mode, annotations are not scanned. Instead, the config file you created in dev mode is automatically merged with your Zend Framework's routes/route config to create a 'traditional' scenario where routes are hardcoded. Zero module overhead.
Important Note: When actuated via the console, it will behave as though it were in production mode
I hope you like this module, you can reach out on freenode's #zftalk or @Saeven on Twitter! All PRs considered!
saeven/zf3-circlical-autowire 适用场景与选型建议
saeven/zf3-circlical-autowire 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.27k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2016 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「controller」 「router」 「annotation」 「acl」 「autowire」 「zf3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 saeven/zf3-circlical-autowire 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 saeven/zf3-circlical-autowire 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 saeven/zf3-circlical-autowire 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
Symfony bundle to add arbitrary metadata to classes and their constants by annotation
Router
PMVC App Action Router
Database alias router extension for Nette Framework
Create mail from controller action render
统计信息
- 总下载量: 30.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2016-10-13