Skip to content

Commit

Permalink
[UserManagementBundle][SeoBundle] Deprecate direct container access i…
Browse files Browse the repository at this point in the history
…n controllers
  • Loading branch information
Peter Zentjens committed May 31, 2018
1 parent 3351971 commit a661658
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
11 changes: 11 additions & 0 deletions UPGRADE-5.1.md
Expand Up @@ -55,6 +55,11 @@ SearchBundle
* `SetupIndexCommand::__construct()`, `PopulateIndexCommand::__construct()` and `DeleteIndexCommand::__construct()` now takes an instance of `Kunstmaan\SearchBundle\Configuration\SearchConfigurationChain` as the first argument. Not passing it is deprecated and will throw a `TypeError` in 6.0.
* `SetupIndexCommand`, `PopulateIndexCommand` and `DeleteIndexCommand` have been marked as final.

SeoBundle
---------

* Getting services directly from the container in list controllers is deprecated and will be removed in 6.0. Register your controllers as services and inject the necessary dependencies.
* Getting parameters directly from the container in list controllers is deprecated and will be removed in 6.0. Register your controllers as services and inject the necessary parameters.

TranslatorBundle
----------------
Expand All @@ -65,6 +70,12 @@ TranslatorBundle
* `TranslationFlagCommand::__construct()` now takes an instance of `Kunstmaan\TranslatorBundle\Repository\TranslationRepository` as the first argument. Not passing it is deprecated and will throw a `TypeError` in 6.0.
* `ExportTranslationsCommand`, `ImportTranslationsCommand`, `MigrationsDiffCommand`, `TranslationCacheCommand` and `TranslationFlagCommand` have been marked as final.

UserManagementBundle
--------------------

* Getting services directly from the container in list controllers is deprecated and will be removed in 6.0. Register your controllers as services and inject the necessary dependencies.
* Getting parameters directly from the container in list controllers is deprecated and will be removed in 6.0. Register your controllers as services and inject the necessary parameters.

UtilitiesBundle
---------------

Expand Down
22 changes: 22 additions & 0 deletions src/Kunstmaan/AdminBundle/Controller/BaseSettingsController.php
Expand Up @@ -6,5 +6,27 @@

class BaseSettingsController extends Controller
{
/**
* {@inheritdoc}
*
* @deprecated
*/
protected function get($id)
{
@trigger_error('Getting services directly from the container is deprecated in KunstmaanAdminBundle 5.1 and will be removed in KunstmaanAdminBundle 6.0. Register your controllers as services and inject the necessary dependencies.', E_USER_DEPRECATED);

return parent::get($id);
}

/**
* {@inheritdoc}
*
* @deprecated
*/
protected function getParameter($name)
{
@trigger_error('Getting parameters directly from the container is deprecated in KunstmaanAdminBundle 5.1 and will be removed in KunstmaanAdminBundle 6.0. Register your controllers as services and inject the necessary parameters.', E_USER_DEPRECATED);

return parent::getParameter($name);
}
}
Expand Up @@ -30,7 +30,7 @@ public function robotsSettingsAction(Request $request)
$em = $this->getDoctrine()->getManager();
$repo = $this->getDoctrine()->getRepository("KunstmaanSeoBundle:Robots");
$robot = $repo->findOneBy(array());
$default = $this->getParameter('robots_default');
$default = $this->container->getParameter('robots_default');
$isSaved = true;

if (!$robot) {
Expand Down Expand Up @@ -59,7 +59,7 @@ public function robotsSettingsAction(Request $request)
if (!$isSaved) {
$this->addFlash(
FlashTypes::WARNING,
$this->get('translator')->trans('seo.robots.warning')
$this->container->get('translator')->trans('seo.robots.warning')
);
}

Expand Down
Expand Up @@ -40,7 +40,7 @@ public function listAction(Request $request)
/* @var $em EntityManager */
$em = $this->getDoctrine()->getManager();
/* @var AdminList $adminlist */
$adminlist = $this->get("kunstmaan_adminlist.factory")->createList(new GroupAdminListConfigurator($em));
$adminlist = $this->container->get("kunstmaan_adminlist.factory")->createList(new GroupAdminListConfigurator($em));
$adminlist->bindRequest($request);

return array(
Expand Down Expand Up @@ -75,7 +75,7 @@ public function addAction(Request $request)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.group.add.flash.success', array(
$this->container->get('translator')->trans('kuma_user.group.add.flash.success', array(
'%groupname%' => $group->getName()
))
);
Expand Down Expand Up @@ -119,7 +119,7 @@ public function editAction(Request $request, $id)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.group.edit.flash.success', array(
$this->container->get('translator')->trans('kuma_user.group.edit.flash.success', array(
'%groupname%' => $group->getName()
))
);
Expand Down Expand Up @@ -159,7 +159,7 @@ public function deleteAction($id)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.group.delete.flash.success', array(
$this->container->get('translator')->trans('kuma_user.group.delete.flash.success', array(
'%groupname%' => $group->getName()
))
);
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function listAction(Request $request)

$em = $this->getDoctrine()->getManager();
/* @var AdminList $adminlist */
$adminlist = $this->get("kunstmaan_adminlist.factory")->createList(new RoleAdminListConfigurator($em));
$adminlist = $this->container->get("kunstmaan_adminlist.factory")->createList(new RoleAdminListConfigurator($em));
$adminlist->bindRequest($request);

return array(
Expand Down Expand Up @@ -72,7 +72,7 @@ public function addAction(Request $request)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.roles.add.flash.success.%role%', [
$this->container->get('translator')->trans('kuma_user.roles.add.flash.success.%role%', [
'%role%' => $role->getRole()
])
);
Expand Down Expand Up @@ -116,7 +116,7 @@ public function editAction(Request $request, $id)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.roles.edit.flash.success.%role%', [
$this->container->get('translator')->trans('kuma_user.roles.edit.flash.success.%role%', [
'%role%' => $role->getRole()
])
);
Expand Down Expand Up @@ -156,7 +156,7 @@ public function deleteAction($id)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.roles.delete.flash.success.%role%', [
$this->container->get('translator')->trans('kuma_user.roles.delete.flash.success.%role%', [
'%role%' => $role->getRole()
])
);
Expand Down
20 changes: 10 additions & 10 deletions src/Kunstmaan/UserManagementBundle/Controller/UsersController.php
Expand Up @@ -43,15 +43,15 @@ public function listAction(Request $request)
$em = $this->getDoctrine()->getManager();
$configuratorClassName = '';
if ($this->container->hasParameter('kunstmaan_user_management.user_admin_list_configurator.class')) {
$configuratorClassName = $this->getParameter(
$configuratorClassName = $this->container->getParameter(
'kunstmaan_user_management.user_admin_list_configurator.class'
);
}

$configurator = new $configuratorClassName($em);

/* @var AdminList $adminList */
$adminList = $this->get("kunstmaan_adminlist.factory")->createList($configurator);
$adminList = $this->container->get("kunstmaan_adminlist.factory")->createList($configurator);
$adminList->bindRequest($request);

return array(
Expand All @@ -66,7 +66,7 @@ public function listAction(Request $request)
*/
private function getUserClassInstance()
{
$userClassName = $this->getParameter('fos_user.model.user.class');
$userClassName = $this->container->getParameter('fos_user.model.user.class');

return new $userClassName();
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public function addAction(Request $request)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.users.add.flash.success.%username%', [
$this->container->get('translator')->trans('kuma_user.users.add.flash.success.%username%', [
'%username%' => $user->getUsername()
])
);
Expand Down Expand Up @@ -142,7 +142,7 @@ public function addAction(Request $request)
public function editAction(Request $request, $id)
{
// The logged in user should be able to change his own password/username/email and not for other users
if ($id == $this->get('security.token_storage')->getToken()->getUser()->getId()) {
if ($id == $this->container->get('security.token_storage')->getToken()->getUser()->getId()) {
$requiredRole = 'ROLE_ADMIN';
} else {
$requiredRole = 'ROLE_SUPER_ADMIN';
Expand All @@ -153,7 +153,7 @@ public function editAction(Request $request, $id)
$em = $this->getDoctrine()->getManager();

/** @var UserInterface $user */
$user = $em->getRepository($this->getParameter('fos_user.model.user.class'))->find($id);
$user = $em->getRepository($this->container->getParameter('fos_user.model.user.class'))->find($id);
if ($user === null) {
throw new NotFoundHttpException(sprintf('User with ID %s not found', $id));
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public function editAction(Request $request, $id)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.users.edit.flash.success.%username%', [
$this->container->get('translator')->trans('kuma_user.users.edit.flash.success.%username%', [
'%username%' => $user->getUsername()
])
);
Expand Down Expand Up @@ -237,7 +237,7 @@ public function deleteAction(Request $request, $id)
/* @var $em EntityManager */
$em = $this->getDoctrine()->getManager();
/* @var UserInterface $user */
$user = $em->getRepository($this->getParameter('fos_user.model.user.class'))->find($id);
$user = $em->getRepository($this->container->getParameter('fos_user.model.user.class'))->find($id);
if (!is_null($user)) {
$userEvent = new UserEvent($user, $request);
$this->container->get('event_dispatcher')->dispatch(UserEvents::USER_DELETE_INITIALIZE, $userEvent);
Expand All @@ -247,7 +247,7 @@ public function deleteAction(Request $request, $id)

$this->addFlash(
FlashTypes::SUCCESS,
$this->get('translator')->trans('kuma_user.users.delete.flash.success.%username%', [
$this->container->get('translator')->trans('kuma_user.users.delete.flash.success.%username%', [
'%username%' => $user->getUsername()
])
);
Expand All @@ -266,7 +266,7 @@ public function changePasswordAction()
$this->generateUrl(
'KunstmaanUserManagementBundle_settings_users_edit',
array(
'id' => $this->get('security.token_storage')->getToken()->getUser()->getId(),
'id' => $this->container->get('security.token_storage')->getToken()->getUser()->getId(),
)
)
);
Expand Down

0 comments on commit a661658

Please sign in to comment.