danmrichards/notaframework

NotAFramework - Something to get things done in PHP

v2.0.1 2019-01-19 12:10 UTC

This package is auto-updated.

Last update: 2024-10-29 04:14:45 UTC


README

Latest Version Software License Build Status Quality Score Total Downloads

This is not a framework, this is something to get things done in PHP.

This thing uses a few community packages to provide just enough functionality to do something useful.

For example Whoops is used for error handling, HttpFoundation is used for HTTP and PHRoute for routing. To name but a few.

Installation

Installation is best handled via composer:

composer create-project --prefer-dist danmrichards/notaframework anewthing

Alternatively, if you dislike composer for some mad reason, you can download the zip file.

Routing

Routes are defined in the src/App/Http/routes.php file. By default routing is powered by PHRoute. So see that for full documentation, but basically routes can either be defined as closures:

$router->get('/example', function() {
    return 'This route responds to requests with the GET method at the path /example';
});

Or they can be defined against classes and methods, such as the 2 example routes defined in the file:

$router->get('/', ['NotAFramework\App\Controllers\HelloWorldController', 'show']);

Controllers

Controllers are placed in the src/App/Controllers directory and should be namespaced under NotAFramework\App\Controllers;.

There is no rigid pattern to follow with these controllers, you can add as many dependencies, helpers and additional traits/services/interfaces you like.

The example controller src/App/Controllers/HelloWorldController.php extends the base NotAFramework\App\Controllers\Controller abstract class. This allows the Symfony Request & Reponse objects to be passed to the controller. This is good practice and will allow easier interfacing with the HTTP layer.

Dependency Injection

Container from the PHP League handles dependency injection. All services are defined in the src/App/container.php file.

A few services have been set up by default; Symfony\Component\HttpFoundation\Request and Symfony\Component\HttpFoundation\Response are defined under the core services section. These are shared dependencies meaning that a single instance will be injected across the application.

Any additional services can be added at the bottom of this file. As an example the default front end renderer, Twig, has been defined. Notice that it has been defined as an alias of the RendererInterface interface, more on this below.

See the Container documentation for more information.

Theming

By default Twig is used as the theme layer, but this can easily be substituted. Simply create a new renderer class in the src/App/Render directory which implements the NotAFramework\App\Render\RendererInterface interface. You cna then update the src/App/container.php file and controllers accordingly.

Twig, if used in file system mode, will look it's template files in the templates folder.

Tests

Yeah...all the packages are unit tested within themselves, and we have PHPUnit. So that'll do for now.

License

MIT License yo!