Skip to content

Commit

Permalink
modified by fab-pot/php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
George Brooks committed Nov 5, 2015
1 parent 76c888f commit f84b253
Show file tree
Hide file tree
Showing 33 changed files with 240 additions and 288 deletions.
10 changes: 6 additions & 4 deletions Controller/ProfileManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace PUGX\MultiUserBundle\Controller;

use FOS\UserBundle\Controller\ProfileController;
Expand Down Expand Up @@ -30,10 +31,10 @@ class ProfileManager
protected $formFactory;

/**
* @param UserDiscriminator $userDiscriminator
* @param UserDiscriminator $userDiscriminator
* @param ContainerInterface $container
* @param ProfileController $controller
* @param FormFactory $formFactory
* @param ProfileController $controller
* @param FormFactory $formFactory
*/
public function __construct(
UserDiscriminator $userDiscriminator,
Expand All @@ -49,6 +50,7 @@ public function __construct(

/**
* @param string $class
*
* @return RedirectResponse
*/
public function edit($class, $templates = array())
Expand All @@ -67,7 +69,7 @@ public function edit($class, $templates = array())
}

$form = $this->formFactory->createForm();

return $this->container->get('templating')->renderResponse($template,
array(
'form' => $form->createView(),
Expand Down
41 changes: 18 additions & 23 deletions Controller/RegistrationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,33 @@
class RegistrationManager
{
/**
*
* @var \PUGX\MultiUserBundle\Model\UserDiscriminator
* @var \PUGX\MultiUserBundle\Model\UserDiscriminator
*/
protected $userDiscriminator;

/**
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;

/**
*
* @var \FOS\UserBundle\Controller\RegistrationController
* @var \FOS\UserBundle\Controller\RegistrationController
*/
protected $controller;

/**
*
* @var \PUGX\MultiUserBundle\Form\FormFactory
*/
protected $formFactory;

/**
*
* @param \PUGX\MultiUserBundle\Model\UserDiscriminator $userDiscriminator
* @param \PUGX\MultiUserBundle\Model\UserDiscriminator $userDiscriminator
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param \FOS\UserBundle\Controller\RegistrationController $controller
* @param \PUGX\MultiUserBundle\Form\FormFactory $formFactory
* @param \FOS\UserBundle\Controller\RegistrationController $controller
* @param \PUGX\MultiUserBundle\Form\FormFactory $formFactory
*/
public function __construct(UserDiscriminator $userDiscriminator,
ContainerInterface $container,
ContainerInterface $container,
RegistrationController $controller,
FormFactory $formFactory)
{
Expand All @@ -51,28 +46,28 @@ public function __construct(UserDiscriminator $userDiscriminator,
$this->controller = $controller;
$this->formFactory = $formFactory;
}

/**
*
* @param string $class
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function register($class, $templates = array())
{
$this->userDiscriminator->setClass($class);

$this->controller->setContainer($this->container);
$result = $this->controller->registerAction($this->container->get('request'));
$result = $this->controller->registerAction($this->container->get('request'));
if ($result instanceof RedirectResponse) {
return $result;
}

$template = $this->userDiscriminator->getTemplate('registration');
if (is_null($template)) {
$template = 'FOSUserBundle:Registration:register.html.twig';
}
$form = $this->formFactory->createForm();

$form = $this->formFactory->createForm();

return $this->container->get('templating')->renderResponse($template, array(
'form' => $form->createView(),
Expand Down
16 changes: 8 additions & 8 deletions DependencyInjection/Compiler/OverrideServiceCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class OverrideServiceCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
$this->changeService(
$container,
'fos_user.registration.form.factory',
$container,
'fos_user.registration.form.factory',
'pugx_multi_user.registration_form_factory');

$this->changeService(
$container,
'fos_user.profile.form.factory',
$container,
'fos_user.profile.form.factory',
'pugx_multi_user.profile_form_factory');

$this->changeService(
Expand All @@ -29,15 +29,15 @@ public function process(ContainerBuilder $container)
'fos_user.profile.form.type',
'pugx_multi_user.profile.form.type');
}

private function changeService($container, $serviceName, $newServiceName)
{
$service = $container->getDefinition($serviceName);
$newService = $container->getDefinition($newServiceName);

if ($service && $newService) {
$container->removeDefinition($serviceName);
$container->setDefinition($serviceName, $newService);
}
}
}
}
12 changes: 6 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('pugx_multi_user');

$supportedDrivers = array('orm');

$rootNode->
children()
->scalarNode('db_driver')
Expand All @@ -31,7 +31,7 @@ public function getConfigTreeBuilder()
->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
->end()
->end();

$rootNode->
children()
->arrayNode('users')->prototype('array')
Expand All @@ -40,7 +40,7 @@ public function getConfigTreeBuilder()
->children()
->scalarNode('class')->isRequired()->cannotBeEmpty()->end()
->scalarNode('factory')->defaultValue('PUGX\MultiUserBundle\Model\UserFactory')->end()
->end()
->end()
->end()
->end()
->children()
Expand Down Expand Up @@ -89,7 +89,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->end();

return $treeBuilder;
}
}
8 changes: 4 additions & 4 deletions DependencyInjection/PUGXMultiUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class PUGXMultiUserExtension extends Extension
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$users = $config['users'];
$container->setParameter('pugx_user_discriminator_users', $users);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$loader->load(sprintf('%s.yml', $config['db_driver']));
}
}
21 changes: 8 additions & 13 deletions Doctrine/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@
use PUGX\MultiUserBundle\Model\UserDiscriminator;

/**
* Custom user manager for FOSUserBundle
* Custom user manager for FOSUserBundle.
*
* @author leonardo proietti (leonardo.proietti@gmail.com)
* @author eux (eugenio@netmeans.net)
*/
class UserManager extends BaseUserManager
{
/**
*
* @var ObjectManager
*/
protected $om;

/**
*
* @var UserDiscriminator
*/
protected $userDiscriminator;
Expand All @@ -48,31 +46,29 @@ public function __construct(EncoderFactoryInterface $encoderFactory, Canonicaliz
}

/**
*
* {@inheritDoc}
* {@inheritdoc}
*/
public function createUser()
{
return $this->userDiscriminator->createUser();
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getClass()
{
return $this->userDiscriminator->getClass();
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function findUserBy(array $criteria)
{
$classes = $this->userDiscriminator->getClasses();

foreach ($classes as $class) {

$repo = $this->om->getRepository($class);

if (!$repo) {
Expand All @@ -88,15 +84,16 @@ public function findUserBy(array $criteria)

if ($user) {
$this->userDiscriminator->setClass($class);

return $user;
}
}

return null;
return;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function findUsers()
{
Expand All @@ -116,16 +113,14 @@ public function findUsers()
return $usersAll;
}


/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function findConflictualUsers($value, array $fields)
{
$classes = $this->userDiscriminator->getClasses();

foreach ($classes as $class) {

$repo = $this->om->getRepository($class);

$users = $repo->findBy($this->getCriteria($value, $fields));
Expand Down
Loading

0 comments on commit f84b253

Please sign in to comment.