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
11 changes: 9 additions & 2 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const labels = context.payload.pull_request.labels.map((label) => label.name);
const versionLabels = labels.filter((name) => /^v\d+\.\d+(\.\d+)?$/.test(name));
const {owner, repo} = context.repo;
const pull_number = context.payload.pull_request.number;
const {data: labels} = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number: pull_number,
});
const labelNames = labels.map((label) => label.name);
const versionLabels = labelNames.filter((name) => /^v\d+\.\d+(\.\d+)?$/.test(name));

if (versionLabels.length !== 1) {
core.setFailed(`Pull request must have exactly one version label like v0.6. Found: ${versionLabels.join(', ') || 'none'}`);
Expand Down
5 changes: 5 additions & 0 deletions Engine/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
namespace Engine;

use Engine\Error\HttpError;
use Engine\Response\JsonResponse;
use Engine\Response\Response;
use Engine\Response\ResponseEmitter;
use Engine\Routing\Attributes\Body;
use Engine\Routing\Attributes\Header;
use Engine\Routing\Attributes\PathParam;
use Engine\Routing\Attributes\QueryParam;
use Engine\Routing\Attributes\Status;
use Engine\Routing\Router\Router;
use Engine\Service\ServiceContainer;
use JsonException;
use ReflectionClass;
use ReflectionException;
Expand Down
2 changes: 1 addition & 1 deletion Engine/Console/Commands/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Engine\Console\Cli;
use Engine\Console\CommandInterface;
use Engine\Modules\ModuleLoader;
use Engine\Router;
use Engine\Routing\Router\Router;

class RouteList implements CommandInterface
{
Expand Down
3 changes: 3 additions & 0 deletions Engine/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Engine;

use Engine\Response\JsonResponse;
use Engine\Response\Response;
use Engine\Service\ServiceContainer;
use JsonException;

/**
Expand Down
4 changes: 2 additions & 2 deletions Engine/Modules/AbstractModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Engine\Modules;

use Engine\Router;
use Engine\ServiceContainer;
use Engine\Routing\Router\Router;
use Engine\Service\ServiceContainer;

abstract class AbstractModule implements ModuleInterface
{
Expand Down
4 changes: 2 additions & 2 deletions Engine/Modules/ModuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Engine\Modules;

use Engine\Router;
use Engine\ServiceContainer;
use Engine\Routing\Router\Router;
use Engine\Service\ServiceContainer;

interface ModuleInterface
{
Expand Down
4 changes: 2 additions & 2 deletions Engine/Modules/ModuleLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Engine\Modules;

use Engine\Router;
use Engine\ServiceContainer;
use Engine\Routing\Router\Router;
use Engine\Service\ServiceContainer;

class ModuleLoader
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Engine;
namespace Engine\Response;

use JsonException;

Expand Down
2 changes: 1 addition & 1 deletion Engine/Response.php → Engine/Response/Response.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Engine;
namespace Engine\Response;

class Response
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Engine;
namespace Engine\Response;

class ResponseEmitter
{
Expand Down
2 changes: 1 addition & 1 deletion Engine/Routing/AttributeRouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Engine\Routing;

use Engine\Router;
use Engine\Routing\Attributes\Route;
use Engine\Routing\Attributes\RoutePrefix;
use Engine\Routing\Router\Router;
use ReflectionClass;

class AttributeRouteLoader
Expand Down
4 changes: 3 additions & 1 deletion Engine/Route.php → Engine/Routing/Router/Route.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Engine;
namespace Engine\Routing\Router;

use Engine\Request;

class Route
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Engine;
namespace Engine\Routing\Router;

readonly class RouteMatch
{
Expand Down
3 changes: 2 additions & 1 deletion Engine/Router.php → Engine/Routing/Router/Router.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace Engine;
namespace Engine\Routing\Router;

use Engine\Error\HttpError;
use Engine\Request;

class Router
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Engine;
namespace Engine\Service;

use Closure;
use InvalidArgumentException;
Expand Down Expand Up @@ -107,4 +107,4 @@ public function getSingletonServices(): array
{
return array_keys($this->singletons);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Engine;
namespace Engine\Service;

/**
* Interface ServiceInterface
Expand All @@ -22,4 +22,4 @@ public function isReady(): bool;
* Get service name
*/
public function getName(): string;
}
}
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ Routes are owned by modules and registered from each module boundary:
```php
namespace Modules\Health;

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

class Module extends AbstractModule
{
Expand Down Expand Up @@ -58,12 +55,12 @@ Controllers extend `Engine\Controller` and return a response object:
namespace Modules\Users\Controllers;

use Engine\Controller;
use Engine\JsonResponse;
use Engine\Response\JsonResponse;
use Engine\Routing\Attributes\Body;
use Engine\Routing\Attributes\Get;
use Engine\Routing\Attributes\Header;
use Engine\Routing\Attributes\Post;
use Engine\Routing\Attributes\PathParam;
use Engine\Routing\Attributes\Post;
use Engine\Routing\Attributes\QueryParam;
use Engine\Routing\Attributes\RoutePrefix;
use Engine\Routing\Attributes\Status;
Expand Down Expand Up @@ -177,12 +174,7 @@ A module registers itself through `Module.php`:
```php
namespace Modules\Health;

use Engine\Modules\AbstractModule;
use Engine\Router;
use Engine\Routing\AttributeRouteLoader;
use Engine\ServiceContainer;
use Modules\Health\Controllers\HealthController;
use Modules\Health\Services\HealthService;
use Engine\Modules\AbstractModule;use Engine\Routing\AttributeRouteLoader;use Engine\Routing\Router\Router;use Engine\Service\ServiceContainer;use Modules\Health\Controllers\HealthController;use Modules\Health\Services\HealthService;

class Module extends AbstractModule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Modules\Health\Controllers;

use Engine\Controller;
use Engine\JsonResponse;
use Engine\Response\JsonResponse;
use Engine\Routing\Attributes\Get;
use Engine\Routing\Attributes\RoutePrefix;
use Modules\Health\Services\HealthService;
Expand Down
4 changes: 2 additions & 2 deletions application/modules/Health/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Modules\Health;

use Engine\Modules\AbstractModule;
use Engine\Router;
use Engine\Routing\AttributeRouteLoader;
use Engine\ServiceContainer;
use Engine\Routing\Router\Router;
use Engine\Service\ServiceContainer;
use Modules\Health\Controllers\HealthController;
use Modules\Health\Services\HealthService;

Expand Down
17 changes: 9 additions & 8 deletions tests/ApiCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
use Engine\App;
use Engine\Controller;
use Engine\Error\HttpError;
use Engine\JsonResponse;
use Engine\Modules\ModuleLoader;
use Engine\Request;
use Engine\ResponseEmitter;
use Engine\Router;
use Engine\ServiceContainer;
use Engine\Response\JsonResponse;
use Engine\Response\ResponseEmitter;
use Engine\Routing\AttributeRouteLoader;
use Engine\Routing\Attributes\Body;
use Engine\Routing\Attributes\Get;
Expand All @@ -17,7 +16,9 @@
use Engine\Routing\Attributes\QueryParam;
use Engine\Routing\Attributes\RoutePrefix;
use Engine\Routing\Attributes\Status;
use Engine\Modules\ModuleLoader;
use Engine\Routing\Router\Route;
use Engine\Routing\Router\Router;
use Engine\Service\ServiceContainer;
use Modules\Health\Services\HealthService;

require_once __DIR__ . '/../bootstrap.php';
Expand All @@ -28,7 +29,7 @@ final class CapturingEmitter extends ResponseEmitter
public array $headers = [];
public string $content = '';

public function emit(\Engine\Response $response): void
public function emit(\Engine\Response\Response $response): void
{
$this->statusCode = $response->getStatusCode();
$this->headers = $response->getHeaders();
Expand Down Expand Up @@ -112,7 +113,7 @@ function makeRequest(string $method, string $uri, string $body = '', array $quer
(new AttributeRouteLoader())->load($router, [TestAttributeController::class]);

$routes = array_map(
static fn (\Engine\Route $route): string => $route->getMethod() . ' ' . $route->getPath(),
static fn (Route $route): string => $route->getMethod() . ' ' . $route->getPath(),
$router->getRoutes()
);

Expand Down Expand Up @@ -224,7 +225,7 @@ function makeRequest(string $method, string $uri, string $body = '', array $quer
assertSameValue(true, $container->has(HealthService::class), 'Health module service should be registered.');

$routes = array_map(
static fn (\Engine\Route $route): string => $route->getMethod() . ' ' . $route->getPath(),
static fn (Route $route): string => $route->getMethod() . ' ' . $route->getPath(),
$router->getRoutes()
);

Expand Down
Loading