Skip to content

Commit

Permalink
fix: overwrite url rewrite setting when on lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed May 2, 2020
1 parent c91786a commit 35dc893
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Configuration/EventManagementConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
];
});
}
Expand Down
31 changes: 31 additions & 0 deletions src/Configuration/PhpConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* This file is part of Ymir WordPress plugin.
*
* (c) Carl Alexander <support@ymirapp.com>
*
* 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'];
}
}
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions src/Subscriber/WordPressSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 35dc893

Please sign in to comment.