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
15 changes: 15 additions & 0 deletions src/Web/Autowire/RegisterControllerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Cspray\AnnotatedContainer\Bootstrap\ServiceFromServiceDefinition;
use Cspray\AnnotatedContainer\Bootstrap\ServiceGatherer;
use Cspray\AnnotatedContainer\Bootstrap\ServiceWiringListener;
use Cspray\AnnotatedContainer\Profiles;
use Labrador\Web\Controller\Controller;
use Labrador\Web\Controller\RouteMappingAttribute;
use Labrador\Web\Router\Route;
Expand All @@ -15,11 +16,25 @@

final class RegisterControllerListener extends ServiceWiringListener {

/**
* @param list<non-empty-string> $profilesToRouteControllers
*/
public function __construct(
private readonly array $profilesToRouteControllers = ['web']
) {
}

public function wireServices(AnnotatedContainer $container, ServiceGatherer $gatherer) : void {
/** @var LoggerInterface $logger */
$logger = $container->get(LoggerInterface::class);
/** @var Router $router */
$router = $container->get(Router::class);
/** @var Profiles $profiles */
$profiles = $container->get(Profiles::class);

if (!$profiles->isAnyActive($this->profilesToRouteControllers)) {
return;
}

foreach ($gatherer->servicesForType(Controller::class) as $controller) {
$this->handlePotentialHttpController($container, $controller, $logger, $router);
Expand Down
4 changes: 2 additions & 2 deletions test/Integration/BootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function testCorrectlyConfiguredAnnotatedContainerHttpServer() : void {
}

public function testCorrectlyConfiguredAnnotatedContainerRouterRoutes() : void {
$bootstrap = Bootstrap::fromProvidedContainerBootstrap($this->containerBootstrap, profiles: ['default', 'integration-test']);
$bootstrap = Bootstrap::fromProvidedContainerBootstrap($this->containerBootstrap, profiles: ['default', 'integration-test', 'web']);

$container = $bootstrap->bootstrapApplication();

Expand All @@ -162,7 +162,7 @@ public function testCorrectlyConfiguredAnnotatedContainerRouterRoutes() : void {
}

public function testApplicationAutowiringControllersLogged() : void {
$bootstrap = Bootstrap::fromProvidedContainerBootstrap($this->containerBootstrap, profiles: ['default', 'integration-test']);
$bootstrap = Bootstrap::fromProvidedContainerBootstrap($this->containerBootstrap, profiles: ['default', 'integration-test', 'web']);

$bootstrap->bootstrapApplication();

Expand Down
2 changes: 1 addition & 1 deletion test/Integration/HttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function setUpBeforeClass() : void {
self::$vfs = VirtualFilesystem::setup();
self::writeStandardConfigurationFile();

self::$container = self::getContainer(['default', 'integration-test'], new VfsDirectoryResolver());
self::$container = self::getContainer(['default', 'integration-test', 'web'], new VfsDirectoryResolver());
self::$app = self::$container->get(Application::class);

self::$app->start();
Expand Down