Skip to content

Commit 7f6b37c

Browse files
committed
feat: attach core library
1 parent 178d892 commit 7f6b37c

12 files changed

Lines changed: 131 additions & 15 deletions

File tree

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
APP_TITLE="My App"
3+
APP_ENV="development"

app/Controllers/HelpController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Controllers;
44

5+
use MaplePHP\Core\Routing\DefaultController;
56
use MaplePHP\Prompts\Themes\Blocks;
6-
use MaplePHP\Unitary\Console\Controllers\DefaultController;
77

88
class HelpController extends DefaultController
99
{
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
6+
7+
use MaplePHP\Core\Routing\DefaultController;
8+
use Psr\Http\Message\ResponseInterface;
9+
10+
class StartController extends DefaultController
11+
{
12+
13+
public function index(ResponseInterface $response): ResponseInterface
14+
{
15+
16+
$response->getBody()->write("Hello World!");
17+
return $response;
18+
}
19+
20+
}

app/Controllers/TestController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
namespace App\Controllers;
44

5-
use MaplePHP\Unitary\Console\Controllers\DefaultController;
5+
use MaplePHP\Core\Routing\DefaultShellController;
66

7-
class TestController extends DefaultController
7+
class TestController extends DefaultShellController
88
{
9-
109
public function index(): void
1110
{
1211
$this->command->message("HELLO WORLD!!");
1312
}
14-
15-
}
13+
}

cli

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
use MaplePHP\Blunder\Handlers\CliHandler;
8-
use MaplePHP\Unitary\Console\Application;
8+
use MaplePHP\Core\CliKernel;
99

1010
$autoload = __DIR__ . '/vendor/autoload.php';
1111
$autoload = realpath($autoload);
@@ -21,9 +21,7 @@ if (!$autoload || !is_file($autoload)) {
2121

2222
require $autoload;
2323

24-
$app = (new Application())
25-
->withRouter(__DIR__ . "/routers/console.php")
26-
->withConfig(__DIR__ . "/unitary.config.php")
24+
$app = (new CliKernel(__DIR__))
2725
->withErrorHandler(new CliHandler())
2826
->boot([
2927
"argv" => $argv,

composer.json

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,50 @@
1717
"email": "daniel.ronkainen@wazabii.se"
1818
}
1919
],
20+
"scripts": {
21+
"test": "vendor/bin/unitary",
22+
"serve": [
23+
"Composer\\Config::disableProcessTimeout",
24+
"@php -S localhost:8000 -t public"
25+
]
26+
},
2027
"require": {
2128
"php": ">=8.2",
22-
"maplephp/unitary": "^v2.1",
23-
"maplephp/log": "^v2.0"
29+
"maplephp/core": "*"
30+
},
31+
"require-dev": {
32+
"maplephp/unitary": "*"
2433
},
34+
"repositories": [
35+
{
36+
"type": "path",
37+
"url": "/Users/danielronkainen/Dev/libraries/Core",
38+
"options": {
39+
"symlink": true
40+
}
41+
},
42+
{
43+
"type": "path",
44+
"url": "/Users/danielronkainen/Dev/libraries/Emitron",
45+
"options": {
46+
"symlink": true
47+
}
48+
},
49+
{
50+
"type": "path",
51+
"url": "/Users/danielronkainen/Dev/libraries/Unitary",
52+
"options": {
53+
"symlink": true
54+
}
55+
},
56+
{
57+
"type": "path",
58+
"url": "/Users/danielronkainen/Dev/libraries/Http",
59+
"options": {
60+
"symlink": true
61+
}
62+
}
63+
],
2564
"autoload": {
2665
"psr-4": {
2766
"App\\": "app/",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
return [
8+
'title' => getenv('APP_TITLE'),
9+
'env' => getenv('APP_ENV'),
810
'type' => "cli",
911
'verbose' => false,
1012
'timezone' => 'UTC',

public/index.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* MaplePHP Unitary bin file
4+
*/
5+
6+
use MaplePHP\Blunder\Handlers\HtmlHandler;
7+
use MaplePHP\Core\HttpKernel;
8+
9+
$root = realpath(__DIR__ . "/../");
10+
$autoload = $root . '/vendor/autoload.php';
11+
$autoload = realpath($autoload);
12+
13+
if (!$autoload || !is_file($autoload)) {
14+
if (!empty($GLOBALS['_composer_autoload_path'])) {
15+
$autoload = $GLOBALS['_composer_autoload_path'];
16+
} else {
17+
die("Autoloader not found. Run `composer install`.\n");
18+
}
19+
}
20+
21+
require $autoload;
22+
23+
$app = (new HttpKernel($root))
24+
->withErrorHandler(new HtmlHandler())
25+
->boot([
26+
"argv" => [],
27+
"dir" => __DIR__
28+
]);

routers/console.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<?php
2+
/**
3+
* Shell router
4+
*
5+
* @var RouterDispatcher $router
6+
*/
27

8+
use MaplePHP\Core\Router\RouterDispatcher;
39
use App\Controllers\TestController;
410
use App\Controllers\HelpController;
511

12+
613
// Bind Middleware to router with `with(TestMiddleware::class)`
714
// use MaplePHP\Unitary\Console\Middlewares\TestMiddleware;
815
// $router->map(["", "test", "run"], [RunTestController::class, "run"])->with(TestMiddleware::class)
916

10-
return $router
11-
->map(["", "run"], [TestController::class, "index"])
12-
->map(["__404", "help"], [HelpController::class, "index"]);
17+
$router->cli("[/help]", [HelpController::class, "index"]);
18+
$router->cli("/run", [TestController::class, "index"]);

routers/web.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Web router
4+
*
5+
* @var RouterDispatcher $router
6+
*/
7+
use MaplePHP\Core\Router\RouterDispatcher;
8+
9+
10+
//$router->cli("/run", [TestController::class, "index"]);
11+
12+
13+
$router->group(function($router) {
14+
15+
$router->get("/", [\App\Controllers\StartController::class, "index"]);
16+
}, []);
17+
18+
19+
//$router->get("/run", [TestController::class, "index"]);
20+
//$router->get("[/help]", [HelpController::class, "index"]);

0 commit comments

Comments
 (0)