Skip to content

Commit 0d28b0a

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

File tree

11 files changed

+138
-136
lines changed

11 files changed

+138
-136
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+
}

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 & 2 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

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:

Tests/Functional/Entity/User.php

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,80 @@
1212
namespace Hackzilla\Bundle\TicketBundle\Tests\Functional\Entity;
1313

1414
use Doctrine\ORM\Mapping as ORM;
15-
use FOS\UserBundle\Model\User as BaseUser;
15+
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;
1616

1717
/**
1818
* @ORM\Entity
19-
* @ORM\Table(name="fos_user")
19+
* @ORM\Table(name="user")
2020
*
2121
* @author Javier Spagnoletti <[email protected]>
2222
*/
23-
class User extends BaseUser
23+
class User implements UserInterface
2424
{
2525
/**
26+
* @var int
27+
*
2628
* @ORM\Id
2729
* @ORM\Column(type="integer")
2830
* @ORM\GeneratedValue(strategy="AUTO")
2931
*/
30-
protected $id;
32+
private $id;
33+
34+
/**
35+
* @var string
36+
*
37+
* @ORM\Column(type="string", nullable=false)
38+
*/
39+
private $username;
40+
41+
/**
42+
* @var string
43+
*
44+
* @ORM\Column(type="string", nullable=false)
45+
*/
46+
private $email;
47+
48+
public function getId()
49+
{
50+
return $this->id;
51+
}
52+
53+
public function getUsername()
54+
{
55+
return $this->username;
56+
}
57+
58+
public function setUsername(?string $username): void
59+
{
60+
$this->username = $username;
61+
}
62+
63+
public function getEmail()
64+
{
65+
return $this->email;
66+
}
67+
68+
public function setEmail(?string $email): void
69+
{
70+
$this->email = $email;
71+
}
72+
73+
public function eraseCredentials()
74+
{
75+
}
76+
77+
public function getRoles()
78+
{
79+
return [];
80+
}
81+
82+
public function getPassword()
83+
{
84+
return '';
85+
}
86+
87+
public function getSalt()
88+
{
89+
return '';
90+
}
3191
}

Tests/Functional/TestKernel.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Hackzilla\Bundle\TicketBundle\Tests\Functional;
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
15-
use FOS\UserBundle\FOSUserBundle;
1615
use Hackzilla\Bundle\TicketBundle\HackzillaTicketBundle;
1716
use Hackzilla\Bundle\TicketBundle\Tests\Functional\Entity\User;
1817
use Knp\Bundle\PaginatorBundle\KnpPaginatorBundle;
@@ -51,7 +50,6 @@ public function registerBundles()
5150
new FrameworkBundle(),
5251
new SecurityBundle(),
5352
new DoctrineBundle(),
54-
new FOSUserBundle(),
5553
new KnpPaginatorBundle(),
5654
new TwigBundle(),
5755
new HackzillaTicketBundle(),
@@ -165,20 +163,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
165163
}
166164
$c->loadFromExtension('twig', $twigConfig);
167165

168-
// FOSUserBundle config
169-
$c->loadFromExtension('fos_user', [
170-
'user_class' => User::class,
171-
'db_driver' => 'orm',
172-
'firewall_name' => 'api',
173-
'from_email' => [
174-
'address' => '[email protected]',
175-
'sender_name' => 'HackzillaTicketBundle',
176-
],
177-
'service' => [
178-
'mailer' => 'fos_user.mailer.noop',
179-
],
180-
]);
181-
182166
// HackzillaBundle config
183167
$c->loadFromExtension('hackzilla_ticket', [
184168
'user_class' => User::class,

0 commit comments

Comments
 (0)