承接 saeven/zf3-circlical-autowire 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

saeven/zf3-circlical-autowire

最新稳定版本:2.1

Composer 安装命令:

composer require saeven/zf3-circlical-autowire

包简介

Annotation based routing, and magic Controller creation for Laminas and ZF3.

README 文档

README

Build Status Codacy Badge Codacy Badge Total Downloads

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!

统计信息

  • 总下载量: 30.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 5
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2016-10-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固