Download the PHP package juliangut/slim-controller without Composer
On this page you can find all versions of the php package juliangut/slim-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download juliangut/slim-controller
More information about juliangut/slim-controller
Files in juliangut/slim-controller
Package slim-controller
Short Description Slim Framework controller creator
License BSD-3-Clause
Homepage http://github.com/juliangut/slim-controller
Informations about the package slim-controller
Slim3 controller management
NOTICE: To anyone using this package you should consider moving to juliangut/slim-routing
Class route creation boilerplate, allows you to define your controller classes as services to be pulled out from container easily, extending from a base controller class.
I strongly suggest you don't use this library but for rapid prototyping or certain use cases. If you really want to follow SOLID principles, don't use this package and either directly inject your dependencies in the controller class, use the container to create and inject dependencies or try another container such as PHP-DI with juliangut/slim-php-di
I cannot stress this enough, this library is meant to be used with default Slim container and for certain cases only.
Installation
Best way to install is using Composer:
Then require_once the autoload file:
Usage
If your controller implements Jgut\Slim\Controller\Controller
it has the DI container automatically injected, you can access it by getContainer
method.
If your controller extends Jgut\Slim\Controller\Base
you can also directly access container services the same way you do on a Closure
route callback. Simply take care to not define class attributes with the same name as services in the container. To do this container is injected in the controller and __get
and __isset
magic methods are defined to look into the container.
You can use the resolver to define your class
routes callback and not implement Controller
or extend Base
on those classes, in this case your controller won't have access to the container but it will still be a valid callback.
Important notice
As a general rule of thumb directly injecting container is considered a bad practice as you are actually hiding your dependencies, by fetching them from the container, instead of defining them in the class. You'll be using the container as a service locator rather than a true DIC.
Caveat
This controller registration works only for controllers whose constructor doesn't need any parameters. In case you need a controller with paramenters in its __construct()
method you can still benefit from \Jgut\Slim\Controller\Controller
but you have to register it yourself.
Contributing
Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before
See file CONTRIBUTING.md
License
Release under BSD-3-Clause License.
See file LICENSE included with the source code for a copy of the license terms