Skip to content

Commit 8993956

Browse files
committed
Refactoring
1 parent 33ec46d commit 8993956

File tree

7 files changed

+36
-12
lines changed

7 files changed

+36
-12
lines changed

www/public/index.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
require_once __DIR__ . '/../vendor/autoload.php';
46

57
use BitFrame\App;
@@ -9,11 +11,13 @@
911

1012
(static function () {
1113
$app = new App();
14+
15+
/** @var \BitFrame\Container $container */
1216
$container = $app->getContainer();
1317

1418
import(Server::CONFIG_DIR . 'settings', [$container]);
1519
import(Server::CONFIG_DIR . 'services', [$container]);
16-
import(Server::ROUTES_DIR . 'routes', [$container['router']]);
20+
import(Server::ROUTES_DIR . 'routes', [$container['router'], $container]);
1721

1822
$app->use([
1923
$container['emitter'],

www/server/app/Controller/DefaultController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace YourProject\App\Controller;
46

57
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface};
68
use Psr\Http\Server\RequestHandlerInterface;
9+
use BitFrame\Container;
710

811
class DefaultController
912
{
1013
public function testAction(
1114
ServerRequestInterface $request,
12-
RequestHandlerInterface $handler
15+
RequestHandlerInterface $handler,
16+
Container $container
1317
): ResponseInterface {
14-
$container = $handler->getContainer();
15-
$globals = $container['globals'];
16-
1718
$response = $handler->handle($request);
19+
$globals = $container['globals'];
1820

1921
$response->getBody()->write(
2022
"{$globals['title']} - 👋 Build Something Amazing Today!"

www/server/app/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace YourProject\App;
46

57
class Server

www/server/config/routes.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
use BitFrame\Container;
36
use BitFrame\Router\AbstractRouter;
47
use YourProject\App\Controller\DefaultController;
58

6-
return static function (AbstractRouter $router) {
7-
$router->get('/hello/{action}', [DefaultController::class, 'testAction']);
9+
return static function (AbstractRouter $router, Container $container) {
10+
$router->get('/hello/{action}', [DefaultController::class, 'testAction', $container]);
811
};

www/server/config/services.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3-
use Psr\Container\ContainerInterface;
3+
declare(strict_types=1);
4+
5+
use BitFrame\Container;
46
use BitFrame\FastRoute\Router;
57
use BitFrame\Factory\HttpFactory;
68
use BitFrame\Emitter\SapiEmitter;
79
use BitFrame\Whoops\ErrorHandler;
810
use BitFrame\Whoops\Provider\HandlerProviderNegotiator;
911

10-
return static function (ContainerInterface $container) {
12+
return static function (Container $container) {
1113
$container['router'] = static fn() => new Router();
1214
$container['emitter'] = static fn() => new SapiEmitter();
1315
$container['errorHandler'] = static fn () => (

www/server/config/settings.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3-
use Psr\Container\ContainerInterface;
3+
declare(strict_types=1);
4+
5+
use BitFrame\Container;
46

57
error_reporting(E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
68
date_default_timezone_set('UTC');
79

8-
return static function (ContainerInterface $container) {
10+
return static function (Container $container) {
911
$container['server'] = [
1012
'env' => 'dev',
1113
];

www/server/helper/func.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace YourProject\Helper;
46

57
use function is_callable;
68

7-
function import(string $location, array $args = []) {
9+
/**
10+
* @param string $location
11+
* @param array $args
12+
*
13+
* @return mixed
14+
*/
15+
function import(string $location, array $args = [])
16+
{
817
if (is_dir($location)) {
918
$location .= 'index';
1019
}

0 commit comments

Comments
 (0)