Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 2 months ago
JSON representation
Automagic wiring of controllers and routes for Laminas or Zend Framework 3.
- Host: GitHub
- URL: https://github.com/saeven/zf3-circlical-autowire
- Owner: Saeven
- License: mpl-2.0
- Created: 2016-10-13T12:56:42.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-20T13:13:31.000Z (9 months ago)
- Last Synced: 2024-10-13T23:12:15.174Z (2 months ago)
- Topics: laminas, laminas-mvc, zend-mvc
- Language: PHP
- Homepage:
- Size: 1000 KB
- Stars: 14
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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 RoutesIn 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 AnnotationsProvided 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!