Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
bd68a9bf
Commit
bd68a9bf
authored
May 15, 2013
by
Dries
Browse files
Issue
#1988666
by Crell, kim.pepper: Cleanup Controllers and Enhancers.
parent
f6dd1e82
Changes
17
Hide whitespace changes
Inline
Side-by-side
core/core.services.yml
View file @
bd68a9bf
...
...
@@ -160,7 +160,7 @@ services:
class
:
Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher
arguments
:
[
'
@service_container'
]
controller_resolver
:
class
:
Drupal\Core\ControllerResolver
class
:
Drupal\Core\
Controller\
ControllerResolver
arguments
:
[
'
@service_container'
]
http_kernel
:
class
:
Drupal\Core\HttpKernel
...
...
@@ -264,13 +264,8 @@ services:
tags
:
-
{
name
:
event_subscriber
}
arguments
:
[
'
@settings'
]
route_enhancer.modal
:
class
:
Drupal\Core\Routing\Enhancer\ModalEnhancer
arguments
:
[
'
@content_negotiation'
]
tags
:
-
{
name
:
route_enhancer
,
priority
:
40
}
route_enhancer.dialog
:
class
:
Drupal\Core\Routing\Enhancer\DialogEnhancer
route_enhancer.content_controller
:
class
:
Drupal\Core\Routing\Enhancer\ContentControllerEnhancer
arguments
:
[
'
@content_negotiation'
]
tags
:
-
{
name
:
route_enhancer
,
priority
:
30
}
...
...
@@ -290,11 +285,12 @@ services:
arguments
:
[
'
@content_negotiation'
]
tags
:
-
{
name
:
route_enhancer
,
priority
:
10
}
route_enhancer.page
:
class
:
Drupal\Core\Routing\Enhancer\PageEnhancer
arguments
:
[
'
@content_negotiation'
]
tags
:
-
{
name
:
route_enhancer
,
priority
:
0
}
controller.page
:
class
:
Drupal\Core\Controller\HtmlPageController
arguments
:
[
'
@http_kernel'
]
controller.dialog
:
class
:
Drupal\Core\Controller\DialogController
arguments
:
[
'
@http_kernel'
]
router_listener
:
class
:
Symfony\Component\HttpKernel\EventListener\RouterListener
tags
:
...
...
@@ -366,7 +362,7 @@ services:
-
{
name
:
event_subscriber
}
arguments
:
[
'
@language_manager'
]
exception_controller
:
class
:
Drupal\Core\ExceptionController
class
:
Drupal\Core\
Controller\
ExceptionController
arguments
:
[
'
@content_negotiation'
]
calls
:
-
[
setContainer
,
[
'
@service_container'
]]
...
...
core/lib/Drupal/Core/AjaxController.php
→
core/lib/Drupal/Core/
Controller/
AjaxController.php
View file @
bd68a9bf
...
...
@@ -2,18 +2,16 @@
/**
* @file
* Contains \Drupal\Core\AjaxController.
* Contains \Drupal\Core\
Controller\
AjaxController.
*/
namespace
Drupal\Core
;
namespace
Drupal\Core
\Controller
;
use
Drupal\Core\Ajax\AjaxResponse
;
use
Drupal\Core\Ajax\InsertCommand
;
use
Drupal\Core\Ajax\PrependCommand
;
use
Symfony\Component\DependencyInjection\ContainerAware
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Default controller for ajax requests.
...
...
core/lib/Drupal/Core/Controller/ControllerInterface.php
0 → 100644
View file @
bd68a9bf
<?php
/**
* @file
* Contains \Drupal\Core\Controller\ControllerInterface.
*/
namespace
Drupal\Core\Controller
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Defines a common interface for route controllers.
*/
interface
ControllerInterface
{
/**
* Instantiates a new instance of this controller.
*
* This is a factory method that returns a new instance of this object. The
* factory should pass any needed dependencies into the constructor of this
* object, but not the container itself. Every call to this method must return
* a new instance of this object; that is, it may not implement a singleton.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container this object should use.
*/
public
static
function
create
(
ContainerInterface
$container
);
}
core/lib/Drupal/Core/ControllerResolver.php
→
core/lib/Drupal/Core/
Controller/
ControllerResolver.php
View file @
bd68a9bf
...
...
@@ -2,10 +2,10 @@
/**
* @file
*
Definition of Drupal\Core
\ControllerResolver.
*
Contains \Drupal\Core\Controller
\ControllerResolver.
*/
namespace
Drupal\Core
;
namespace
Drupal\Core
\Controller
;
use
Symfony\Component\HttpKernel\Controller\ControllerResolver
as
BaseControllerResolver
;
use
Symfony\Component\HttpKernel\Log\LoggerInterface
;
...
...
@@ -79,7 +79,8 @@ protected function createController($controller) {
if
(
!
class_exists
(
$class
))
{
throw
new
\
InvalidArgumentException
(
sprintf
(
'Class "%s" does not exist.'
,
$class
));
}
if
(
in_array
(
'Drupal\Core\ControllerInterface'
,
class_implements
(
$class
)))
{
// @todo Remove the second in_array() once that interface has been removed.
if
(
in_array
(
'Drupal\Core\Controller\ControllerInterface'
,
class_implements
(
$class
))
||
in_array
(
'Drupal\Core\ControllerInterface'
,
class_implements
(
$class
)))
{
$controller
=
$class
::
create
(
$this
->
container
);
}
else
{
...
...
core/lib/Drupal/Core/
Ajax
/DialogController.php
→
core/lib/Drupal/Core/
Controller
/DialogController.php
View file @
bd68a9bf
...
...
@@ -2,22 +2,36 @@
/**
* @file
* Contains \Drupal\core\
Ajax
\DialogController
* Contains \Drupal\core\
Controller
\DialogController
.
*/
namespace
Drupal\core\
Ajax
;
namespace
Drupal\core\
Controller
;
use
Drupal\Core\ControllerInterface
;
use
Drupal\Core\Ajax\AjaxResponse
;
use
Drupal\Core\Ajax\OpenModalDialogCommand
;
use
Drupal\Core\Ajax\OpenDialogCommand
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\
DependencyInjection\ContainerAwar
e
;
use
Symfony\Component\
HttpKernel\HttpKernelInterfac
e
;
/**
* Defines a default controller for dialog requests.
*/
class
DialogController
extends
ContainerAware
{
class
DialogController
{
/**
* The HttpKernel object to use for subrequests.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected
$httpKernel
;
/**
* Constructs a new HtmlPageController.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
*/
public
function
__construct
(
HttpKernelInterface
$kernel
)
{
$this
->
httpKernel
=
$kernel
;
}
/**
* Forwards request to a subrequest.
...
...
@@ -45,7 +59,7 @@ protected function forward(Request $request, $content) {
// controller.
$request
->
headers
->
remove
(
'accept'
);
return
$this
->
container
->
get
(
'
http
_k
ernel
'
)
->
forward
(
$content
,
$attributes
->
all
(),
$request
->
query
->
all
());
return
$this
->
http
K
ernel
->
forward
(
$content
,
$attributes
->
all
(),
$request
->
query
->
all
());
}
/**
...
...
core/lib/Drupal/Core/ExceptionController.php
→
core/lib/Drupal/Core/
Controller/
ExceptionController.php
View file @
bd68a9bf
...
...
@@ -2,18 +2,20 @@
/**
* @file
*
Definition of Drupal\Core
\ExceptionController.
*
Contains \Drupal\Core\Controller
\ExceptionController.
*/
namespace
Drupal\Core
;
namespace
Drupal\Core
\Controller
;
use
Symfony\Component\DependencyInjection\Container
;
use
Symfony\Component\DependencyInjection\ContainerAware
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\HttpKernel\HttpKernelInterface
;
use
Symfony\Component\HttpKernel\Exception\FlattenException
;
use
Drupal\Core\ContentNegotiation
;
/**
* This controller handles HTTP errors generated by the routing system.
*/
...
...
@@ -107,7 +109,7 @@ public function on403Html(FlattenException $exception, Request $request) {
drupal_static_reset
(
'menu_set_active_trail'
);
menu_reset_static_cache
();
$response
=
$this
->
container
->
get
(
'http_kernel'
)
->
handle
(
$subrequest
,
HttpKernel
::
SUB_REQUEST
);
$response
=
$this
->
container
->
get
(
'http_kernel'
)
->
handle
(
$subrequest
,
HttpKernel
Interface
::
SUB_REQUEST
);
$response
->
setStatusCode
(
403
,
'Access denied'
);
}
else
{
...
...
@@ -180,7 +182,7 @@ public function on404Html(FlattenException $exception, Request $request) {
drupal_static_reset
(
'menu_set_active_trail'
);
menu_reset_static_cache
();
$response
=
$this
->
container
->
get
(
'http_kernel'
)
->
handle
(
$subrequest
,
HttpKernel
::
SUB_REQUEST
);
$response
=
$this
->
container
->
get
(
'http_kernel'
)
->
handle
(
$subrequest
,
HttpKernel
Interface
::
SUB_REQUEST
);
$response
->
setStatusCode
(
404
,
'Not Found'
);
}
else
{
...
...
core/lib/Drupal/Core/HtmlFormController.php
→
core/lib/Drupal/Core/
Controller/
HtmlFormController.php
View file @
bd68a9bf
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\Core\HtmlFormController.
* Contains \Drupal\Core\
Controller\
HtmlFormController.
*/
namespace
Drupal\Core
;
namespace
Drupal\Core
\Controller
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
...
...
core/lib/Drupal/Core/HtmlPageController.php
→
core/lib/Drupal/Core/
Controller/
HtmlPageController.php
View file @
bd68a9bf
...
...
@@ -2,36 +2,34 @@
/**
* @file
*
Definition of Drupal\Core
\HtmlPageController.
*
Contains \Drupal\Core\Controller
\HtmlPageController.
*/
namespace
Drupal\Core
;
namespace
Drupal\Core
\Controller
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\DependencyInjection\ContainerAwareInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpKernel\HttpKernelInterface
;
/**
* Default controller for most HTML pages.
*/
class
HtmlPageController
implements
ContainerAwareInterface
{
class
HtmlPageController
{
/**
* The
injection container for this object
.
* The
HttpKernel object to use for subrequests
.
*
* @var \Symfony\Component\
DependencyInjection\Container
Interface
* @var \Symfony\Component\
HttpKernel\HttpKernel
Interface
*/
protected
$
container
;
protected
$
httpKernel
;
/**
*
Injects the service container used by this object
.
*
Constructs a new HtmlPageController
.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container this object should use.
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
*/
public
function
setContainer
(
ContainerInterface
$container
=
NULL
)
{
$this
->
container
=
$container
;
public
function
__construct
(
HttpKernelInterface
$kernel
)
{
$this
->
httpKernel
=
$kernel
;
}
/**
...
...
@@ -60,7 +58,7 @@ public function content(Request $request, $_content) {
$attributes
->
remove
(
'system_path'
);
$attributes
->
remove
(
'_content'
);
$response
=
$this
->
container
->
get
(
'
http
_k
ernel
'
)
->
forward
(
$controller
,
$attributes
->
all
(),
$request
->
query
->
all
());
$response
=
$this
->
http
K
ernel
->
forward
(
$controller
,
$attributes
->
all
(),
$request
->
query
->
all
());
// For successful (HTTP status 200) responses, decorate with blocks.
if
(
$response
->
isOk
())
{
...
...
core/lib/Drupal/Core/ControllerInterface.php
View file @
bd68a9bf
...
...
@@ -2,28 +2,17 @@
/**
* @file
* Contains \Drupal\Core\ControllerInterface
.
* Contains \Drupal\Core\ControllerInterface
;
*/
namespace
Drupal\Core
;
use
Symfony\Component\DependencyInjection\Container
Interface
;
use
Drupal\Core\Controller\ControllerInterface
as
Base
Interface
;
/**
* Defines a common interface for route controllers.
* BC shiv for controllers using the old interface name.
*
* @deprecated Use \Drupal\Core\Controller\ControllerInterface instead.
*/
interface
ControllerInterface
{
/**
* Instantiates a new instance of this controller.
*
* This is a factory method that returns a new instance of this object. The
* factory should pass any needed dependencies into the constructor of this
* object, but not the container itself. Every call to this method must return
* a new instance of this object; that is, it may not implement a singleton.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container this object should use.
*/
public
static
function
create
(
ContainerInterface
$container
);
interface
ControllerInterface
extends
BaseInterface
{
}
core/lib/Drupal/Core/Entity/HtmlEntityFormController.php
View file @
bd68a9bf
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\Core\Entity
;
use
Drupal\Core\HtmlFormController
;
use
Drupal\Core\
Controller\
HtmlFormController
;
use
Symfony\Component\HttpFoundation\Request
;
/**
...
...
@@ -16,7 +16,7 @@
class
HtmlEntityFormController
extends
HtmlFormController
{
/**
*
Overrides \Drupal\Core\HtmlFormController::content().
*
{@inheritdoc}
*
* Due to reflection, the argument must be named $_entity_form. The parent
* method has $request and $_form, but the parameter must match the route.
...
...
@@ -26,7 +26,7 @@ public function content(Request $request, $_entity_form) {
}
/**
*
Overrides \Drupal\Core\HtmlFormController::getFormObject().
*
{@inheritdoc}
*
* Instead of a class name or service ID, $form_arg will be a string
* representing the entity and operation being performed.
...
...
core/lib/Drupal/Core/Routing/Enhancer/AjaxEnhancer.php
View file @
bd68a9bf
...
...
@@ -39,7 +39,7 @@ public function __construct(ContentNegotiation $negotiation) {
public
function
enhance
(
array
$defaults
,
Request
$request
)
{
if
(
empty
(
$defaults
[
'_content'
])
&&
$this
->
negotiation
->
getContentType
(
$request
)
==
'drupal_ajax'
)
{
$defaults
[
'_content'
]
=
$defaults
[
'_controller'
];
$defaults
[
'_controller'
]
=
'\Drupal\Core\AjaxController::content'
;
$defaults
[
'_controller'
]
=
'\Drupal\Core\
Controller\
AjaxController::content'
;
}
return
$defaults
;
}
...
...
core/lib/Drupal/Core/Routing/Enhancer/
Dialog
Enhancer.php
→
core/lib/Drupal/Core/Routing/Enhancer/
ContentController
Enhancer.php
View file @
bd68a9bf
...
...
@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Routing\Enhancer\
Dialog
Enhancer.
* Contains \Drupal\Core\Routing\Enhancer\
ContentController
Enhancer.
*/
namespace
Drupal\Core\Routing\Enhancer
;
...
...
@@ -12,33 +12,30 @@
use
Drupal\Core\ContentNegotiation
;
/**
* Enhances a route to
u
se
the DialogController for matching
request
s
.
* Enhances a route to se
lect a controller based on the mime type of the
request.
*/
class
Dialog
Enhancer
implements
RouteEnhancerInterface
{
class
ContentController
Enhancer
implements
RouteEnhancerInterface
{
/**
* Content negotiation library.
*
* @var \Drupal\CoreContentNegotiation
* @var \Drupal\Core
\
ContentNegotiation
*/
protected
$negotiation
;
/**
*
Content type this enhancer targets
.
*
Associative array of supported mime types and their appropriate controller
.
*
* @var
string
* @var
array
*/
protected
$targetContentType
=
'drupal_dialog'
;
protected
$types
=
array
(
'drupal_dialog'
=>
'controller.dialog:dialog'
,
'drupal_modal'
=>
'controller.dialog:modal'
,
'html'
=>
'controller.page:content'
,
);
/**
* Controller to route matching requests to.
*
* @var string
*/
protected
$controller
=
'\Drupal\Core\Ajax\DialogController::dialog'
;
/**
* Constructs a new \Drupal\Core\Routing\Enhancer\AjaxEnhancer object.
* Constructs a new ContentControllerEnhancer object.
*
* @param \Drupal\Core\ContentNegotiation $negotiation
* The Content Negotiation service.
...
...
@@ -51,8 +48,11 @@ public function __construct(ContentNegotiation $negotiation) {
* {@inheritdoc}
*/
public
function
enhance
(
array
$defaults
,
Request
$request
)
{
if
(
empty
(
$defaults
[
'_controller'
])
&&
!
empty
(
$defaults
[
'_content'
])
&&
$this
->
negotiation
->
getContentType
(
$request
)
==
$this
->
targetContentType
)
{
$defaults
[
'_controller'
]
=
$this
->
controller
;
if
(
empty
(
$defaults
[
'_controller'
])
&&
!
empty
(
$defaults
[
'_content'
]))
{
$type
=
$this
->
negotiation
->
getContentType
(
$request
);
if
(
isset
(
$this
->
types
[
$type
]))
{
$defaults
[
'_controller'
]
=
$this
->
types
[
$type
];
}
}
return
$defaults
;
}
...
...
core/lib/Drupal/Core/Routing/Enhancer/FormEnhancer.php
View file @
bd68a9bf
...
...
@@ -38,7 +38,7 @@ public function __construct(ContentNegotiation $negotiation) {
*/
public
function
enhance
(
array
$defaults
,
Request
$request
)
{
if
(
empty
(
$defaults
[
'_controller'
])
&&
!
empty
(
$defaults
[
'_form'
])
&&
$this
->
negotiation
->
getContentType
(
$request
)
===
'html'
)
{
$defaults
[
'_controller'
]
=
'\Drupal\Core\HtmlFormController::content'
;
$defaults
[
'_controller'
]
=
'\Drupal\Core\
Controller\
HtmlFormController::content'
;
}
return
$defaults
;
}
...
...
core/lib/Drupal/Core/Routing/Enhancer/ModalEnhancer.php
deleted
100644 → 0
View file @
f6dd1e82
<?php
/**
* @file
* Contains \Drupal\Core\Routing\Enhancer\ModalEnhancer.
*/
namespace
Drupal\Core\Routing\Enhancer
;
/**
* Enhances a route to use the DialogController for matching requests.
*/
class
ModalEnhancer
extends
DialogEnhancer
{
/**
* Content type this enhancer targets.
*
* @var string
*/
protected
$targetContentType
=
'drupal_modal'
;
/**
* Controller to route matching requests to.
*
* @var string
*/
protected
$controller
=
'\Drupal\Core\Ajax\DialogController::modal'
;
}
core/lib/Drupal/Core/Routing/Enhancer/PageEnhancer.php
deleted
100644 → 0
View file @
f6dd1e82
<?php
/**
* @file
* Contains \Drupal\Core\Routing\Enhancer\PageEnhancer.
*/
namespace
Drupal\Core\Routing\Enhancer
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface
;
use
Drupal\Core\ContentNegotiation
;
/**
* Enhances a page route with the appropriate controller.
*/
class
PageEnhancer
implements
RouteEnhancerInterface
{
/**
* Content negotiation library.
*
* @var \Drupal\CoreContentNegotiation
*/
protected
$negotiation
;
/**
* Constructs a new \Drupal\Core\Routing\Enhancer\PageEnhancer object.
*
* @param \Drupal\Core\ContentNegotiation $negotiation
* The Content Negotiation service.
*/
public
function
__construct
(
ContentNegotiation
$negotiation
)
{
$this
->
negotiation
=
$negotiation
;
}
/**
* {@inheritdoc}
*/
public
function
enhance
(
array
$defaults
,
Request
$request
)
{
if
(
empty
(
$defaults
[
'_controller'
])
&&
!
empty
(
$defaults
[
'_content'
])
&&
$this
->
negotiation
->
getContentType
(
$request
)
===
'html'
)
{
$defaults
[
'_controller'
]
=
'\Drupal\Core\HtmlPageController::content'
;
}
return
$defaults
;
}
}
core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php
View file @
bd68a9bf
...
...
@@ -10,7 +10,7 @@
use
Symfony\Component\DependencyInjection\Container
;
use
Symfony\Component\HttpFoundation\Request
;
use
Drupal\Core\ControllerResolver
;
use
Drupal\Core\
Controller\
ControllerResolver
;
use
Drupal\simpletest\UnitTestBase
;
/**
...
...
core/modules/system/lib/Drupal/system/Tests/System/ExceptionControllerTest.php
View file @
bd68a9bf
...
...
@@ -7,7 +7,7 @@
namespace
Drupal\system\Tests\System
;
use
\
Drupal\Core\ContentNegotiation
;
use
\
Drupal\Core\ExceptionController
;
use
\
Drupal\Core\
Controller\
ExceptionController
;
use
\
Drupal\simpletest\UnitTestBase
;
use
\
Symfony\Component\HttpFoundation\Request
;
use
\
Symfony\Component\HttpKernel\Exception\FlattenException
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment