Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/saeven/zf3-circlical-autowire

Automagic wiring of controllers and routes for Laminas or Zend Framework 3.
https://github.com/saeven/zf3-circlical-autowire

laminas laminas-mvc zend-mvc

Last synced: 9 days ago
JSON representation

Automagic wiring of controllers and routes for Laminas or Zend Framework 3.

Awesome Lists containing this project

README

        

# Route Auto-Wiring for Laminas-MVC
[![Build Status](https://github.com/saeven/zf3-circlical-autowire/actions/workflows/phpspec-task.yml/badge.svg)](https://github.com/Saeven/zf3-circlical-autowire/actions)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/74a8233ff1464fada1a333104770705f)](https://www.codacy.com/gh/Saeven/zf3-circlical-autowire/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Saeven/zf3-circlical-autowire&utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/74a8233ff1464fada1a333104770705f)](https://www.codacy.com/gh/Saeven/zf3-circlical-autowire/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Saeven/zf3-circlical-autowire&utm_campaign=Badge_Coverage)
[![Total Downloads](https://poser.pugx.org/saeven/zf3-circlical-autowire/downloads)](https://packagist.org/packages/saeven/zf3-circlical-autowire)

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:

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:

[
'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:

I hope you like this module, you can reach out on freenode's #zftalk or @Saeven on Twitter! All PRs considered!