Lightweight PHP routing framework, respecting CQRS.
Requirements
- PHP >= 7.0
- fileinfo extension for handling uploaded files correctly
For development only:
- xdebug extension for running the tests
Installation
composer require icehawk/icehawk:^2.0
or add to your composer.json
:
"require": {
"icehawk/icehawk": "^2.0"
}
Quickstart (installer)
We provide an installer package that creates a new IceHawk project for you. Simply run:
composer create-project icehawk/installer /path/to/new-project
Answer the questions of the interactive installer and you're good to go.
Quickstart (manual)
Step 0 - Create a basic composer.json
{
"require": {
"icehawk/icehawk": "^2.0"
},
"autoload": {
"psr-4": {
"YourVendor\\YourProject\\": "./"
}
}
}
Then run:
composer update
Step 1 - Create a request handler
<?php declare(strict_types = 1);
namespace YourVendor\YourProject;
use IceHawk\IceHawk\Interfaces\HandlesGetRequest;
use IceHawk\IceHawk\Interfaces\ProvidesReadRequestData;
final class SayHelloRequestHandler implements HandlesGetRequest
{
public function handle( ProvidesReadRequestData $request )
{
echo "Hello World!";
}
}
— SayHelloRequestHandler.php
Step 2 - Create a basic config
All you need is at least one read or write route.
<?php declare(strict_types = 1);
namespace YourVendor\YourProject;
use IceHawk\IceHawk\Routing\ReadRoute;
use IceHawk\IceHawk\Routing\Patterns\Literal;
use YourVendor\YourProject\SayHelloRequestHandler;
final class IceHawkConfig extends \IceHawk\IceHawk\Defaults\IceHawkConfig
{
public function getReadRoutes()
{
return [
new ReadRoute( new Literal('/'), new SayHelloRequestHandler() ),
];
}
}
— IceHawkConfig.php
Step 3 - Create a bootstrap script
<?php declare(strict_types = 1);
namespace YourVendor\YourProject;
use IceHawk\IceHawk\IceHawk;
use IceHawk\IceHawk\Defaults\IceHawkDelegate;
require('vendor/autoload.php');
$iceHawk = new IceHawk(new IceHawkConfig(), new IceHawkDelegate());
$iceHawk->init();
$iceHawk->handleRequest();
— index.php
Step 4 - Say hello
Go to your project folder an run:
php -S 127.0.0.1:8088
Go to your browser an visit: http://127.0.0.1:8088/
Hello World!
Documentation
Further documentation can be found on our website: icehawk.github.io
Contributing
Contributions are welcome! Please see our contribution guide.