Skip to content

Commit

Permalink
Merge pull request #923 from oat-sa/release-15.5.0
Browse files Browse the repository at this point in the history
Release 15.5.0
  • Loading branch information
gabrielfs7 authored Sep 28, 2021
2 parents cf6a240 + d080e0b commit 9514d9b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 311 deletions.
73 changes: 57 additions & 16 deletions core/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
use Psr\Container\ContainerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException as SymfonyServiceNotFoundException;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use oat\oatbox\service\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Reference;

class ContainerBuilder extends SymfonyContainerBuilder
{
Expand All @@ -38,20 +43,15 @@ class ContainerBuilder extends SymfonyContainerBuilder
/** @var bool|null */
private $cachePath;

/** @var string|null */
private $configPath;

/** @var ContainerInterface */
private $legacyContainer;

public function __construct(
string $configPath,
string $cachePath,
ContainerInterface $legacyContainer,
bool $isDebugEnabled = null,
ContainerCache $cache = null
) {
$this->configPath = $configPath;
$this->cachePath = $cachePath;
$this->legacyContainer = $legacyContainer;
$this->cache = $cache ?? new ContainerCache(
Expand Down Expand Up @@ -97,19 +97,60 @@ public function forceBuild(): ContainerInterface
);
$phpLoader->load('services.php');

$legacyLoader = new LegacyFileLoader(
$this,
new FileLocator(
[
$this->configPath
]
)
);
$legacyLoader->load('*/*.conf.php');

return $this->cache->forceLoad();
}

/**
* @inheritDoc
*/
public function get(string $id, int $invalidBehavior = SymfonyContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
{
try {
return parent::get($id, $invalidBehavior);
} catch (SymfonyServiceNotFoundException $exception) {
}

try {
return $this->legacyContainer->get($id);
} catch (ServiceNotFoundException $exception) {
throw new SymfonyServiceNotFoundException($id);
}
}

/**
* @inheritDoc
*/
public function has(string $id)
{
if (parent::has($id)) {
return true;
}

try {
$this->legacyContainer->get($id);

return true;
} catch (ServiceNotFoundException $exception) {
return false;
}
}

/**
* @inheritDoc
*/
public function findDefinition(string $id)
{
try {
return parent::findDefinition($id);
} catch (SymfonyServiceNotFoundException $exception) {
return (new Definition($id))
->setAutowired(true)
->setPublic(true)
->setFactory(new Reference(LegacyServiceGateway::class))
->setArguments([$id]);
}
}

private function getTemporaryServiceFileContent(): string
{
$contents = [];
Expand All @@ -127,7 +168,7 @@ private function getTemporaryServiceFileContent(): string
return function (ContainerConfigurator $configurator): void
{
%s
' . str_repeat('%s' . PHP_EOL, count($contents)) . '
};',
$contents
);
Expand Down
2 changes: 1 addition & 1 deletion core/DependencyInjection/ContainerCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(

public function isFresh(): bool
{
return !$this->isEnvVarTrue('DI_CONTAINER_FORCE_BUILD') && $this->configCache->isFresh();
return $this->configCache->isFresh();
}

public function load(): ContainerInterface
Expand Down
12 changes: 1 addition & 11 deletions core/DependencyInjection/ContainerStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,22 @@ final class ContainerStarter
/** @var ContainerInterface */
private $legacyContainer;

/** @var string|null */
private $configPath;

/** @var string|null */
private $cachePath;

public function __construct(
ContainerInterface $legacyContainer,
string $configPath = null,
string $cachePath = null
) {
if (!$configPath) {
$configPath = defined('CONFIG_PATH') ? CONFIG_PATH : null;
}

if (!$cachePath) {
$cachePath = defined('GENERIS_CACHE_PATH') ? GENERIS_CACHE_PATH : null;
}

if (!$configPath || !$cachePath) {
if (!$cachePath) {
throw new LogicException('Required application constants were not initialized!');
}

$this->legacyContainer = $legacyContainer;
$this->configPath = $configPath;
$this->cachePath = $cachePath;
}

Expand All @@ -77,7 +68,6 @@ public function getContainerBuilder(): ContainerBuilder
{
if (!$this->containerBuilder) {
$this->containerBuilder = new ContainerBuilder(
$this->configPath,
$this->cachePath,
$this->legacyContainer
);
Expand Down
171 changes: 0 additions & 171 deletions core/DependencyInjection/LegacyFileLoader.php

This file was deleted.

19 changes: 10 additions & 9 deletions core/DependencyInjection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ class MyContainerServiceProvider implements ContainerServiceProviderInterface

$parameters->set('someParam', 'someValue');

$services->set(MyService::class, MyService::class)->args(
[
service(MyOtherService::class),
service(MyLegacyService::SERVICE_ID),
env('MY_ENV_VAR'),
param('someParam'),
]
);
$services->set(MyService::class, MyService::class)
->public()
->args(
[
service(MyOtherService::class),
service(MyLegacyService::SERVICE_ID),
env('MY_ENV_VAR'),
param('someParam'),
]
);
}
}
```
Expand Down Expand Up @@ -167,7 +169,6 @@ To avoid container caching (useful on dev mode), please add the following variab

```shell
DI_CONTAINER_DEBUG=true
DI_CONTAINER_FORCE_BUILD=true
```

## Testing container inside Legacy Services (ConfigurableService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function setUp(): void
$this->tempDir = sys_get_temp_dir();
$this->cache = $this->createMock(ContainerCache::class);
$this->subject = new ContainerBuilder(
$this->tempDir,
$this->tempDir,
$legacyContainer,
true,
Expand Down
Loading

0 comments on commit 9514d9b

Please sign in to comment.