shubinmi / ant-framework-php
Ant framework. A small tool for big purpose.
1.1.2
2017-03-15 12:02 UTC
Requires
- php: >=5.4
- nikic/fast-route: ^1.0
- pimple/pimple: ^3.0
- zendframework/zend-diactoros: ^1.3
This package is not auto-updated.
Last update: 2024-11-09 20:45:15 UTC
README
A small php tool for big purpose
The concept - to know its place and purpose. The rule of this framework - to be flexible and not to be intrusive.
Installation
Install the latest version with
$ composer require shubinmi/ant-framework-php
Basic Usage
index.php
<?php use Ant\Application\Application; // Define paths of folders with configuration files $configDirs = [ 'Config/Production' ]; if (defined('APPLICATION_ENV') && APPLICATION_ENV == 'local') { $configDirs[] = 'Config/Local'; } $app = new Application(); $app->loadConfig($configDirs); $app->run();
./Config/Production/router.php
<?php return [ 'router' => [ 'main' => [ ['GET', 'POST'], '/[{msg}[/]]', [ 'controller' => 'Controllers\Main', 'action' => 'mainAction' ] ] ] ]
./Config/Local/router.php
<?php return [ 'router' => [ // This will be rewriting rulles for path with 'main' key at Production folder 'main' => [ ['GET', 'POST'], '/[{msg}[/]]', [ 'controller' => 'Controllers\Main', 'action' => 'mainAction' ] ] ] ]
./Controllers/Main.php
<?php namespace Controllers; use Ant\Application\Controller; use Ant\Application\View; class Main extends Controller { public function mainAction() { $msg = $this->getRequestUriParam('msg'); $elements = [ // It mean that {{body}} at layout.phtml (and at other view elements) will be // replaced to content from main.phtml 'body' => [ 'path' => 'Views/main.phtml', 'vars' => ['msg' => $msg] ] ]; return $this->getView()->addLayoutElements($elements); } private function getView() { $view = new View(); $view->setLayoutPath('Views/layout.phtml'); return $view; } }
./Views/layout.phtml
<!DOCTYPE html> <html> <head> </head> <body> {{body}} </body> </html>
./Views/main.phtml
Your message = " <?php /** @var string|null $msg */ echo $msg; ?> "
Roadmap
- Core Framework
- + Examples (Add to advance DI)
- + Tests
- + Validators
- + RPC API
- + RestFull API
- + Web sockets API