Skip to content

Commit

Permalink
refactor demo code
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Mar 14, 2018
1 parent a728362 commit d91fba1
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 38 deletions.
File renamed without changes.
5 changes: 1 addition & 4 deletions example/bin/index.php → demo/bin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
* @license http://opensource.org/licenses/MIT MIT
*/
use BEAR\Sunday\Extension\Application\AppInterface;
use Doctrine\Common\Annotations\AnnotationRegistry;
use MyVendor\HelloWorld\AppModule;
use Ray\Di\Injector;

require dirname(__DIR__) . '/vendor/autoload.php';
AnnotationRegistry::registerLoader('class_exists');

$app = (new Injector(new AppModule))->getInstance(AppInterface::class);
try {
$page = $app
->resource
$page = $app->resource
->get
->uri('page://self/index')(['name' => 'BEAR.Sunday'])
->transfer($app->responder, $_SERVER);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion example/phpunit.xml.dist → demo/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<phpunit bootstrap="tests/bootstrap.php">
<phpunit bootstrap="vendor/autoload.php">
<testsuites>
<testsuite>
<directory suffix="Test.php">tests</directory>
Expand Down
68 changes: 68 additions & 0 deletions demo/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* This file is part of the BEAR.Sunday package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
use BEAR\Resource\Exception\BadRequestException;
use BEAR\Resource\Exception\ResourceNotFoundException;
use BEAR\Sunday\Extension\Application\AbstractApp;
use BEAR\Sunday\Extension\Application\AppInterface;
use MyVendor\HelloWorld\AppModule;
use Ray\Di\Injector;

require dirname(__DIR__) . '/vendor/autoload.php';

$app = (new Injector(new AppModule))->getInstance(AppInterface::class);
/* @var $app AbstractApp */
$request = $app->router->match($GLOBALS, $_SERVER);
try {
$page = $app
->resource
->{$request->method}
->uri($request->path)($request->query)
->transfer($app->responder, $_SERVER);
} catch (ResourceNotFoundException $e) {
http_response_code(404);
echo 'Not found' . PHP_EOL;
} catch (BadRequestException $e) {
http_response_code(400);
echo 'Bad request' . PHP_EOL;
} catch (\Exception $e) {
http_response_code(500);
echo 'Server error' . PHP_EOL;
error_log($e);
exit(1);
}

// php -S 127.0.0.1:8088 index.php

//$ curl -i -X DELETE http://127.0.0.1:8088/
//HTTP/1.1 400 Bad Request
//Host: 127.0.0.1:8088
//Date: Wed, 14 Mar 2018 01:10:39 +0100
//Connection: close
//X-Powered-By: PHP/7.1.10
//Content-type: text/html; charset=UTF-8
//
//Bad request

//$ curl -i -X GET http://127.0.0.1:8088/abc
//HTTP/1.1 404 Not Found
//Host: 127.0.0.1:8088
//Date: Wed, 14 Mar 2018 01:09:00 +0100
//Connection: close
//Content-type: text/html; charset=UTF-8
//
//Not found

//$ curl -i -X GET http://127.0.0.1:8088/
//HTTP/1.1 200 OK
//Host: 127.0.0.1:8088
//Date: Wed, 14 Mar 2018 01:10:01 +0100
//Connection: close
//content-type: application/json
//
//{
// "greeting": "Hello World"
//}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions example/public/index.php

This file was deleted.

7 changes: 0 additions & 7 deletions example/tests/bootstrap.php

This file was deleted.

0 comments on commit d91fba1

Please sign in to comment.