так ли действительно нужно быть независимым от контейнера?
так ли действительно нужно быть независимым от контейнера?
manyToMany:
rubrics:
targetEntity: Rubric
mappedBy: companies
targetEntity: Company
inversedBy: rubrics
joinColumns:
name: rubric_id
referencedColumnName: id
inverseJoinColumns:
name: company_id
referencedColumnName: id
class ChoicesCollectionToArrayTransformer implements DataTransformerInterface
{
private $choiceList;
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
}
public function transform($collection)
{
if (null === $collection) {
return array();
}
if (is_array($collection)) {
return $collection;
}
if (!$collection instanceof Collection) {
throw new TransformationFailedException('Expected a Doctrine\Common\Collections\Collection object.');
}
return $this->choiceList->getValuesForChoices($collection->toArray());
}
public function reverseTransform($array)
{
if ('' === $array || null === $array) {
$array = array();
} else {
$array = (array) $array;
}
$choices = $this->choiceList->getChoicesForValues($array);
if (count($choices) !== count($array)) {
throw new TransformationFailedException('Could not find all matching choices for the given values');
}
return new ArrayCollection($choices);
}
}
$skillsChoiceList = new ObjectChoiceList(
$this->skillManager->getAllSkills()->toArray(),
'name',
array(),
null,
'alias'
);
$builder ->add('skills', 'choice', array(
'choice_list' => $skillsChoiceList,
'multiple' => true
));
$builder->get('skills')->resetViewTransformers()->addViewTransformer(new ChoicesCollectionToArrayTransformer($skillsChoiceList));
<?php
namespace Retouch\AppBundle\Tests;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\DependencyInjection\Container;
/**
* Class FixturesLoader
*/
class FixturesLoader
{
/**
* @var Application
*/
protected $console;
/**
* @var Container
*/
protected $container;
/**
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
$this->console = new Application($this->container->get('kernel'));
$this->console->setAutoExit(false);
}
/**
* @param array $fixtures
*/
public function loadFixture(array $fixtures = array())
{
$this->runConsole('doctrine:schema:drop --force');
$this->runConsole('doctrine:schema:create');
$loader = new ContainerAwareLoader($this->container);
foreach($fixtures as $fixture){
if($fixture instanceof FixtureInterface){
$loader->addFixture($fixture);
}
}
$fixtures = $loader->getFixtures();
if(!$fixtures){
return;
}
$doctrine = $this->container->get('doctrine');
$em = $doctrine->getManager();
$purger = new ORMPurger($em);
$purger->setPurgeMode(ORMPurger::PURGE_MODE_DELETE);
$executor = new ORMExecutor($em, $purger);
$executor->execute($fixtures, false);
}
/**
* @param $command
* @return int
* @throws \Exception
*/
protected function runConsole($command)
{
$command .= ' --env=test --quiet';
$input = new StringInput($command);
return $this->console->run($input);
}
}
"require": {
"isolutions/storage-bundle" : "dev-develop"
}
"require": {
"storage-bundle" : "dev-develop"
}
"name" : "storage-bundle"
class SecurityUserChecker extends UserChecker
{
/**
* Checks the user account before authentication.
*
* @param UserInterface $user a UserInterface instance
*/
public function checkPreAuth(UserInterface $user) {
parent::checkPreAuth($user);
if(!$user instanceof CustomUserInterface){
return;
}
if($user->isDeleted()){
$ex = new DeletedException('User account is deleted.');
$ex->setUser($user);
throw $ex;
}
}
}
security.user_checker:
class: UserBundle\Security\SecurityUserChecker
interface CustomUserInterface extends AdvancedUserInterface
{
/**
* @return boolean
*/
public function isDeleted();
}