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

  • Mapbender
  • MapbenderCoreBundle
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: /**
  4:  * TODO: License
  5:  */
  6: 
  7: namespace Mapbender\CoreBundle;
  8: 
  9: use Mapbender\CoreBundle\Component\Application;
 10: use Mapbender\CoreBundle\Component\ApplicationYAMLMapper;
 11: use Mapbender\CoreBundle\Entity\Application as Entity;
 12: use Symfony\Component\DependencyInjection\ContainerInterface;
 13: 
 14: /**
 15:  * Mapbender - The central Mapbender3 service. Provides metadata about
 16:  * available elements, layers and templates.
 17:  *
 18:  * @author Christian Wygoda
 19:  */
 20: class Mapbender {
 21:     private $container;
 22:     private $elements = array();
 23:     private $layers = array();
 24:     private $templates = array();
 25:     private $repositoryManagers = array();
 26: 
 27:     /**
 28:      * Mapbender constructor.
 29:      *
 30:      * Iterate over all bundles and if is an MapbenderBundle, get list
 31:      * of elements, layers and templates.
 32:      *
 33:      * @param ContainerInterface $container
 34:      */
 35:     public function __construct(ContainerInterface $container) {
 36:         $this->container = $container;
 37:         $bundles = $container->get('kernel')->getBundles();
 38:         foreach($bundles as $bundle) {
 39:             if(is_subclass_of($bundle,
 40:                 'Mapbender\CoreBundle\Component\MapbenderBundle')) {
 41: 
 42:                 $this->elements = array_merge($this->elements,
 43:                     $bundle->getElements());
 44:                 $this->layer =  array_merge($this->layers,
 45:                     $bundle->getLayers());
 46:                 $this->templates = array_merge($this->templates,
 47:                     $bundle->getTemplates());
 48:                 $this->repositoryManagers = array_merge($this->repositoryManagers,
 49:                     $bundle->getRepositoryManagers());
 50:             }
 51:         }
 52:     }
 53: 
 54:     /**
 55:      * Get list of all declared element classes.
 56:      *
 57:      * Element classes need to be declared in each bundle's main class getElement
 58:      * method.
 59:      *
 60:      * @return array
 61:      */
 62:     public function getElements() {
 63:         return $this->elements;
 64:     }
 65: 
 66:     /**
 67:      * Get list of all declared source factories.
 68:      *
 69:      * @return array
 70:      */
 71:     public function getRepositoryManagers()
 72:     {
 73:         return $this->repositoryManagers;
 74:     }
 75: 
 76:     /**
 77:      * Get list of all declared layer classes.
 78:      *
 79:      * Layer classes need to be declared in each bundle's main class getLayers
 80:      * method.
 81:      *
 82:      * @return array
 83:      */
 84:     public function getLayers() {
 85:         return $this->layers;
 86:     }
 87: 
 88:     /**
 89:      * Get list of all declared template classes.
 90:      *
 91:      * Template classes need to be declared in each bundle's main class
 92:      * getTemplates method.
 93:      *
 94:      * @return array
 95:      */
 96:     public function getTemplates() {
 97:         return $this->templates;
 98:     }
 99: 
100:     /**
101:      * Get the application for the given slug.
102:      *
103:      * Returns either application if it exists, null otherwise. If two
104:      * applications with the same slug exist, the database one will
105:      * override the YAML one.
106:      *
107:      * @return Application
108:      */
109:     public function getApplication($slug, $urls) {
110:         $entity = $this->getApplicationEntity($slug);
111:         if(!$entity) {
112:             return null;
113:         }
114: 
115:         return new Application($this->container, $entity, $urls);
116:     }
117: 
118:     /**
119:      * Get application entities
120:      *
121:      * @return array
122:      */
123:     public function getApplicationEntities() {
124:         $entities = array();
125: 
126:         $yamlMapper = new ApplicationYAMLMapper($this->container);
127:         $yamlEntities = $yamlMapper->getApplications();
128:         foreach($yamlEntities as $entity) {
129:             if(!$entity->isPublished()) {
130:                 continue;
131:             }
132:             $entities[$entity->getSlug()] = $entity;
133:         }
134: 
135:         $dbEntities = $this->container->get('doctrine')
136:             ->getRepository('MapbenderCoreBundle:Application')
137:             ->findAll();
138:         foreach($dbEntities as $entity) {
139:             $entity->setSource(Entity::SOURCE_DB);
140:             $entities[$entity->getSlug()] = $entity;
141:         }
142: 
143:         return $entities;
144:     }
145: 
146:     /**
147:      * Get application entity for given slug
148:      *
149:      * @return Entity
150:      */
151:     public function getApplicationEntity($slug) {
152:         $entity = $this->container->get('doctrine')
153:             ->getRepository('MapbenderCoreBundle:Application')
154:             ->findOneBySlug($slug);
155:         if($entity) {
156:             $entity->setSource(Entity::SOURCE_DB);
157:             return $entity;
158:         }
159: 
160:         $yamlMapper = new ApplicationYAMLMapper($this->container);
161:         $entity = $yamlMapper->getApplication($slug);
162:         if(!$entity->isPublished()) {
163:             return;
164:         }
165:         return $entity;
166:     }
167: 
168:     /**
169:      * @inheritdoc
170:      */
171:     public static function getFormTemplate()
172:     {
173:         return 'MapbenderManagerBundle:Element:map.html.twig';
174:     }
175: }
176: 
177: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0