All pastes #2109629 Raw Edit

Untitled

public php v1 · immutable
#2109629 ·published 2012-02-04 10:57 UTC
rendered paste body
<?phpnamespace Politistream\CoreBundle\Form\DataTransformer;use Symfony\Component\Form\Exception\TransformationFailedException;use Symfony\Component\Form\DataTransformerInterface;use Politistream\CoreBundle\Component\Profile\ProfileComponentFactory;use Doctrine\ORM\PersistentCollection;use Doctrine\Common\Collections\ArrayCollection;class ComponentTransformer implements DataTransformerInterface{  /**   *   * @var ProfileComponentFactory $componentFactory   */  protected $componentFactory;  protected $em;  public function __construct(ProfileComponentFactory $componentFactory, $container, $parent)  {    $this->componentFactory = $componentFactory;    $this->em = $container->get('doctrine')->getEntityManager();    $this->parent = $parent;  }  public function reverseTransform($value)  {    if (null === $value)    {      return '';    }    $return = new ArrayCollection();    $repo = $em->getRepository('Politistream\CoreBundle\Entity\ComponentConfiguration');    foreach ($value as $component)    {      foreach ($component as $field)      {        if ($this->parent)        {          $config = $repo->findByComponentAndField($this->parent, $component, $field);        }        else        {          $config = new \Politistream\CoreBundle\Entity\ComponentConfiguration();          $config->setField($field);          $config->setComponent($component);        }        $return->add($config);      }    }    echo 'reverse';    var_dump($return);    die();        return $return;  }  public function transform($value)  {    if (!$value || $value->count() == 0)    {      return null;    }    echo 'transform';    var_dump($value);    die();  }}