Skip to content

Commit

Permalink
Merge pull request #44 from RonasIT/42-drivers-feature
Browse files Browse the repository at this point in the history
feat: config comparing;
  • Loading branch information
astorozhevsky authored May 3, 2022
2 parents 7ac392b + 20a85b2 commit 37226a0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Exceptions/LegacyConfigException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RonasIT\Support\AutoDoc\Exceptions;

use Exception;

class LegacyConfigException extends Exception
{
public function __construct()
{
parent::__construct('Your local auto-doc.php config file version is out of date, please update it using php artisan vendor:publish or manually.');
}
}
26 changes: 25 additions & 1 deletion src/Services/SwaggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Str;
use ReflectionClass;
use Illuminate\Http\Request;
use RonasIT\Support\AutoDoc\Exceptions\LegacyConfigException;
use RonasIT\Support\AutoDoc\Exceptions\WrongSecurityConfigException;
use RonasIT\Support\AutoDoc\Traits\GetDependenciesTrait;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -38,7 +39,7 @@ class SwaggerService

public function __construct(Container $container)
{
$this->config = config('auto-doc');
$this->initConfig();

$this->setDriver();

Expand All @@ -57,6 +58,29 @@ public function __construct(Container $container)
}
}

protected function initConfig()
{
$this->config = config('auto-doc');

$version = Arr::get($this->config, 'config_version');

if (empty($version)) {
throw new LegacyConfigException();
}

$packageConfigs = require __DIR__ . '/../../config/auto-doc.php';

$major = Str::before($version, '.');
$minor = Str::after($version, '.');

$actualMajor = Str::before($packageConfigs['config_version'], '.');
$actualMinor = Str::after($packageConfigs['config_version'], '.');

if ($actualMajor > $major || $actualMinor > $minor) {
throw new LegacyConfigException();
}
}

protected function setDriver()
{
$driver = $this->config['driver'];
Expand Down

0 comments on commit 37226a0

Please sign in to comment.