/** * Collect all libraries. * * @param EncodeValueEvent $event The subscribed event. * * @return void */ public function collect(EncodeValueEvent $event) { $value = $event->getValue(); if ($value instanceof Definition) { foreach ($value->getRequiredLibraries() as $library) { if (isset($this->libraries[$library])) { continue; } if (isset($this->stylesheets[$library])) { foreach ($this->stylesheets[$library] as $asset) { $this->assets->addStylesheet($asset[0], $asset[1]); } } if (isset($this->javascripts[$library])) { foreach ($this->javascripts[$library] as $asset) { $this->assets->addJavascript($asset[0], $asset[1]); } } $this->libraries[$library] = true; } } }
/** * Build map as a javascript resource. * * It always return the generated map no matter if an assets object is given or not. If you want to get the * combined generated assets, just use $assets->getHtml(). * * @param Map $map The map being created. * @param Assets $assets Optional pass an assets instance which collects all required assets. * * @return string */ public function build(Map $map, Assets $assets = null) { $prefix = 'var map, layers = {}, controls = {}, icons = {};' . "\n"; if (!$assets) { return $prefix . $this->javascriptBuilder->encode($map, $this->jsonEncodeFlags); } $collector = new Collector($assets, $this->javascripts, $this->stylesheets); $this->eventDispatcher->addSubscriber($collector); $assets->setMap($prefix . $this->javascriptBuilder->encode($map, $this->jsonEncodeFlags)); $this->eventDispatcher->removeSubscriber($collector); return $assets->getMap(); }