8
0
Fork 0

throw d3DicException in case of errors

Dieser Commit ist enthalten in:
Daniel Seifert 2024-02-17 22:33:41 +01:00
Ursprung 943adfaa5e
Commit afdb6ff4c1
Signiert von: DanielS
GPG-Schlüssel-ID: 6A513E13AEE66170
3 geänderte Dateien mit 67 neuen und 24 gelöschten Zeilen

Datei anzeigen

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

29
d3DicException.php Normale Datei
Datei anzeigen

@ -0,0 +1,29 @@
<?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
{
/**
* @param Exception $previous
*/
public function __construct(Exception $previous)
{
parent::__construct($previous->getMessage(), $previous->getCode(), $previous);
}
}

Datei anzeigen

@ -36,11 +36,12 @@ class d3DicHandler implements d3DicHandlerInterface
/**
* get instance
*
* @throws Exception
* @return Container
* @throws d3DicException
*/
public static function getInstance(): Container
{
try {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$caller = $trace[1];
$functionName = $caller['function'];
@ -53,17 +54,21 @@ class d3DicHandler implements d3DicHandlerInterface
$oDicHandler = oxNew(d3DicHandler::class);
self::$_instance = $oDicHandler->buildContainer();
}
} catch (Exception $exception) {
throw new d3DicException($exception);
}
return self::$_instance;
}
/**
* get instance
*
* @throws Exception
* @return Container
* @throws d3DicException
*/
public static function getUncompiledInstance(): Container
{
try {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$caller = $trace[1];
$functionName = $caller['function'];
@ -74,6 +79,9 @@ class d3DicHandler implements d3DicHandlerInterface
$oDicHandler = oxNew(d3DicHandler::class);
self::$_instance = $oDicHandler->buildContainer(false);
} catch (Exception $exception) {
throw new d3DicException($exception);
}
return self::$_instance;
}
@ -112,6 +120,8 @@ class d3DicHandler implements d3DicHandlerInterface
}
/**
* @param ContainerBuilder $container
* @return void
* @throws Exception
*/
public function loadFiles(ContainerBuilder $container): void
@ -138,11 +148,13 @@ class d3DicHandler implements d3DicHandlerInterface
}
/**
* @param bool $compileAndDump
* @return Container
* @throws Exception
*/
public function buildContainer(bool $compileAndDump = true): Container
{
if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) {
if (Registry::get(ConfigFile::class)->getVar('iDebug')) {
startProfile(__METHOD__);
}
@ -168,7 +180,7 @@ class d3DicHandler implements d3DicHandlerInterface
}
}
if ((bool) Registry::get(ConfigFile::class)->getVar('iDebug')) {
if (Registry::get(ConfigFile::class)->getVar('iDebug')) {
stopProfile(__METHOD__);
}