Przeglądaj źródła

Merge pull request #572 from sangnguyenplus/laravel-6-compatible

Add support Laravel 6.0 & remove deprecated functions
Shalvah 5 lat temu
rodzic
commit
11d0ed756d

+ 3 - 3
composer.json

@@ -17,9 +17,9 @@
     "require": {
         "php": ">=7.0.0",
         "fzaninotto/faker": "~1.8",
-        "illuminate/routing": "5.5.* || 5.6.* || 5.7.* || 5.8.*",
-        "illuminate/support": "5.5.* || 5.6.* || 5.7.* || 5.8.*",
-        "illuminate/console": "5.5.* || 5.6.* || 5.7.* || 5.8.*",
+        "illuminate/routing": "^5.5|^6.0",
+        "illuminate/support": "^5.5|^6.0",
+        "illuminate/console": "^5.5|^6.0",
         "mpociot/documentarian": "^0.2.0",
         "mpociot/reflection-docblock": "^1.0.1",
         "ramsey/uuid": "^3.8",

+ 1 - 1
resources/views/documentarian.blade.php

@@ -8,7 +8,7 @@
 @foreach($parsedRoutes as $groupName => $routes)
 #{!! $groupName !!}
 {{-- We pick the first non-empty description we see. --}}
-{!! array_first($routes, function ($route) { return $route['groupDescription'] !== ''; })['groupDescription'] ?? '' !!}
+{!! \Illuminate\Support\Arr::first($routes, function ($route) { return $route['groupDescription'] !== ''; })['groupDescription'] ?? '' !!}
 @foreach($routes as $parsedRoute)
 @if($writeCompareFile === true)
 {!! $parsedRoute['output'] !!}

+ 2 - 1
src/Tools/Generator.php

@@ -5,6 +5,7 @@ namespace Mpociot\ApiDoc\Tools;
 use Faker\Factory;
 use ReflectionClass;
 use ReflectionMethod;
+use Illuminate\Support\Str;
 use Illuminate\Routing\Route;
 use Mpociot\Reflection\DocBlock;
 use Mpociot\Reflection\DocBlock\Tag;
@@ -227,7 +228,7 @@ class Generator
 
                 list($description, $value) = $this->parseDescription($description, 'string');
                 if (is_null($value) && ! $this->shouldExcludeExample($tag)) {
-                    $value = str_contains($description, ['number', 'count', 'page'])
+                    $value = Str::contains($description, ['number', 'count', 'page'])
                         ? $this->generateDummyValue('integer')
                         : $this->generateDummyValue('string');
                 }

+ 4 - 3
src/Tools/ResponseStrategies/TransformerTagsStrategy.php

@@ -4,6 +4,7 @@ namespace Mpociot\ApiDoc\Tools\ResponseStrategies;
 
 use ReflectionClass;
 use ReflectionMethod;
+use Illuminate\Support\Arr;
 use League\Fractal\Manager;
 use Illuminate\Routing\Route;
 use Mpociot\ApiDoc\Tools\Flags;
@@ -80,7 +81,7 @@ class TransformerTagsStrategy
      */
     private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod)
     {
-        $modelTag = array_first(array_filter($tags, function ($tag) {
+        $modelTag = Arr::first(array_filter($tags, function ($tag) {
             return ($tag instanceof Tag) && strtolower($tag->getName()) == 'transformermodel';
         }));
 
@@ -88,7 +89,7 @@ class TransformerTagsStrategy
         if ($modelTag) {
             $type = $modelTag->getContent();
         } else {
-            $parameter = array_first($transformerMethod->getParameters());
+            $parameter = Arr::first($transformerMethod->getParameters());
             if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) {
                 // ladies and gentlemen, we have a type!
                 $type = (string) $parameter->getType();
@@ -146,6 +147,6 @@ class TransformerTagsStrategy
             })
         );
 
-        return array_first($transFormerTags);
+        return Arr::first($transFormerTags);
     }
 }

+ 7 - 6
src/Tools/RouteMatcher.php

@@ -2,6 +2,7 @@
 
 namespace Mpociot\ApiDoc\Tools;
 
+use Illuminate\Support\Str;
 use Illuminate\Routing\Route;
 use Dingo\Api\Routing\RouteCollection;
 use Illuminate\Support\Facades\Route as RouteFacade;
@@ -71,10 +72,10 @@ class RouteMatcher
             ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
             : true;
 
-        return str_is($mustIncludes, $route->getName())
-            || str_is($mustIncludes, $route->uri())
-            || (str_is($routeRule['match']['domains'] ?? [], $route->getDomain())
-            && str_is($routeRule['match']['prefixes'] ?? [], $route->uri())
+        return Str::is($mustIncludes, $route->getName())
+            || Str::is($mustIncludes, $route->uri())
+            || (Str::is($routeRule['match']['domains'] ?? [], $route->getDomain())
+            && Str::is($routeRule['match']['prefixes'] ?? [], $route->uri())
             && $matchesVersion);
     }
 
@@ -82,7 +83,7 @@ class RouteMatcher
     {
         $excludes = $routeRule['exclude'] ?? [];
 
-        return str_is($excludes, $route->getName())
-            || str_is($excludes, $route->uri());
+        return Str::is($excludes, $route->getName())
+            || Str::is($excludes, $route->uri());
     }
 }

+ 5 - 2
src/Tools/Traits/ParamHelpers.php

@@ -2,6 +2,9 @@
 
 namespace Mpociot\ApiDoc\Tools\Traits;
 
+use Illuminate\Support\Arr;
+use Illuminate\Support\Str;
+
 trait ParamHelpers
 {
     /**
@@ -36,9 +39,9 @@ trait ParamHelpers
      */
     protected function cleanValueFrom($name, $value, array &$values = [])
     {
-        if (str_contains($name, '[')) {
+        if (Str::contains($name, '[')) {
             $name = str_replace(['][', '[', ']', '..'], ['.', '.', '', '.*.'], $name);
         }
-        array_set($values, str_replace('.*', '.0', $name), $value);
+        Arr::set($values, str_replace('.*', '.0', $name), $value);
     }
 }

+ 17 - 16
tests/Unit/GeneratorTestCase.php

@@ -2,6 +2,7 @@
 
 namespace Mpociot\ApiDoc\Tests\Unit;
 
+use Illuminate\Support\Arr;
 use Orchestra\Testbench\TestCase;
 use Mpociot\ApiDoc\Tools\Generator;
 use Mpociot\ApiDoc\Tools\DocumentationConfig;
@@ -315,7 +316,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('POST', '/responseTag', 'withResponseTag');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -336,7 +337,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('POST', '/responseTag', 'withResponseTagAndStatusCode');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -385,7 +386,7 @@ abstract class GeneratorTestCase extends TestCase
         config(['apidoc.fractal.serializer' => $serializer]);
         $route = $this->createRoute('GET', '/transformerTag', 'transformerTag');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -403,7 +404,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('GET', '/transformerTagWithModel', 'transformerTagWithModel');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -421,7 +422,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('GET', '/transformerCollectionTag', 'transformerCollectionTag');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -440,7 +441,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('GET', '/transformerCollectionTagWithModel', 'transformerCollectionTagWithModel');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -469,7 +470,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -496,7 +497,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(array_first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['response'])['content'], true);
         $originalValue = $response['app.env'];
 
         $now = time();
@@ -509,7 +510,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(array_first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['response'])['content'], true);
         $newValue = $response['app.env'];
         $this->assertEquals($now, $newValue);
         $this->assertNotEquals($originalValue, $newValue);
@@ -530,7 +531,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(array_first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['response'])['content'], true);
         $param = $response['param'];
         $this->assertEquals($rand, $param);
     }
@@ -550,7 +551,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(array_first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['response'])['content'], true);
         $param = $response['param'];
         $this->assertEquals($rand, $param);
     }
@@ -573,12 +574,12 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route1, $rules);
-        $response = json_decode(array_first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['response'])['content'], true);
         $param = $response['param'];
         $this->assertEquals($rand1, $param);
 
         $parsed = $this->generator->processRoute($route2, $rules);
-        $response = json_decode(array_first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['response'])['content'], true);
         $param = $response['param'];
         $this->assertEquals($rand2, $param);
     }
@@ -593,7 +594,7 @@ abstract class GeneratorTestCase extends TestCase
 
         $route = $this->createRoute('GET', '/responseFileTag', 'responseFileTag');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -618,7 +619,7 @@ abstract class GeneratorTestCase extends TestCase
 
         $route = $this->createRoute('GET', '/responseFileTagAndCustomJson', 'responseFileTagAndCustomJson');
         $parsed = $this->generator->processRoute($route);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -717,7 +718,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = array_first($parsed['response']);
+        $response = Arr::first($parsed['response']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);

+ 8 - 7
tests/Unit/RouteMatcherTest.php

@@ -2,6 +2,7 @@
 
 namespace Mpociot\ApiDoc\Tests\Unit;
 
+use Illuminate\Support\Str;
 use Dingo\Api\Routing\Router;
 use Orchestra\Testbench\TestCase;
 use Mpociot\ApiDoc\Tools\RouteMatcher;
@@ -108,7 +109,7 @@ class RouteMatcherTest extends TestCase
         $routes = $this->matcher->getRoutesToBeDocumented($routeRules);
         $this->assertCount(4, $routes);
         foreach ($routes as $route) {
-            $this->assertTrue(str_is('prefix2/*', $route['route']->uri()));
+            $this->assertTrue(Str::is('prefix2/*', $route['route']->uri()));
         }
     }
 
@@ -130,14 +131,14 @@ class RouteMatcherTest extends TestCase
         $routes = $this->matcher->getDingoRoutesToBeDocumented($routeRules);
         $this->assertCount(4, $routes);
         foreach ($routes as $route) {
-            $this->assertTrue(str_is('prefix1/*', $route['route']->uri()));
+            $this->assertTrue(Str::is('prefix1/*', $route['route']->uri()));
         }
 
         $routeRules[0]['match']['prefixes'] = ['prefix2/*'];
         $routes = $this->matcher->getDingoRoutesToBeDocumented($routeRules);
         $this->assertCount(4, $routes);
         foreach ($routes as $route) {
-            $this->assertTrue(str_is('prefix2/*', $route['route']->uri()));
+            $this->assertTrue(Str::is('prefix2/*', $route['route']->uri()));
         }
     }
 
@@ -337,14 +338,14 @@ class RouteMatcherTest extends TestCase
 
         $routes = collect($routes);
         $firstRuleGroup = $routes->filter(function ($route) {
-            return str_is('prefix1/*', $route['route']->uri())
-                && str_is('domain1.*', $route['route']->getDomain());
+            return Str::is('prefix1/*', $route['route']->uri())
+                && Str::is('domain1.*', $route['route']->getDomain());
         });
         $this->assertCount(2, $firstRuleGroup);
 
         $secondRuleGroup = $routes->filter(function ($route) {
-            return str_is('prefix2/*', $route['route']->uri())
-                && str_is('domain2.*', $route['route']->getDomain());
+            return Str::is('prefix2/*', $route['route']->uri())
+                && Str::is('domain2.*', $route['route']->getDomain());
         });
         $this->assertCount(2, $secondRuleGroup);
     }