diff --git a/src/Configuration/EventManagementConfiguration.php b/src/Configuration/EventManagementConfiguration.php index a2b8b3b..b5fec43 100644 --- a/src/Configuration/EventManagementConfiguration.php +++ b/src/Configuration/EventManagementConfiguration.php @@ -47,7 +47,7 @@ public function modify(Container $container) new Subscriber\ImageEditorSubscriber($container['console_client'], $container['file_manager']), new Subscriber\PluploadSubscriber($container['plugin_relative_path'], $container['rest_namespace'], $container['assets_url'], $container['plupload_error_messages']), new Subscriber\RestApiSubscriber($container['rest_namespace'], $container['rest_endpoints']), - new Subscriber\WordPressSubscriber(), + new Subscriber\WordPressSubscriber($container['server_software']), ]; }); } diff --git a/src/Configuration/PhpConfiguration.php b/src/Configuration/PhpConfiguration.php new file mode 100644 index 0000000..b6db162 --- /dev/null +++ b/src/Configuration/PhpConfiguration.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Ymir\Plugin\Configuration; + +use Ymir\Plugin\DependencyInjection\Container; +use Ymir\Plugin\DependencyInjection\ContainerConfigurationInterface; + +/** + * Configures the dependency injection container with PHP parameters and services. + */ +class PhpConfiguration implements ContainerConfigurationInterface +{ + /** + * {@inheritdoc} + */ + public function modify(Container $container) + { + $container['server_software'] = $_SERVER['SERVER_SOFTWARE']; + } +} diff --git a/src/Plugin.php b/src/Plugin.php index 940e4a4..24036df 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -83,6 +83,7 @@ public function load() Configuration\CloudStorageConfiguration::class, Configuration\ConsoleConfiguration::class, Configuration\EventManagementConfiguration::class, + Configuration\PhpConfiguration::class, Configuration\RestApiConfiguration::class, Configuration\UploadsConfiguration::class, Configuration\WordPressConfiguration::class, diff --git a/src/Subscriber/WordPressSubscriber.php b/src/Subscriber/WordPressSubscriber.php index b81d93b..7395225 100644 --- a/src/Subscriber/WordPressSubscriber.php +++ b/src/Subscriber/WordPressSubscriber.php @@ -20,16 +20,44 @@ */ class WordPressSubscriber implements SubscriberInterface { + /** + * The server identification string received by PHP. + * + * @var string + */ + private $serverSoftware; + + /** + * Constructor. + */ + public function __construct(string $serverSoftware) + { + $this->serverSoftware = strtolower($serverSoftware); + } + /** * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ + 'got_url_rewrite' => 'enableUrlRewrite', 'sanitize_file_name_chars' => 'sanitizeFileNameCharacters', ]; } + /** + * Overwrite URL rewrite setting if we're on the Ymir runtime. + */ + public function enableUrlRewrite(bool $urlRewriteEnabled): bool + { + if ('ymir' === $this->serverSoftware) { + $urlRewriteEnabled = true; + } + + return $urlRewriteEnabled; + } + /** * Replace the list of characters that WordPress uses to sanitize file names. *