Skip to content

Instantly share code, notes, and snippets.

@alexwilson
Last active September 2, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexwilson/6750fee1078dbe2e9e200a9071644f1e to your computer and use it in GitHub Desktop.
Save alexwilson/6750fee1078dbe2e9e200a9071644f1e to your computer and use it in GitHub Desktop.
EzPublish Legacy Configuration Mapper
<?php
namespace EzPublish\AppBundle\EventListener;
use eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelEvent;
use eZ\Publish\Core\MVC\Legacy\LegacyEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LegacyConfigurationMapper implements EventSubscriberInterface
{
/**
* Settings to inject into the legacy stack.
*
* @var array
*/
protected $settings;
/**
* {@inheritdoc}
*
* @return array
*/
public static function getSubscribedEvents()
{
return [
LegacyEvents::PRE_BUILD_LEGACY_KERNEL => ["onBuildKernel", 128]
];
}
/**
* Maps a setting to legacy stack configuration settings.
*
* @param string $namespace A full namespace (e.g. `site.ini/RegionalSettings/Locale`)
* @param string $value Setting
*
* @return void
*/
public function addSetting($namespace, $value)
{
$this->settings[$namespace] = $value;
}
/**
* {@inheritdoc}
*
* @param PreBuildKernelEvent $e
*
* @return void
*/
public function onBuildKernel(PreBuildKernelEvent $e)
{
$e->getParameters()->set(
"injected-settings",
$this->settings+(array)$e->getParameters()->get("injected-settings")
);
}
}
services:
# Event Listeners
ezpublish.event_listeners.legacy_configuration_mapper:
class: EzPublish\AppBundle\EventListener\LegacyConfigurationMapper
tags: [{ name: kernel.event_subscriber }]
calls:
- [addSetting, ["ezjscore.ini/Packer/CustomHosts", { 0: null, ".js": @=service('request_stack').getMasterRequest().getSchemeAndHttpHost() ~ "/" } ]]
- [addSetting, ["acmecorp.ini/Settings/ContentRemoteId", %content.remote_id%]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment