Skip to content

Commit a5f661d

Browse files
committed
Controllers can now be services.
1 parent d8e4270 commit a5f661d

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/Trident/Component/HttpKernel/AbstractKernel.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ abstract class AbstractKernel implements HttpKernelInterface
5151
protected $session;
5252
protected $startTime;
5353

54-
const VERSION = '1.0.6-alpha2';
54+
const VERSION = '1.0.6-alpha3';
5555
const VERSION_ID = '10006';
5656
const MAJOR_VERSION = '1';
5757
const MINOR_VERSION = '0';
5858
const RELEASE_VERSION = '6';
59-
const EXTRA_VERSION = 'alpha2';
59+
const EXTRA_VERSION = 'alpha3';
6060

6161
/**
6262
* Constructor.
@@ -141,17 +141,9 @@ protected function handleRequest(Request $request, $type)
141141
$event->setArguments($arguments);
142142
$this->getDispatcher()->dispatch(KernelEvents::CONTROLLER, $event);
143143

144-
if (method_exists($controller, 'preAction')) {
145-
$controller->preAction();
146-
}
147-
148144
// Attempt to get a response from the controller
149145
$response = call_user_func_array($controller, $arguments);
150146

151-
if (method_exists($controller, 'postAction')) {
152-
$controller->postAction();
153-
}
154-
155147
if ( ! $response instanceof Response) {
156148
$message = sprintf('The controller must return a valid Response (%s given).', $this->varToString($response));
157149

src/Trident/Component/HttpKernel/Controller/ControllerResolver.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ protected function createController($controller)
7676

7777
list($class, $method) = explode('::', $controller, 2);
7878

79-
if (!class_exists($class)) {
80-
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
79+
if ($this->container->has($class)) {
80+
$controller = $this->container->get($class);
81+
} else {
82+
if ( ! class_exists($class)) {
83+
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
84+
}
85+
86+
$controller = new $class();
8187
}
8288

83-
$controller = new $class();
8489
if ($controller instanceof ContainerAwareInterface) {
8590
$controller->setContainer($this->container);
8691
}

0 commit comments

Comments
 (0)