Skip to content

Stop suggesting "friendsofsymfony/user-bundle" #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Command/AutoClosingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Hackzilla\Bundle\TicketBundle\Command;

use Hackzilla\Bundle\TicketBundle\Entity\Ticket;
use Hackzilla\Bundle\TicketBundle\Entity\TicketMessage;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -23,6 +24,8 @@
*/
class AutoClosingCommand extends ContainerAwareCommand
{
use UserManagerTrait;

protected static $defaultName = 'ticket:autoclosing';

/**
Expand Down Expand Up @@ -57,10 +60,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

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

$locale = $this->getContainer()->getParameter('locale') ? $this->getContainer()->getParameter('locale') : 'en';
$locale = $this->getContainer()->hasParameter('locale') ? $this->getContainer()->getParameter('locale') : 'en';
$translator = $this->getContainer()->get('translator');
$translator->setLocale($locale);

Expand All @@ -77,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
->setStatus(TicketMessage::STATUS_CLOSED)
->setPriority($ticket->getPriority())
->setUser($userManager->findUserByUsername($username))
->setUser($this->findUser($username))
->setTicket($ticket);

$ticket->setStatus(TicketMessage::STATUS_CLOSED);
Expand Down
10 changes: 3 additions & 7 deletions Command/TicketManagerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
class TicketManagerCommand extends ContainerAwareCommand
{
use UserManagerTrait;

protected static $defaultName = 'ticket:create';

/**
Expand Down Expand Up @@ -57,12 +59,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->getContainer()->has('fos_user.user_manager')) {
throw new \RuntimeException(sprintf('Command "%s" requires the service "fos_user.user_manager". Is "friendsofsymfony/user-bundle" installed and enabled?', $this->getName()));
}

$userManager = $this->getContainer()->get('fos_user.user_manager');

$ticketManager = $this->getContainer()->get('hackzilla_ticket.ticket_manager');

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

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

Expand Down
56 changes: 56 additions & 0 deletions Command/UserManagerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hackzilla\Bundle\TicketBundle\Command;

use Doctrine\Persistence\ObjectRepository;
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;

/**
* NEXT_MAJOR: Inject the object repository and the user class directly in the command
* classes and remove this trait.
*
* @author Javier Spagnoletti <phansys@gmail.com>
*/
trait UserManagerTrait
{
/**
* @var ObjectRepository
*/
private $userRepository;

public function __construct(string $name = null, ?ObjectRepository $userRepository = null)
{
parent::__construct($name);

$this->userRepository = $userRepository;

if (null === $userRepository) {
@trigger_error(sprintf(
'Omitting or passing null as argument 2 for "%s()" is deprecated since hackzilla/ticket-bundle 3.x.',
__METHOD__
), E_USER_DEPRECATED);
}
}

private function findUser(string $username): ?UserInterface
{
if (null !== $this->userRepository) {
return $this->userRepository->findBy(['username' => $username]);
}

if (!$this->getContainer()->has('fos_user.user_manager')) {
throw new \RuntimeException(sprintf('Command "%s" requires the service "fos_user.user_manager". Is "friendsofsymfony/user-bundle" installed and enabled?', $this->getName()));
}

return $this->getContainer()->get('fos_user.user_manager')->findUserByUsername($username);
}
}
19 changes: 0 additions & 19 deletions DependencyInjection/HackzillaTicketExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public function load(array $configs, ContainerBuilder $container)
}

$this->setTranslationDomain($config, $container);

if (isset($bundles['FOSUserBundle'])) {
$this->createDoctrineCommonBackwardCompatibilityAliases();
}
}

public static function bundleDirectory()
Expand All @@ -78,19 +74,4 @@ private function setTranslationDomain(array $config, ContainerBuilder $container
$definition = $container->getDefinition('hackzilla_ticket.ticket_manager');
$definition->addMethodCall('setTranslationDomain', [$translationDomain]);
}

/**
* We MUST remove this method when support for "friendsofsymfony/user-bundle" is dropped
* or adapted to work with "doctrine/common:^3".
*/
private function createDoctrineCommonBackwardCompatibilityAliases(): void
{
if (!interface_exists(\Doctrine\Common\Persistence\ObjectManager::class)) {
class_alias(\Doctrine\Persistence\ObjectManager::class, \Doctrine\Common\Persistence\ObjectManager::class);
}

if (!class_exists(\Doctrine\Common\Persistence\Event\LifecycleEventArgs::class)) {
class_alias(\Doctrine\Persistence\Event\LifecycleEventArgs::class, \Doctrine\Common\Persistence\Event\LifecycleEventArgs::class);
}
}
}
2 changes: 0 additions & 2 deletions Model/UserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ interface UserInterface extends \Symfony\Component\Security\Core\User\UserInterf
{
public function getId();

public function getUsername();

public function getEmail();
}
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ You can see the full requirement definitions for each available version in [Pack

## Setup

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

## Optional features

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

## Optional integrations

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

## 3rd party extensions
Expand Down
8 changes: 7 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:

hackzilla_ticket.user_repository:
class: Doctrine\ORM\EntityRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
factory: ['@doctrine.orm.entity_manager', getRepository]
arguments:
- '%hackzilla_ticket.model.user.class%'

Expand Down Expand Up @@ -73,10 +73,16 @@ services:

hackzilla_ticket.command.autoclosing:
class: Hackzilla\Bundle\TicketBundle\Command\AutoClosingCommand
arguments:
- null
- '@hackzilla_ticket.user_repository'
tags:
- { name: console.command, command: 'ticket:autoclosing' }

hackzilla_ticket.command.create:
class: Hackzilla\Bundle\TicketBundle\Command\TicketManagerCommand
arguments:
- null
- '@hackzilla_ticket.user_repository'
tags:
- { name: console.command, command: 'ticket:create' }
97 changes: 0 additions & 97 deletions Resources/doc/setup/fosuserbundle.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add HackzillaTicketBundle to your requirements:
composer require hackzilla/ticket-bundle
```

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

```yaml
hackzilla_ticket:
Expand Down
Loading