Skip to content

Commit

Permalink
Replace Usage of Legacy Config-class
Browse files Browse the repository at this point in the history
  • Loading branch information
JonisoftGermany committed May 30, 2023
1 parent cdf4da3 commit c599762
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions ErrorReport2Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace ErrorReport2;

use SPFW\system\config\Config;
use SPFW\system\Controller;
use SPFW\system\Core;
use SPFW\system\CoreException;
use SPFW\system\output\JsonOutput;
use SPFW\system\routing\PostRequest;
use SPFW\system\routing\Request;
Expand All @@ -13,11 +14,11 @@
* ErrorReport2 Server
*
* @package ErrorReport2
* @version 2.1.2
* @version 2.2.0
*/
final class ErrorReport2Server extends Controller
{
private const ER2_VERSION = '2.1.2';
private const ER2_VERSION = '2.2.0';

public const REQUIRED_DATABASE_VERSION = 3;

Expand All @@ -44,18 +45,23 @@ public function __construct(string $method_name, Request $request)
{
parent::__construct( $method_name, $request);

$global_config = Config::get();
if ($global_config === null) {
throw new \RuntimeException('Unknown global configuration');
try {
$global_environment = Core::activeInstance()->getEnvironment();
} catch (CoreException $e) {
throw new \RuntimeException('No active core instance');
}

if ($global_environment === null) {
throw new \RuntimeException('Unknown active environment');
}

$config_traits = class_uses($global_config);
$config_traits = class_uses($global_environment);
if (!\in_array(ErrorReport2ServerConfigTrait::class, $config_traits, true)) {
throw new \RuntimeException('Unknown global configuration');
}

/** @noinspection PhpUndefinedMethodInspection */
$er2_server_config = $global_config->getER2Config();
$er2_server_config = $global_environment->getER2Config();

if ($er2_server_config === null) {
throw new \RuntimeException('Undefined ER2 configuration');
Expand Down

0 comments on commit c599762

Please sign in to comment.