Skip to content

Commit b521eee

Browse files
committed
Stop suggesting "friendsofsymfony/user-bundle"
1 parent bc9450a commit b521eee

File tree

12 files changed

+138
-156
lines changed

12 files changed

+138
-156
lines changed

Command/AutoClosingCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Hackzilla\Bundle\TicketBundle\Command;
1313

14+
use Hackzilla\Bundle\TicketBundle\Entity\Ticket;
1415
use Hackzilla\Bundle\TicketBundle\Entity\TicketMessage;
1516
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1617
use Symfony\Component\Console\Input\InputArgument;
@@ -23,6 +24,8 @@
2324
*/
2425
class AutoClosingCommand extends ContainerAwareCommand
2526
{
27+
use UserManagerTrait;
28+
2629
protected static $defaultName = 'ticket:autoclosing';
2730

2831
/**
@@ -57,10 +60,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
5760
}
5861

5962
$ticketManager = $this->getContainer()->get('hackzilla_ticket.ticket_manager');
60-
$userManager = $this->getContainer()->get('fos_user.user_manager');
61-
$ticketRepository = $this->getContainer()->get('doctrine')->getRepository('HackzillaTicketBundle:Ticket');
63+
$ticketRepository = $this->getContainer()->get('doctrine')->getRepository(Ticket::class);
6264

63-
$locale = $this->getContainer()->getParameter('locale') ? $this->getContainer()->getParameter('locale') : 'en';
65+
$locale = $this->getContainer()->hasParameter('locale') ? $this->getContainer()->getParameter('locale') : 'en';
6466
$translator = $this->getContainer()->get('translator');
6567
$translator->setLocale($locale);
6668

@@ -77,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7779
)
7880
->setStatus(TicketMessage::STATUS_CLOSED)
7981
->setPriority($ticket->getPriority())
80-
->setUser($userManager->findUserByUsername($username))
82+
->setUser($this->findUser($username))
8183
->setTicket($ticket);
8284

8385
$ticket->setStatus(TicketMessage::STATUS_CLOSED);

Command/TicketManagerCommand.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class TicketManagerCommand extends ContainerAwareCommand
2525
{
26+
use UserManagerTrait;
27+
2628
protected static $defaultName = 'ticket:create';
2729

2830
/**
@@ -57,12 +59,6 @@ protected function configure()
5759
*/
5860
protected function execute(InputInterface $input, OutputInterface $output)
5961
{
60-
if (!$this->getContainer()->has('fos_user.user_manager')) {
61-
throw new \RuntimeException(sprintf('Command "%s" requires the service "fos_user.user_manager". Is "friendsofsymfony/user-bundle" installed and enabled?', $this->getName()));
62-
}
63-
64-
$userManager = $this->getContainer()->get('fos_user.user_manager');
65-
6662
$ticketManager = $this->getContainer()->get('hackzilla_ticket.ticket_manager');
6763

6864
$ticket = $ticketManager->createTicket()
@@ -72,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7268
->setMessage($input->getArgument('message'))
7369
->setStatus(TicketMessage::STATUS_OPEN)
7470
->setPriority($input->getOption('priority'))
75-
->setUser($userManager->findUserByUsername('system'));
71+
->setUser($this->findUser('system'));
7672

7773
$ticketManager->updateTicket($ticket, $message);
7874

Command/UserManagerTrait.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of HackzillaTicketBundle package.
5+
*
6+
* (c) Daniel Platt <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Hackzilla\Bundle\TicketBundle\Command;
13+
14+
use Doctrine\Persistence\ObjectRepository;
15+
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;
16+
17+
/**
18+
* NEXT_MAJOR: Inject the object repository and the user class directly in the command
19+
* classes and remove this trait.
20+
*
21+
* @author Javier Spagnoletti <[email protected]>
22+
*/
23+
trait UserManagerTrait
24+
{
25+
/**
26+
* @var ObjectRepository
27+
*/
28+
private $userRepository;
29+
30+
public function __construct(string $name = null, ?ObjectRepository $userRepository = null)
31+
{
32+
parent::__construct($name);
33+
34+
$this->userRepository = $userRepository;
35+
36+
if (null === $userRepository) {
37+
@trigger_error(sprintf(
38+
'Omitting or passing null as argument 2 for "%s()" is deprecated since hackzilla/ticket-bundle 3.x.',
39+
__METHOD__
40+
), E_USER_DEPRECATED);
41+
}
42+
}
43+
44+
private function findUser(string $username): ?UserInterface
45+
{
46+
if (null !== $this->userRepository) {
47+
return $this->userRepository->findBy(['username' => $username]);
48+
}
49+
50+
if (!$this->getContainer()->has('fos_user.user_manager')) {
51+
throw new \RuntimeException(sprintf('Command "%s" requires the service "fos_user.user_manager". Is "friendsofsymfony/user-bundle" installed and enabled?', $this->getName()));
52+
}
53+
54+
return $this->getContainer()->get('fos_user.user_manager')->findUserByUsername($username);
55+
}
56+
}

DependencyInjection/HackzillaTicketExtension.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public function load(array $configs, ContainerBuilder $container)
5050
}
5151

5252
$this->setTranslationDomain($config, $container);
53-
54-
if (isset($bundles['FOSUserBundle'])) {
55-
$this->createDoctrineCommonBackwardCompatibilityAliases();
56-
}
5753
}
5854

5955
public static function bundleDirectory()
@@ -78,19 +74,4 @@ private function setTranslationDomain(array $config, ContainerBuilder $container
7874
$definition = $container->getDefinition('hackzilla_ticket.ticket_manager');
7975
$definition->addMethodCall('setTranslationDomain', [$translationDomain]);
8076
}
81-
82-
/**
83-
* We MUST remove this method when support for "friendsofsymfony/user-bundle" is dropped
84-
* or adapted to work with "doctrine/common:^3".
85-
*/
86-
private function createDoctrineCommonBackwardCompatibilityAliases(): void
87-
{
88-
if (!interface_exists(\Doctrine\Common\Persistence\ObjectManager::class)) {
89-
class_alias(\Doctrine\Persistence\ObjectManager::class, \Doctrine\Common\Persistence\ObjectManager::class);
90-
}
91-
92-
if (!class_exists(\Doctrine\Common\Persistence\Event\LifecycleEventArgs::class)) {
93-
class_alias(\Doctrine\Persistence\Event\LifecycleEventArgs::class, \Doctrine\Common\Persistence\Event\LifecycleEventArgs::class);
94-
}
95-
}
9677
}

Model/UserInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ interface UserInterface extends \Symfony\Component\Security\Core\User\UserInterf
1515
{
1616
public function getId();
1717

18-
public function getUsername();
19-
2018
public function getEmail();
2119
}

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ You can see the full requirement definitions for each available version in [Pack
1313

1414
## Setup
1515

16-
* [Installation with FOSUserBundle](Resources/doc/setup/fosuserbundle.md)
17-
* [Generic installation](Resources/doc/setup/other.md)
16+
* [Install](Resources/doc/setup/install.md)
1817

1918
## Optional features
2019

@@ -28,7 +27,6 @@ These optional features that can be turned on or off.
2827

2928
## Optional integrations
3029

31-
* [FOSUserBundle](https://symfony.com/doc/current/bundles/FOSUserBundle/index.html)
3230
* [Bootstrap v3](http://getbootstrap.com/docs/3.3/) (see http://symfony.com/blog/new-in-symfony-2-6-bootstrap-form-theme)
3331

3432
## 3rd party extensions

Resources/config/services.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616

1717
hackzilla_ticket.user_repository:
1818
class: Doctrine\ORM\EntityRepository
19-
factory: ['@doctrine.orm.default_entity_manager', getRepository]
19+
factory: ['@doctrine.orm.entity_manager', getRepository]
2020
arguments:
2121
- '%hackzilla_ticket.model.user.class%'
2222

@@ -73,10 +73,16 @@ services:
7373

7474
hackzilla_ticket.command.autoclosing:
7575
class: Hackzilla\Bundle\TicketBundle\Command\AutoClosingCommand
76+
arguments:
77+
- null
78+
- '@hackzilla_ticket.user_repository'
7679
tags:
7780
- { name: console.command, command: 'ticket:autoclosing' }
7881

7982
hackzilla_ticket.command.create:
8083
class: Hackzilla\Bundle\TicketBundle\Command\TicketManagerCommand
84+
arguments:
85+
- null
86+
- '@hackzilla_ticket.user_repository'
8187
tags:
8288
- { name: console.command, command: 'ticket:create' }

Resources/doc/setup/fosuserbundle.md

Lines changed: 0 additions & 97 deletions
This file was deleted.

Resources/doc/setup/other.md renamed to Resources/doc/setup/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Add HackzillaTicketBundle to your requirements:
88
composer require hackzilla/ticket-bundle
99
```
1010

11-
Specify your user class in your config, if you are using FOSUserBundle, then this will be exactly the same.
11+
Specify your user class in your config.
1212

1313
```yaml
1414
hackzilla_ticket:

0 commit comments

Comments
 (0)