Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • DrupalIntegrationBundle
      • DependencyInjection
      • Security
        • Authentication
          • Provider
          • Token
        • Authorization
          • Voter
        • Factory
        • Firewall
        • User
      • Session
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • EventListener
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • ElementIdTransformer
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
 1: <?php
 2: namespace Mapbender\CoreBundle\Form\DataTransformer;
 3: 
 4: use Symfony\Component\Form\DataTransformerInterface;
 5: use Symfony\Component\Form\Exception\TransformationFailedException;
 6: use Doctrine\Common\Persistence\ObjectManager;
 7: use Mapbender\CoreBundle\Entity\Element;
 8: 
 9: /**
10:  * 
11:  */
12: class ElementIdTransformer implements DataTransformerInterface
13: {
14:     /**
15:      * @var ObjectManager
16:      */
17:     private $om;
18: 
19:     /**
20:      * @param ObjectManager $om
21:      */
22:     public function __construct(ObjectManager $om)
23:     {
24:         $this->om = $om;
25:     }
26: 
27:     /**
28:      * Transforms an object (element) to a string (id).
29:      *
30:      * @param  Element|null $element
31:      * @return string
32:      */
33:         public function transform($id)
34:     {
35:         if (!$id) {
36:             return null;
37:         }
38: 
39:         $element = $this->om
40:             ->getRepository('MapbenderCoreBundle:Element')
41:             ->findOneBy(array('id' => $id))
42:         ;
43: 
44:         if (null === $element) {
45:             throw new TransformationFailedException(sprintf(
46:                 'An element with id "%s" does not exist!',
47:                 $id
48:             ));
49:         }
50: 
51:         return $element;
52:     }
53: 
54:     /**
55:      * Transforms a string (id) to an object (element).
56:      *
57:      * @param  string $id
58:      * @return Element|null
59:      * @throws TransformationFailedException if object (element) is not found.
60:      */
61:     public function reverseTransform($element)
62:     {
63:         if (null === $element) {
64:             return "";
65:         }
66:         return (string) $element->getId();
67:     }
68: }
69: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0