Download the PHP package brtriver/karen without Composer
On this page you can find all versions of the php package brtriver/karen. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package karen
Karen -- PSR-7 micro framework with PHP7
Karen is a simple PSR-7 micro framework with PHP7. This framework provide these names of blocks and simple Controller class:
- container
- middleware
- routes
- response
- run
You have only to write a code in your way with PSR-7 objects.
Karen uses following components by default :
- PSR-7 Request, Response
- zendframework/zend-diactoros
- middleware
- relay/relay
- container
- pimple/pimple
- aura/router
- twig/twig
Requirements
- PHP 7.0 or later.
Install
Demo
and open http://localhost:8888/hello/karen_girls
in your browser.
If try FastRoute version, open http://localhost:8888/karen2/hello/karen_girls
Usage
see web/index.php.
You have to write your logic of a controller with anonymous function:
If you write your application class and write logic there instead of anonymous class, it is to be a simple one:
$args
is arguments from routing path,
and $controller
is a instance of Karen\Controller
class.
Karen\Controller
has a render
method. this is equal to $controller->response->getBody()->write($output)
.
Extends Controller
For example, you want to render without a template engine:
And if you want to use a template engine like Twig, you have only to write with anonymous class and trait:
Create your own framework
This microframework application is a simple template method pattern.
this abstract application knows about Request, Response, MiddlewareBulder(relay), so you have to write your application logic in methods(container, middleware, route and response methods) of your extends application class. these methods are executed by run()
method.
method
container
create your container and set necessary object in your container:
Karen use pimple, but you can change it.
middleware (option)
Middleware method is to add your middleware through $this->addQueue()
method as needed.
Karen use (Relay)[http://relayphp.com/], so you have to pass callabe following signature:
This is a sample to change status by query parameter(status):
route
Route method is to define you application routes and controller logics:
or if you use anonymous class, you can your logic to this class:
-
route method:
- anonymous class:
If you change Aura.Route to another, read src/Framework/Karen2.php
response
In response method, you have to pass your controller callable handler to $this->addQueue('action', $handler, $args)
.
it is different how to get $handler
, because it depends on your selected router library.
-
Aura.Router version (Karen.php)
- FastRoute version (Karen2.php)
After execute this response method, queue in middleware are executed automatically.
If you want to use JsonResponse:
Your Own Framework
Within this pattern, you have only to implement your framework logic in these methods.
For example, Karen2 is a sample microframework with FastRoute instead of Aura.Router but you have only to call same methods.
see code web/karen2/index.php
and src/Framework/Karen2.php
Feel free to create your own framework for PHP7.
License
Karen is licensed under the MIT license.
All versions of karen with dependencies
relay/relay Version ^1.0
aura/router Version ^3.0
twig/twig Version ^1.23
pimple/pimple Version ^3.0
nikic/fast-route Version ^0.7.0