2017-25 © Pedro PelÔez
 

library flow

Micro PHP framework

image

spajak/flow

Micro PHP framework

  • Thursday, April 12, 2018
  • by spajak
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Flow

Simple PHP HTTP application base using:, (*1)

Rationale

  • Basing on standardized interfaces and well tested components;
  • Not being tied to any specific framework;
  • Being able to make lightweight and customizable apps fast with just PHP's includes and anonymous functions.

Usage

$app = new Flow\Application;

Register services (using: php-di/php-di):, (*2)

$services = [];
$services['hello'] = function() {
    return new class {
        public function sayHello($name) { return "Hello {$name}!"; }
    };
};
$app->getContainerBuilder()->addDefinitions($services);

Register routes (using: nikic/fast-route):, (*3)

$app->getRouteCollector()->get('/hello[/{name}]', function($request, $name = 'World') use ($app) {
    $container = $app->getContainer();
    $response = $container->get('http_factory')->createResponse(200);
    $response->getBody()->write(
        $container->get('hello')->sayHello($name)
    );
    return $response;
});

Register console commands (using: symfony/console):, (*4)

$app->getConsole()->register('hello')
    ->setDescription('Say hello')
    ->addArgument('name', null, 'Your name', 'World')
    ->setCode(function($input, $output) use ($app) {
        $service = $app->getContainer()->get('hello');
        $output->writeLn($service->sayHello($input->getArgument('name')));
    });

…or use factories to lazy-load commands:, (*5)

use Flow\Command\RequestCommand;
use Flow\Emitter\ConsoleEmitter;

$commands = [];
$commands['request'] = function() use ($app) {
    return new RequestCommand(
        $app->getServerRequestCreator(),
        $app->getBroker(),
        new ConsoleEmitter
    );
}
$app->getCommandLoader()->addFactories($commands);

At the end of the script, simply run the application:, (*6)

$app->run();

Try it from terminal:, (*7)

$ php examples/application.php hello "Grim Reaper"
$ php examples/application.php request GET /hello

License

MIT, (*8)

The Versions

12/04 2018
01/10 2017

v0.7.0

0.7.0.0

Micro PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastian Pająk

17/06 2016

0.6.0

0.6.0.0

Micro PHP framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastian Pająk