8
0
Fork 0

Commits vergleichen

...

4 Commits

9 geänderte Dateien mit 78 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -3,11 +3,11 @@
# Dependency Injection Container handler for OXID eShop # Dependency Injection Container handler for OXID eShop
Enables the simple use of a class container outside of the OXID DI Services. Enables the simple use of a class container outside the OXID DI Services.
## Install ## Install
This package requires an Composer installed OXID eShop as defined in [composer.json](composer.json). This package requires a Composer installed OXID eShop as defined in [composer.json](composer.json).
Open a command line interface and navigate to the shop root directory (parent of source and vendor). Execute the following command. Adapt the paths to your environment. Open a command line interface and navigate to the shop root directory (parent of source and vendor). Execute the following command. Adapt the paths to your environment.
@ -31,7 +31,7 @@ Then empty the TMP folder.
## Changelog ## Changelog
See [CHANGELOG](CHANGELOG.md) for further informations. See [CHANGELOG](CHANGELOG.md) for further information.
## Contributing ## Contributing

Datei anzeigen

@ -13,11 +13,12 @@
declare(strict_types=1); declare(strict_types=1);
use D3\DIContainerHandler\d3DicException;
use D3\DIContainerHandler\d3DicHandler; use D3\DIContainerHandler\d3DicHandler;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
/** /**
* @throws Exception * @throws d3DicException
*/ */
function d3GetOxidDIC(): Container function d3GetOxidDIC(): Container
{ {

Datei anzeigen

@ -47,6 +47,7 @@
"phpstan-report": "./vendor/bin/phpstan --configuration=vendor/d3/ordermanager/phpstan.neon analyse --error-format=json > vendor/d3/ordermanager/tests/phpstan.report.json", "phpstan-report": "./vendor/bin/phpstan --configuration=vendor/d3/ordermanager/phpstan.neon analyse --error-format=json > vendor/d3/ordermanager/tests/phpstan.report.json",
"phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/", "phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/",
"phpunit-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --bootstrap=source/bootstrap.php --config=vendor/d3/oxid-dic-handler/tests/ --coverage-html=vendor/d3/oxid-dic-handler/tests/result/coverage",
"rector": "./vendor/bin/rector process --dry-run --config ./vendor/d3/oxid-dic-handler/rector.php" "rector": "./vendor/bin/rector process --dry-run --config ./vendor/d3/oxid-dic-handler/rector.php"
} }

26
d3DicException.php Normale Datei
Datei anzeigen

@ -0,0 +1,26 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\DIContainerHandler;
use Exception;
class d3DicException extends Exception
{
public function __construct(Exception $previous)
{
parent::__construct($previous->getMessage(), $previous->getCode(), $previous);
}
}

Datei anzeigen

@ -36,22 +36,25 @@ class d3DicHandler implements d3DicHandlerInterface
/** /**
* get instance * get instance
* * @throws d3DicException
* @throws Exception
*/ */
public static function getInstance(): Container public static function getInstance(): Container
{ {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); try {
$caller = $trace[1]; $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$functionName = $caller['function']; $caller = $trace[1];
$functionName = $caller['function'];
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) { if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference"); throw oxNew(Exception::class, 'method ' . $functionName . " can't use DIC due the danger of circular reference");
} }
if (null == self::$_instance) { if (null == self::$_instance) {
$oDicHandler = oxNew(d3DicHandler::class); $oDicHandler = oxNew(d3DicHandler::class);
self::$_instance = $oDicHandler->buildContainer(); self::$_instance = $oDicHandler->buildContainer();
}
} catch (Exception $exception) {
throw new d3DicException($exception);
} }
return self::$_instance; return self::$_instance;
@ -59,22 +62,25 @@ class d3DicHandler implements d3DicHandlerInterface
/** /**
* get instance * get instance
* * @throws d3DicException
* @throws Exception
*/ */
public static function getUncompiledInstance(): Container public static function getUncompiledInstance(): Container
{ {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); try {
$caller = $trace[1]; $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$functionName = $caller['function']; $caller = $trace[1];
$functionName = $caller['function'];
if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) { if (in_array(strtolower($functionName), array_map('strtolower', self::$circularReferenceMethodNames))) {
throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference"); throw oxNew(Exception::class, 'method '.$functionName." can't use DIC due the danger of circular reference");
}
$oDicHandler = oxNew(d3DicHandler::class);
self::$_instance = $oDicHandler->buildContainer(false);
} catch (Exception $exception) {
throw new d3DicException($exception);
} }
$oDicHandler = oxNew(d3DicHandler::class);
self::$_instance = $oDicHandler->buildContainer(false);
return self::$_instance; return self::$_instance;
} }
@ -142,17 +148,11 @@ class d3DicHandler implements d3DicHandlerInterface
*/ */
public function buildContainer(bool $compileAndDump = true): Container public function buildContainer(bool $compileAndDump = true): Container
{ {
if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) { if (Registry::get(ConfigFile::class)->getVar('iDebug')) {
startProfile(__METHOD__); startProfile(__METHOD__);
} }
$config = $this->d3GetConfig(); if ($this->d3UseCachedContainer()) {
if ($config->isProductiveMode()
&& ! $config->getConfigParam('iDebug')
&& $this->isNotInTest()
&& $this->cacheFileExists()
) {
$container = $this->d3GetCacheContainer(); $container = $this->d3GetCacheContainer();
} else { } else {
$container = $this->getContainerBuilder(); $container = $this->getContainerBuilder();
@ -168,29 +168,35 @@ class d3DicHandler implements d3DicHandlerInterface
} }
} }
if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) { if (Registry::get(ConfigFile::class)->getVar('iDebug')) {
stopProfile(__METHOD__); stopProfile(__METHOD__);
} }
return $container; return $container;
} }
protected function d3UseCachedContainer(): bool
{
$config = $this->d3GetConfig();
return $config->isProductiveMode()
&& !$config->getConfigParam('iDebug')
&& $this->isNotInTest()
&& $this->cacheFileExists();
}
public function getContainerBuilder(): ContainerBuilder public function getContainerBuilder(): ContainerBuilder
{ {
return oxNew(ContainerBuilder::class); return oxNew(ContainerBuilder::class);
} }
/**
* clone
*/
public function __clone() public function __clone()
{ {
/** keep clear */
} }
/**
* constructor
*/
public function __construct() public function __construct()
{ {
/** keep clear */
} }
} }

Datei anzeigen

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\DIContainerHandler; namespace D3\DIContainerHandler;
use Assert\Assert; use Assert\Assert;
use Assert\InvalidArgumentException;
class definitionFileContainer class definitionFileContainer
{ {
@ -32,6 +31,7 @@ class definitionFileContainer
public function __construct() public function __construct()
{ {
/** keep clear */
} }
public function addDefinitions(string $definitionFile, string $type): void public function addDefinitions(string $definitionFile, string $type): void

Datei anzeigen

@ -2,27 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
use Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector;
use Rector\Config\RectorConfig; use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Php80\Rector\FunctionLike\MixedTypeRector; use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList; use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromStrictScalarReturnsRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector;
use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector;
return static function (RectorConfig $rectorConfig): void { return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([ $rectorConfig->paths([

Datei anzeigen

@ -30,6 +30,8 @@ class functions_oxDICTest extends TestCase
*/ */
public function d3GetOxidDICTest(): void public function d3GetOxidDICTest(): void
{ {
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$this->assertInstanceOf( $this->assertInstanceOf(
ContainerBuilder::class, ContainerBuilder::class,
d3GetOxidDIC() d3GetOxidDIC()

Datei anzeigen

@ -35,7 +35,7 @@ class d3DicUtilitiesTest extends TestCase
* @covers \D3\DIContainerHandler\d3DicUtilities::getServiceId * @covers \D3\DIContainerHandler\d3DicUtilities::getServiceId
* @dataProvider getServiceIdTestDataProvider * @dataProvider getServiceIdTestDataProvider
*/ */
public function getServiceIdTest(string $className, string $additional = null, string $expected): void public function getServiceIdTest(string $className, ?string $additional, string $expected): void
{ {
$sut = oxNew(d3DicUtilities::class); $sut = oxNew(d3DicUtilities::class);