8000 cakePHP 4.x compatiblity by mimorocks · Pull Request #55 · alt3/cakephp-swagger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cakePHP 4.x compatiblity #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

sudo: false

Expand All @@ -16,10 +15,10 @@ matrix:
fast_finish: true

include:
- php: 7.2
- php: 7.3
env: PHPCS=1 PHPUNIT=0

- php: 7.2
- php: 7.3
env: CODECOVERAGE=1 PHPUNIT=0

allow_failures:
Expand All @@ -29,7 +28,7 @@ before_script:
- composer self-update
- composer install --prefer-dist --no-interaction

- sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi"
- sh -c "if [ '$PHPCS' = '1' ]; then composer require --dev cakephp/cakephp-codesniffer; fi"

- phpenv rehash
- set +H
Expand Down
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
[![Total Downloads](https://img.shields.io/packagist/dt/alt3/cakephp-swagger.svg?style=flat-square)](https://packagist.org/packages/alt3/cakephp-swagger)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.txt)

CakePHP 3.x plugin that adds auto-generated Swagger 2.0 documentation to your projects using swagger-php and swagger-ui.
CakePHP 4.x plugin that adds auto-generated Swagger 2.0 documentation to your projects using swagger-php and swagger-ui.

## Requirements

* CakePHP 3.5+
* CakePHP 4.0+
* Some [swagger-php](https://github.com/zircote/swagger-php) annotation knowledge

## Installation
Expand All @@ -21,22 +21,7 @@ Install the plugin using composer:
composer require alt3/cakephp-swagger
```

## Enabling for CakePHP < 3.6

To enable the plugin either run the following command:

```bash
bin/cake plugin load Alt3/Swagger --routes --bootstrap
```

or manually add the following line to your `config/bootstrap.php` file:

```bash
Plugin::load('Alt3/Swagger', ['routes' => true, 'bootstrap' => true]);
```

## Enabling for CakePHP >= 3.6

## Enabling
Enable the plugin in the `bootstrap()` method found in `src/Application.php`:

```php
Expand Down Expand Up @@ 8000 -281,6 +266,6 @@ Which should result in:

Before submitting a PR make sure:

- [PHPUnit](http://book.cakephp.org/3.0/en/development/testing.html#running-tests)
- [PHPUnit](http://book.cakephp.org/4.0/en/development/testing.html#running-tests)
and [CakePHP Code Sniffer](https://github.com/cakephp/cakephp-codesniffer) tests pass
- [Coveralls Code Coverage ](https://coveralls.io/github/alt3/cakephp-swagger) remains at 100%
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "alt3/cakephp-swagger",
"description": "Instant Swagger documentation for your CakePHP 3.x APIs",
"description": "Instant Swagger documentation for your CakePHP 4.x APIs",
"type": "cakephp-plugin",
"license": "MIT",
"require": {
"php": ">=5.6",
"cakephp/cakephp": "^3.5",
"php": ">=7.0",
"cakephp/cakephp": "^4.0",
"zircote/swagger-php": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "5.*"
"phpunit/phpunit": "^7.0"
},
"support": {
"issues": "https://github.com/alt3/cakephp-swagger/issues",
Expand Down
3 changes: 2 additions & 1 deletion config/routes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

use Cake\Core\Configure;
use Cake\Routing\Router;

Expand All @@ -10,7 +11,7 @@
* - per library document, defaults to /alt3/swagger/docs/:id
*/
Router::plugin('Alt3/Swagger', [
'path' => '/'
'path' => '/',
], function (\Cake\Routing\RouteBuilder $routes) {

// UI route
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
Expand Down
11 changes: 6 additions & 5 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Controller;

use Cake\Controller\Controller as BaseController;
Expand All @@ -7,7 +9,6 @@

class AppController extends BaseController
{

/**
* @var array that will hold merged configuration settings.
*/
Expand All @@ -18,19 +19,19 @@ class AppController extends BaseController
*/
public static $defaultConfig = [
'docs' => [
'crawl' => true
'crawl' => true,
],
'ui' => [
'title' => 'cakephp-swagger'
]
'title' => 'cakephp-swagger',
],
];

/**
* Initialization hook method.
*
* @return void
*/
public function initialize()
public function initialize(): void
{
parent::initialize();

Expand Down
13 changes: 7 additions & 6 deletions src/Controller/DocsController.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Controller;

use Alt3\Swagger\Lib\SwaggerTools;
use Cake\Routing\Router;

class DocsController extends AppController
{

/**
* @var array Default CakePHP API success response structure.
*/
public static $apiResponseBody = [
'success' => true,
'data' => []
'data' => [],
];

/**
Expand All @@ -37,7 +38,7 @@ public function index($id = null)
}

if (!array_key_exists($id, $this->config['library'])) {
throw new \InvalidArgumentException("Swagger configuration file does not contain a document definition for '$id'");
throw new \InvalidArgumentException("Swagger configuration file does not contain a document definition for '$id'"); // phpcs:ignore
}

$document = SwaggerTools::getSwaggerDocument($id, $this->request->host());
Expand Down Expand Up @@ -67,8 +68,8 @@ protected function getJsonDocumentList()
'plugin' => 'Alt3/Swagger',
'controller' => 'Docs',
'action' => 'index',
$document
], true)
$document,
], true),
];
}

Expand Down Expand Up @@ -105,7 +106,7 @@ protected function addCorsHeaders()
protected function jsonResponse($json)
{
$this->set('json', $json);
$this->viewBuilder()->setLayout(false);
$this->viewBuilder()->disableAutoLayout();
$this->addCorsHeaders();
$this->response = $this->response->withType('json');
}
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/UiController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Controller;

use Cake\Routing\Router;
Expand All @@ -15,7 +17,7 @@ class UiController extends AppController
*/
public function index()
{
$this->viewBuilder()->setLayout(false);
$this->viewBuilder()->disableAutoLayout();
$this->set('uiConfig', $this->config['ui']);
$this->set('url', $this->getDefaultDocumentUrl());
}
Expand All @@ -37,7 +39,7 @@ public function getDefaultDocumentUrl()
'plugin' => 'Alt3/Swagger',
'controller' => 'Docs',
'action' => 'index',
$defaultDocument
$defaultDocument,
], true);
}
}
9 changes: 5 additions & 4 deletions src/Lib/SwaggerTools.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Lib;

use Cake\Core\Configure;
Expand All @@ -8,7 +10,6 @@

class SwaggerTools
{

/**
* @var string Prepended to filesystem swagger json files
*/
Expand Down Expand Up @@ -40,7 +41,7 @@ public static function getSwaggerDocument($id, $host)
$swaggerOptions = [];
if (Configure::read("Swagger.library.$id.exclude")) {
$swaggerOptions = [
'exclude' => Configure::read("Swagger.library.$id.exclude")
'exclude' => Configure::read("Swagger.library.$id.exclude"),
];
}
if (Configure::read('Swagger.analyser')) {
Expand All @@ -65,14 +66,14 @@ public static function getSwaggerDocument($id, $host)
* Write swagger document to filesystem.
*
* @param string $path Full path to the json document including filename
* @param string $content Swagger content
* @param object $content Swagger content
* @throws \Cake\Http\Exception\InternalErrorException
* @return bool
*/
protected static function writeSwaggerDocumentToFile($path, $content)
{
$fh = new File($path, true);
if (!$fh->write($content)) {
if (!$fh->write(serialize($content))) {
throw new InternalErrorException('Error writing Swagger json document to filesystem');
}

Expand Down
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger;

Expand Down
9 changes: 6 additions & 3 deletions src/Shell/SwaggerShell.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Shell;

use Alt3\Swagger\Controller\AppController;
use Alt3\Swagger\Lib\SwaggerTools;
use Cake\Console\ConsoleOptionParser;
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\Utility\Hash;
Expand All @@ -17,16 +20,16 @@ class SwaggerShell extends Shell
* @return \Cake\Console\ConsoleOptionParser
* @throws \Aura\Intl\Exception
*/
public function getOptionParser()
public function getOptionParser(): ConsoleOptionParser
{
$parser = parent::getOptionParser();

$parser->addSubcommand('makedocs', [
'description' => __('Crawl-generate fresh swagger file system documents for all entries found in the library.')
'description' => __('Crawl-generate fresh swagger file system documents for all entries found in the library.'), //phpcs:ignore
])
->addArgument('host', [
'help' => __("Swagger host FQDN (without protocol) as to be inserted into the swagger doc property 'host'"),
'required' => true
'required' => true,
]);

return $parser;
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions tests/App/Application.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Test\App;

use Alt3\Swagger\Plugin;
use Cake\Http\BaseApplication;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware;

Expand All @@ -14,7 +17,7 @@ class Application extends BaseApplication
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to set in your App Class
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware($middlewareQueue)
public function middleware($middlewareQueue): MiddlewareQueue
{
$middlewareQueue
// Handle plugin/theme assets like CakePHP normally does.
Expand All @@ -25,7 +28,7 @@ public function middleware($middlewareQueue)
return $middlewareQueue;
}

public function bootstrap()
public function bootstrap(): void
{
$this->addPlugin(Plugin::class, ['routes' => true, 'bootstrap' => true]);
parent::bootstrap();
Expand Down
5 changes: 4 additions & 1 deletion tests/App/src/Controller/DummyExcludeController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Controller;

/**
* Dummy test_app controller only used for crawl-generating a swagger document.
*
Expand All @@ -17,5 +21,4 @@
*/
class DummyExcludeController
{

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
declare(strict_types=1);

namespace Alt3\Swagger\Controller;

/**
* Dummy test_app controller only used for crawl-generating a swagger document.
Expand Down Expand Up @@ -63,5 +66,4 @@ enum={"name", "description"}
*/
class DummyIncludeController
{

}
Loading
0