Skip to content

Commit 37226a0

Browse files
Merge pull request #44 from RonasIT/42-drivers-feature
feat: config comparing;
2 parents 7ac392b + 20a85b2 commit 37226a0

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace RonasIT\Support\AutoDoc\Exceptions;
4+
5+
use Exception;
6+
7+
class LegacyConfigException extends Exception
8+
{
9+
public function __construct()
10+
{
11+
parent::__construct('Your local auto-doc.php config file version is out of date, please update it using php artisan vendor:publish or manually.');
12+
}
13+
}

src/Services/SwaggerService.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Support\Str;
99
use ReflectionClass;
1010
use Illuminate\Http\Request;
11+
use RonasIT\Support\AutoDoc\Exceptions\LegacyConfigException;
1112
use RonasIT\Support\AutoDoc\Exceptions\WrongSecurityConfigException;
1213
use RonasIT\Support\AutoDoc\Traits\GetDependenciesTrait;
1314
use Symfony\Component\HttpFoundation\Response;
@@ -38,7 +39,7 @@ class SwaggerService
3839

3940
public function __construct(Container $container)
4041
{
41-
$this->config = config('auto-doc');
42+
$this->initConfig();
4243

4344
$this->setDriver();
4445

@@ -57,6 +58,29 @@ public function __construct(Container $container)
5758
}
5859
}
5960

61+
protected function initConfig()
62+
{
63+
$this->config = config('auto-doc');
64+
65+
$version = Arr::get($this->config, 'config_version');
66+
67+
if (empty($version)) {
68+
throw new LegacyConfigException();
69+
}
70+
71+
$packageConfigs = require __DIR__ . '/../../config/auto-doc.php';
72+
73+
$major = Str::before($version, '.');
74+
$minor = Str::after($version, '.');
75+
76+
$actualMajor = Str::before($packageConfigs['config_version'], '.');
77+
$actualMinor = Str::after($packageConfigs['config_version'], '.');
78+
79+
if ($actualMajor > $major || $actualMinor > $minor) {
80+
throw new LegacyConfigException();
81+
}
82+
}
83+
6084
protected function setDriver()
6185
{
6286
$driver = $this->config['driver'];

0 commit comments

Comments
 (0)