Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Engine/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public static function autoload(string $class_name): void
}

$locations = [
APP_PATH . '/controller/',
APP_PATH . '/model/',
APP_ROOT,
];
Expand Down
9 changes: 0 additions & 9 deletions Engine/Console/Commands/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ public function execute(mixed ...$args): void
$cli = new Cli();
$router = new Router();
(new ModuleLoader())->load()->registerRoutes($router);
$routesFile = APP_PATH . '/routes.php';

if (!file_exists($routesFile)) {
$cli->warning('No routes file found.');
return;
}

$registerRoutes = require $routesFile;
$registerRoutes($router);

$rows = [];
foreach ($router->getRoutes() as $route) {
Expand Down
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

ShiftPHP is a small API-only PHP framework.

Version `0.5` focuses on the HTTP API core:
The current architecture focuses on an API-only modular monolith:

- explicit routes,
- module-owned routes,
- module-owned controllers,
- module-owned services,
- module-owned CLI commands,
- controller actions,
- JSON responses,
- request helpers,
Expand All @@ -18,18 +21,25 @@ Version `0.5` focuses on the HTTP API core:

## Routing

Routes are registered in `application/routes.php`:
Routes are owned by modules and registered from each module boundary:

```php
use Controllers\HelloController;
namespace Modules\Health;

use Engine\Modules\AbstractModule;
use Engine\Router;
use Engine\Routing\AttributeRouteLoader;
use Modules\Health\Controllers\HealthController;

return static function (Router $router): void {
(new AttributeRouteLoader())->load($router, [
HelloController::class,
]);
};
class Module extends AbstractModule
{
public function registerRoutes(Router $router): void
{
(new AttributeRouteLoader())->load($router, [
HealthController::class,
]);
}
}
```

Supported methods:
Expand All @@ -45,7 +55,7 @@ Supported methods:
Controllers extend `Engine\Controller` and return a response object:

```php
namespace Controllers;
namespace Modules\Users\Controllers;

use Engine\Controller;
use Engine\JsonResponse;
Expand Down Expand Up @@ -131,8 +141,7 @@ php -S 127.0.0.1:8000 index.php
Then open:

```text
http://127.0.0.1:8000/hello
http://127.0.0.1:8000/hello/api/example
http://127.0.0.1:8000/health
```

## CLI
Expand Down
24 changes: 14 additions & 10 deletions REFACTORING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ShiftPHP 0.5 - API-only refactoring
# ShiftPHP - API-only modular monolith

ShiftPHP 0.5 turns the framework into an API-only HTTP core. View templates, compiled view storage, page assets and MVC rendering are out of scope for this line.
ShiftPHP is moving toward an API-only modular monolith. View templates, compiled view storage, page assets and MVC rendering are out of scope for this line.

## 0.5 Scope

Implemented in this branch:

- explicit `application/routes.php` routing,
- module-owned routing,
- route parameters with `{name}` placeholders,
- controller actions returning response objects,
- `Response`, `JsonResponse` and `ResponseEmitter`,
Expand Down Expand Up @@ -55,14 +55,18 @@ Request

## Routes

Routes live in `application/routes.php`:
Routes live inside modules:

```php
return static function (Router $router): void {
(new AttributeRouteLoader())->load($router, [
HelloController::class,
]);
};
class Module extends AbstractModule
{
public function registerRoutes(Router $router): void
{
(new AttributeRouteLoader())->load($router, [
HealthController::class,
]);
}
}
```

Supported methods:
Expand All @@ -78,7 +82,7 @@ Supported methods:
Controllers receive the current `Request` and `ServiceContainer` through the constructor. Actions should return `Response` or `JsonResponse`.

```php
class HelloController extends \Engine\Controller
class HealthController extends \Engine\Controller
{
#[Get('/api/{argument}')]
public function api(#[PathParam] string $argument, #[QueryParam('include')] ?string $include = null): JsonResponse
Expand Down
81 changes: 0 additions & 81 deletions application/controller/HelloController.php

This file was deleted.

11 changes: 0 additions & 11 deletions application/routes.php

This file was deleted.

2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"psr-4": {
"Tools\\": "Engine/Tools",
"Console\\": "Engine/Console",
"AppConsole\\": "application/console",
"Engine\\": "Engine",
"Controllers\\": "application/controller",
"Modules\\": "application/modules"
}
}
Expand Down
6 changes: 0 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@
$modules->registerServices($app->getContainer());
$modules->registerRoutes($app->getRouter());

$routes = APP_PATH . '/routes.php';
if (file_exists($routes)) {
$registerRoutes = require $routes;
$registerRoutes($app->getRouter());
}

$app->start();
Loading
Loading