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

  • Application
  • ApplicationYAMLMapper
  • BoundingBox
  • Element
  • InstanceConfiguration
  • InstanceConfigurationOptions
  • MapbenderBundle
  • ProxyService
  • Size
  • SQLSearchEngine
  • StateHandler
  • Template
  • Utils

Interfaces

  • InstanceLayerIn
  • SearchEngine
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: /**
  4:  * TODO: License
  5:  */
  6: 
  7: namespace Mapbender\CoreBundle\Component;
  8: 
  9: use Mapbender\CoreBundle\Entity\Application as ApplicationEntity;
 10: use Mapbender\CoreBundle\Entity\Element;
 11: use Mapbender\CoreBundle\Component\Element as ElementComponent;
 12: use Mapbender\CoreBundle\Entity\Layerset;
 13: //use Mapbender\CoreBundle\Entity\Layer;
 14: use Symfony\Component\DependencyInjection\ContainerInterface;
 15: 
 16: /**
 17:  * YAML mapper for applications
 18:  *
 19:  * This class is responsible for mapping application definitions given in the
 20:  * YAML configuration to Application configuration entities.
 21:  *
 22:  * @author Christian Wygoda
 23:  */
 24: class ApplicationYAMLMapper
 25: {
 26: 
 27:     /**
 28:      * The service container
 29:      * @var ContainerInterface
 30:      */
 31:     private $container;
 32: 
 33:     public function __construct(ContainerInterface $container)
 34:     {
 35:         $this->container = $container;
 36:     }
 37: 
 38:     /**
 39:      * Get all YAML applications
 40:      *
 41:      * @return array
 42:      */
 43:     public function getApplications()
 44:     {
 45:         $definitions = $this->container->getParameter('applications');
 46: 
 47:         $applications = array();
 48:         foreach($definitions as $slug => $def)
 49:         {
 50:             $application = $this->getApplication($slug);
 51:             if($application !== null)
 52:             {
 53:                 $applications[] = $application;
 54:             }
 55:         }
 56: 
 57:         return $applications;
 58:     }
 59: 
 60:     /**
 61:      * Get YAML application for given slug
 62:      *
 63:      * Will return null if no YAML application for the given slug exists.
 64:      *
 65:      * @param string $slug
 66:      * @return Application
 67:      */
 68:     public function getApplication($slug)
 69:     {
 70:         $definitions = $this->container->getParameter('applications');
 71:         if(!array_key_exists($slug, $definitions))
 72:         {
 73:             return null;
 74:         }
 75:         $timestamp = round((microtime(true) * 1000));
 76:         $definition = $definitions[$slug];
 77:         if(!key_exists('title', $definition))
 78:         {
 79:             $definition['title'] = "TITLE ". $timestamp;
 80:         }
 81: 
 82:         if(!key_exists('published', $definition))
 83:         {
 84:             $definition['published'] = false;
 85:         } else 
 86:         {
 87:             $definition['published'] = (boolean) $definition['published'];
 88:         }
 89: 
 90:         // First, create an application entity
 91:         $application = new ApplicationEntity();
 92:         $application
 93:                 ->setSlug($slug)
 94:                 ->setTitle($definition['title'])
 95:                 ->setDescription($definition['description'])
 96:                 ->setTemplate($definition['template'])
 97:                 ->setPublished($definition['published']);
 98: 
 99:         if(array_key_exists('extra_assets', $definition))
100:         {
101:             $application->setExtraAssets($definition['extra_assets']);
102:         }
103: 
104:         // Then create elements
105:         foreach($definition['elements'] as $region => $elementsDefinition)
106:         {
107:             $weight = 0;
108:             if($elementsDefinition !== null)
109:             {
110:                 foreach($elementsDefinition as $id => $elementDefinition)
111:                 {
112:                     $configuration_ = $elementDefinition;
113:                     unset($configuration_['class']);
114:                     unset($configuration_['title']);
115:                     $entity_class = $elementDefinition['class'];
116:                     $appl = new \Mapbender\CoreBundle\Component\Application($this->container, $application, array());
117:                     $elComp = new $entity_class($appl, $this->container, new \Mapbender\CoreBundle\Entity\Element());
118:                     $defConfig = $elComp->getDefaultConfiguration();
119:                     $configuration = ElementComponent::mergeArrays($elComp->getDefaultConfiguration(), $configuration_, array());
120: 
121:                     $class = $elementDefinition['class'];
122:                     $title = array_key_exists('title', $elementDefinition) ?
123:                             $elementDefinition['title'] :
124:                             $class::getClassTitle();
125: 
126:                     $element = new Element();
127:                    
128:                     $element->setId($id)
129:                             ->setClass($elementDefinition['class'])
130:                             ->setTitle($title)
131:                             ->setConfiguration($configuration)
132:                             ->setRegion($region)
133:                             ->setWeight($weight++)
134:                             ->setApplication($application);
135:                     
136:                     //TODO: Roles
137:                     $application->addElements($element);
138:                 }
139:             }
140:         }
141: 
142:         $owner = $this->container->get('doctrine')
143:                 ->getRepository('FOMUserBundle:User')
144:                 ->find(1);
145:         $application->setOwner($owner);
146: 
147:         $application->yaml_roles = array();
148:         if(array_key_exists('roles', $definition)) {
149:             $application->yaml_roles = $definition['roles'];
150:         }
151:         
152:         // TODO: Add roles, entity needs work first
153:         // Create layersets and layers
154:         foreach($definition['layersets'] as $id => $layerDefinitions)
155:         {
156:             $layerset = new Layerset();
157:             $layerset
158:                     ->setId($id)
159:                     ->setTitle('YAML - ' . $id)
160:                     ->setApplication($application);
161: 
162:             $weight = 0;            
163:             foreach($layerDefinitions as $id => $layerDefinition)
164:             {
165:                 $class = $layerDefinition['class'];
166:                 unset($layerDefinition['class']);
167:                 $instance = new $class();
168:                 $instance->setId($id)
169:                         ->setTitle($layerDefinition['title'])
170:                         ->setWeight($weight++)
171:                         ->setLayerset($layerset)
172:                         ->setProxy(!isset($layerDefinition['proxy']) ? false : $layerDefinition['proxy'])
173:                         ->setVisible(!isset($layerDefinition['visible']) ? true : $layerDefinition['visible'])
174:                         ->setFormat(!isset($layerDefinition['format']) ? true : $layerDefinition['format'])
175:                         ->setInfoformat(!isset($layerDefinition['info_format']) ? null : $layerDefinition['info_format'])
176:                         ->setTransparency(!isset($layerDefinition['transparent']) ? true : $layerDefinition['transparent'])
177:                         ->setOpacity(!isset($layerDefinition['opacity']) ? 100 : $layerDefinition['opacity'])
178:                         ->setTiled(!isset($layerDefinition['tiled']) ? false : $layerDefinition['tiled'])
179:                         ->setConfiguration($layerDefinition);
180:                 $layerset->addInstance($instance);
181:             }
182:             $application->addLayerset($layerset);
183:         }
184: 
185:         $application->setSource(ApplicationEntity::SOURCE_YAML);
186: 
187:         return $application;
188:     }
189: 
190: }
191: 
192: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0