Skip to content

Commit 153cf48

Browse files
authored
Fix #29 and #30. Add a basic usage example. Fix typo in documentation (#31)
1 parent 36fa8f6 commit 153cf48

5 files changed

Lines changed: 70 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Hawkbit Changelog
22

3+
## 2.3.0
4+
5+
## Added
6+
7+
- Add basic usage example
8+
9+
## Altered
10+
11+
- Add official league/route 3.0 support
12+
13+
## Fixed
14+
15+
- Fix #29, #30
16+
317
## 2.2.0
418

519
## Added

README.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Hawkbit\Application uses latest versions of [League\Route](https://github.com/th
1818

1919
Hawkbit\Application is an advanced derivate of [Proton](https://github.com/alexbilbie/Proton) and part of Hawkbit\Application Component collection by Marco Bunge. Hawkbit\Application 1.x is also known as Blast Hawkbit\Application.
2020

21+
### Quick start
22+
23+
Please see [public/](public/) for example usage and read documentation.
24+
2125
### Integrations
2226

2327
Hawkbit\Application delivers also optional packages:
@@ -77,7 +81,7 @@ Create a new app
7781

7882
require __DIR__.'/../vendor/autoload.php';
7983

80-
$app = new \Hawkbit\Application\Application();
84+
$app = new \Hawkbit\Application();
8185
```
8286

8387
Create a new app with configuration
@@ -88,15 +92,15 @@ Create a new app with configuration
8892
$config = [
8993
'key' => 'value'
9094
];
91-
$app = new \Hawkbit\Application\Application($config);
95+
$app = new \Hawkbit\Application($config);
9296
```
9397

9498
Add routes
9599

96100
```php
97101
<?php
98102

99-
/** @var Hawkbit\Application\Application $app */
103+
/** @var Hawkbit\Application $app */
100104
$app->get('/', function ($request, $response) {
101105
$response->getBody()->write('<h1>It works!</h1>');
102106
return $response;
@@ -171,7 +175,7 @@ Hawkbit\Application middlewares allows advanced control of lifecycle execution.
171175
$app->addMiddleware(new Acme\SomeMiddleware);
172176
```
173177

174-
Hawkbit\Application uses it's own runner `Hawkbit\Application\Application\MiddelwareRunner`
178+
Hawkbit\Application uses it's own runner `Hawkbit\Application\MiddelwareRunner`
175179

176180
## Routing
177181

@@ -225,7 +229,7 @@ Basic usage with controllers:
225229

226230
require __DIR__.'/../vendor/autoload.php';
227231

228-
$app = new Hawkbit\Application\Application();
232+
$app = new Hawkbit\Application();
229233

230234
$app->get('/', 'HomeController::index'); // calls index method on HomeController class
231235

@@ -259,7 +263,7 @@ Automatic constructor injection of controllers:
259263

260264
require __DIR__.'/../vendor/autoload.php';
261265

262-
$app = new Hawkbit\Application\Application();
266+
$app = new Hawkbit\Application();
263267

264268
$app->getContainer()->add('CustomService', new CustomService);
265269
$app->get('/', 'HomeController::index'); // calls index method on HomeController class
@@ -332,7 +336,7 @@ $app->group('/admin', function (\League\Route\RouteGroup $route) {
332336
#### Available vars
333337

334338
- `$route` - `\League\Route\RouteGroup`
335-
- `$this` - `\Hawkbit\Application\Application`
339+
- `$this` - `\Hawkbit\Application`
336340

337341
## Middleware integrations
338342

@@ -346,7 +350,7 @@ Basic usage with StackPHP (using `Stack\Builder` and `Stack\Run`):
346350
// index.php
347351
require __DIR__.'/../vendor/autoload.php';
348352

349-
$app = new Hawkbit\Application\Application();
353+
$app = new Hawkbit\Application();
350354

351355
$app->get('/', function ($request, $response) {
352356
$response->setContent('<h1>Hello World</h1>');
@@ -373,7 +377,7 @@ Basic usage with Stratigility (using `Zend\Stratigility\MiddlewarePipe`):
373377

374378
use Psr\Http\Message\ResponseInterface;
375379
use Zend\Diactoros\ServerRequestFactory;
376-
use Hawkbit\Application\Application;
380+
use Hawkbit\Application;
377381
use Hawkbit\Application\Stratigility\MiddlewarePipeAdapter;
378382

379383
$application = new Application();
@@ -448,14 +452,14 @@ For more information about channels read this guide - [https://github.com/Seldae
448452
## Events
449453

450454
You can intercept requests and responses at seven points during the lifecycle. You can manipulate Request, Response and
451-
ErrorResponse via `Hawkbit\Application\ApplicationEvent`.
455+
ErrorResponse via `Hawkbit\ApplicationEvent`.
452456

453457
### Application event
454458

455459
```php
456460
<?php
457461

458-
/** @var \Hawkbit\Application\Application\ApplicationEvent $event */
462+
/** @var \Hawkbit\Application\ApplicationEvent $event */
459463

460464
// custom params
461465
$event->getParamCollection(); // returns a mutable \ArrayObject
@@ -470,7 +474,7 @@ $event->getApplication();
470474
```php
471475
<?php
472476

473-
$app->addListener($app::EVENT_REQUEST_RECEIVED, function (\Hawkbit\Application\Application\ApplicationEvent $event) {
477+
$app->addListener($app::EVENT_REQUEST_RECEIVED, function (\Hawkbit\Application\ApplicationEvent $event) {
474478
$request = $event->getRequest();
475479

476480
// manipulate $request
@@ -488,7 +492,7 @@ This event is fired when a request is received but before it has been processed
488492
```php
489493
<?php
490494

491-
$app->addListener($app::EVENT_RESPONSE_CREATED, function (\Hawkbit\Application\Application\ApplicationEvent $event) {
495+
$app->addListener($app::EVENT_RESPONSE_CREATED, function (\Hawkbit\Application\ApplicationEvent $event) {
492496
$request = $event->getRequest();
493497
$response = $event->getResponse();
494498

@@ -508,7 +512,7 @@ This event is fired when a response has been created but before it has been outp
508512
```php
509513
<?php
510514

511-
$app->addListener($app::EVENT_RESPONSE_SENT, function (\Hawkbit\Application\Application\ApplicationEvent $event) {
515+
$app->addListener($app::EVENT_RESPONSE_SENT, function (\Hawkbit\Application\ApplicationEvent $event) {
512516
$request = $event->getRequest();
513517
$response = $event->getResponse();
514518

@@ -526,7 +530,7 @@ This event is fired when a response has been output and before the application l
526530
```php
527531
<?php
528532

529-
$app->addListener($app::EVENT_RUNTIME_ERROR, function (\Hawkbit\Application\Application\ApplicationEvent $event, $exception) use ($app) {
533+
$app->addListener($app::EVENT_RUNTIME_ERROR, function (\Hawkbit\Application\ApplicationEvent $event, $exception) use ($app) {
530534
//process exception
531535
});
532536
```
@@ -542,7 +546,7 @@ This event is always fired when an error occurs.
542546
```php
543547
<?php
544548

545-
$app->addListener($app::EVENT_LIFECYCLE_ERROR, function (\Hawkbit\Application\Application\ApplicationEvent $event, \Exception $exception) {
549+
$app->addListener($app::EVENT_LIFECYCLE_ERROR, function (\Hawkbit\Application\ApplicationEvent $event, \Exception $exception) {
546550
$errorResponse = $event->getErrorResponse();
547551

548552
//manipulate error response and process exception
@@ -561,7 +565,7 @@ This event is fired after runtime.error
561565
```php
562566
<?php
563567

564-
$app->addListener($app::EVENT_LIFECYCLE_COMPLETE, function (\Hawkbit\Application\Application\ApplicationEvent $event) {
568+
$app->addListener($app::EVENT_LIFECYCLE_COMPLETE, function (\Hawkbit\Application\ApplicationEvent $event) {
565569
// access the request using $event->getRequest()
566570
// access the response using $event->getResponse()
567571
});
@@ -574,7 +578,7 @@ This event is fired when a response has been output and before the application l
574578
```php
575579
<?php
576580

577-
$app->addListener($app::EVENT_SHUTDOWN, function (\Hawkbit\Application\Application\ApplicationEvent $event, $response, $terminatedOutputBuffers = []) {
581+
$app->addListener($app::EVENT_SHUTDOWN, function (\Hawkbit\Application\ApplicationEvent $event, $response, $terminatedOutputBuffers = []) {
578582
// access the response using $event->getResponse()
579583
// access terminated output buffer contents
580584
// or force application exit()
@@ -612,7 +616,7 @@ You can bind singleton objects into the container from the main application obje
612616

613617
```php
614618
<?php
615-
/** @var Hawkbit\Application\Application $app */
619+
/** @var Hawkbit\Application $app */
616620
$app['db'] = function () use($app) {
617621
$config = $app->getConfig('database');
618622
$manager = new Illuminate\Database\Capsule\Manager;
@@ -637,7 +641,7 @@ or by container access:
637641

638642
```php
639643
<?php
640-
/** @var Hawkbit\Application\Application $app */
644+
/** @var Hawkbit\Application $app */
641645
$app->getContainer()->share('db', function () use($app) {
642646
$config = $app->getConfig('database');
643647
$manager = new Illuminate\Database\Capsule\Manager;

composer.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@
2424
"email": "hello@alexbilbie.com"
2525
}
2626
],
27-
"repositories": [
28-
{
29-
"type": "vcs",
30-
"url": "https://github.com/thephpleague/route"
31-
}
32-
],
3327
"require": {
3428
"php": ">=5.5.9",
3529
"filp/whoops": "^2.1",
36-
"league/route": "dev-master",
30+
"league/route": "~3.0",
3731
"league/container": "^2.2",
3832
"league/event": "^2.1",
3933
"league/climate": "^3.2",

public/.htaccess

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
RewriteEngine On
2+
3+
# Some hosts may require you to use the `RewriteBase` directive.
4+
# If you need to use the `RewriteBase` directive, it should be the
5+
# absolute physical path to the directory that contains this htaccess file.
6+
#
7+
RewriteBase /
8+
9+
# Disallow set PHPSESSID
10+
RewriteCond %{QUERY_STRING} PHPSESSID=.*$
11+
RewriteRule .* %{REQUEST_URI}? [R=301,L]
12+
13+
RewriteCond %{REQUEST_FILENAME} !-d
14+
RewriteCond %{REQUEST_FILENAME} !-f
15+
RewriteRule ^ index.php [QSA,L]

public/index.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Psr\Http\Message\ResponseInterface;
4+
use Psr\Http\Message\ServerRequestInterface;
5+
6+
require __DIR__.'/../vendor/autoload.php';
7+
8+
$app = new Hawkbit\Application();
9+
10+
$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
11+
$response->getBody()->write('<h1>Hello, World!</h1>');
12+
13+
return $response;
14+
});
15+
16+
$app->run();

0 commit comments

Comments
 (0)