Skip to content

Commit f470b7d

Browse files
committed
Formatting fixes
1 parent cfbbf86 commit f470b7d

7 files changed

Lines changed: 156 additions & 154 deletions

File tree

‎composer.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "outeredge/swagger-module",
3-
"description": "Laminas Framework Module for Swagger resource file generation",
3+
"description": "Laminas Framework Module for Swagger/OpenAPI resource file generation",
44
"type": "library",
55
"license": "Apache-2.0",
6-
"homepage": "https://github.com/outeredge/SwaggerModule",
6+
"homepage": "https://github.com/xl32/SwaggerModule",
77
"keywords": [
88
"api",
99
"rest",
@@ -14,7 +14,8 @@
1414
"require": {
1515
"php": "^7.0",
1616
"laminas/laminas-servicemanager": "^3.1",
17-
"zircote/swagger-php": "~3.0"
17+
"zircote/swagger-php": "~3.0",
18+
"laminas/laminas-mvc": "^3.0"
1819
},
1920
"autoload": {
2021
"psr-0": {

‎config/module.config.php‎

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
<?php
22

3-
return array(
4-
'router' => array(
5-
'routes' => array(
6-
'swagger-resources' => array(
3+
use SwaggerModule\Controller\DocumentationController;
4+
use SwaggerModule\Controller\DocumentationControllerFactory;
5+
6+
return [
7+
'router' => [
8+
'routes' => [
9+
'swagger-resources' => [
710
'type' => 'Literal',
8-
'options' => array(
11+
'options' => [
912
'route' => '/api/docs',
10-
'defaults' => array(
11-
'controller' => 'SwaggerModule\Controller\Documentation',
12-
'action' => 'display'
13-
)
14-
)
15-
),
13+
'defaults' => [
14+
'controller' => DocumentationController::class,
15+
'action' => 'display',
16+
],
17+
],
18+
],
1619

17-
'swagger-resource-detail' => array(
20+
'swagger-resource-detail' => [
1821
'type' => 'Segment',
19-
'options' => array(
22+
'options' => [
2023
'route' => '/api/docs/:resource',
21-
'defaults' => array(
22-
'controller' => 'SwaggerModule\Controller\Documentation',
23-
'action' => 'details'
24-
)
25-
)
26-
)
27-
)
28-
),
24+
'defaults' => [
25+
'controller' => DocumentationController::class,
26+
'action' => 'details',
27+
],
28+
],
29+
],
30+
],
31+
],
2932

30-
'controllers' => array(
31-
'factories' => array(
32-
'SwaggerModule\Controller\Documentation' => 'SwaggerModule\Controller\DocumentationControllerFactory',
33-
),
34-
),
33+
'controllers' => [
34+
'factories' => [
35+
DocumentationController::class =>
36+
DocumentationControllerFactory::class,
37+
],
38+
],
3539

36-
'view_manager' => array(
37-
'strategies' => array(
38-
'ViewJsonStrategy'
39-
),
40-
),
41-
);
40+
'view_manager' => [
41+
'strategies' => [
42+
'ViewJsonStrategy',
43+
],
44+
],
45+
];
Lines changed: 62 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,62 @@
1-
<?php
2-
/**
3-
* SwaggerModule
4-
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*
17-
* @copyright Copyright (c) 2012 OuterEdge UK Ltd (http://www.outeredgeuk.com)
18-
* @license http://www.apache.org/licenses/LICENSE-2.0
19-
*/
20-
21-
namespace SwaggerModule\Controller;
22-
23-
use OpenApi\Annotations\OpenApi;
24-
use Laminas\Mvc\Controller\AbstractActionController;
25-
use Laminas\View\Model\JsonModel;
26-
27-
/**
28-
* DocumentationController. It is used to display a documentation in HTML
29-
*/
30-
class DocumentationController extends AbstractActionController
31-
{
32-
protected $openApi;
33-
34-
public function setOpenApi(OpenApi $openApi) {
35-
$this->swagger = $openApi;
36-
}
37-
38-
/**
39-
* Display the documentation
40-
*
41-
* @return JsonModel
42-
*/
43-
public function displayAction()
44-
{
45-
$jsonModel = new JsonModel((array)$this->swagger->jsonSerialize());
46-
return $jsonModel;
47-
}
48-
49-
/**
50-
* Get the details of a resource
51-
*
52-
* @return JsonModel
53-
*/
54-
public function detailsAction()
55-
{
56-
/** @var $options \SwaggerModule\Options\ModuleOptions */
57-
$options = $this->serviceLocator->get('SwaggerModule\Options\ModuleOptions');
58-
$resourceOptions = $options->getResourceOptions() ? : array();
59-
$resource = $this->swagger->getResource('/' . $this->params('resource', null), $resourceOptions);
60-
61-
if ($resource === false) {
62-
return new JsonModel();
63-
}
64-
65-
$jsonModel = new JsonModel();
66-
67-
return $jsonModel->setVariables($resource);
68-
}
69-
}
1+
<?php
2+
3+
/**
4+
* SwaggerModule
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @copyright Copyright (c) 2012 OuterEdge UK Ltd (http://www.outeredgeuk.com)
19+
* @license http://www.apache.org/licenses/LICENSE-2.0
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace SwaggerModule\Controller;
25+
26+
use OpenApi\Annotations\OpenApi;
27+
use Laminas\Mvc\Controller\AbstractActionController;
28+
use Laminas\View\Model\JsonModel;
29+
use SwaggerModule\Options\ModuleOptions;
30+
31+
/**
32+
* DocumentationController. It is used to display a documentation in HTML
33+
*/
34+
class DocumentationController extends AbstractActionController
35+
{
36+
/** @var OpenApi */
37+
protected $openApi;
38+
39+
/** @var ModuleOptions */
40+
protected $moduleOptions;
41+
42+
public function setOpenApi(OpenApi $openApi)
43+
{
44+
$this->openApi = $openApi;
45+
}
46+
47+
public function setModuleOptions(ModuleOptions $moduleOptions)
48+
{
49+
$this->moduleOptions = $moduleOptions;
50+
}
51+
52+
/**
53+
* Display the documentation
54+
*
55+
* @return JsonModel
56+
*/
57+
public function displayAction()
58+
{
59+
$jsonModel = new JsonModel((array)$this->openApi->jsonSerialize());
60+
return $jsonModel;
61+
}
62+
}
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SwaggerModule
45
*
@@ -18,40 +19,34 @@
1819
* @license http://www.apache.org/licenses/LICENSE-2.0
1920
*/
2021

22+
declare(strict_types=1);
23+
2124
namespace SwaggerModule\Controller;
2225

2326
use Interop\Container\ContainerInterface;
2427
use OpenApi\Annotations\OpenApi;
25-
use Laminas\ServiceManager\AbstractFactoryInterface;
26-
use Laminas\ServiceManager\AbstractPluginManager;
27-
use Laminas\ServiceManager\ServiceLocatorInterface;
28+
use Laminas\ServiceManager\Factory\AbstractFactoryInterface;
29+
use SwaggerModule\Options\ModuleOptions;
2830

2931
class DocumentationControllerFactory implements AbstractFactoryInterface
3032
{
31-
public function canCreate(ContainerInterface $container, $requestedName)
33+
public function canCreate(ContainerInterface $container, $requestedName): bool
3234
{
3335
return class_exists($requestedName);
3436
}
3537

36-
public function canCreateServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
37-
{
38-
return $this->canCreate($services, $requestedName);
39-
}
40-
41-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
42-
{
38+
public function __invoke(
39+
ContainerInterface $container,
40+
$requestedName,
41+
array $options = null
42+
): DocumentationController {
4343
$controller = new DocumentationController();
4444
/** @var OpenApi $openApi */
45-
$openApi = $container->get('OpenApi\Annotations\OpenApi');
45+
$openApi = $container->get(OpenApi::class);
4646
$controller->setOpenApi($openApi);
47-
return $controller;
48-
}
4947

50-
public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
51-
{
52-
if ($services instanceof AbstractPluginManager) {
53-
$services = $services->getServiceLocator();
54-
}
55-
return $this($services, $requestedName);
48+
$moduleOptions = $container->get(ModuleOptions::class);
49+
$controller->setModuleOptions($moduleOptions);
50+
return $controller;
5651
}
5752
}

‎src/SwaggerModule/Module.php‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SwaggerModule
45
*
@@ -15,17 +16,19 @@
1516
* limitations under the License.
1617
*
1718
* @copyright Copyright (c) 2012 OuterEdge UK Ltd (http://www.outeredgeuk.com)
18-
* @license http://www.apache.org/licenses/LICENSE-2.0
19+
* @license http://www.apache.org/licenses/LICENSE-2.0
1920
*/
2021

22+
declare(strict_types=1);
23+
2124
namespace SwaggerModule;
2225

26+
use OpenApi\Annotations\OpenApi;
2327
use RuntimeException;
2428
use SwaggerModule\Options\ModuleOptions as SwaggerModuleOptions;
2529
use OpenApi\StaticAnalyser as OpenApiStaticAnalyser;
2630
use OpenApi\Analysis as OpenApiAnalysis;
2731
use OpenApi\Util as OpenApiUtil;
28-
use Laminas\Console\Adapter\AdapterInterface;
2932
use Laminas\ModuleManager\Feature\ConfigProviderInterface;
3033
use Laminas\ModuleManager\Feature\ServiceProviderInterface;
3134

@@ -47,33 +50,33 @@ public function getConfig()
4750
*/
4851
public function getServiceConfig()
4952
{
50-
return array(
51-
'aliases' => array(
52-
'service.swagger' => 'Swagger\Annotations\Swagger',
53-
),
53+
return [
54+
'aliases' => [
55+
'service.swagger' => 'OpenApi\Annotations\OpenApi',
56+
],
5457

55-
'factories' => array(
56-
'SwaggerModule\Options\ModuleOptions' => function ($serviceManager) {
58+
'factories' => [
59+
SwaggerModuleOptions::class => function ($serviceManager) {
5760
$config = $serviceManager->get('Config');
5861
$config = (isset($config['swagger']) ? $config['swagger'] : null);
5962

60-
if($config === null) {
63+
if ($config === null) {
6164
throw new RuntimeException('Configuration for SwaggerModule was not found');
6265
}
6366

6467
return new SwaggerModuleOptions($config);
6568
},
6669

67-
'OpenApi\Annotations\OpenApi' => function($serviceManager) {
68-
/** @var $options \SwaggerModule\Options\ModuleOptions */
69-
$options = $serviceManager->get('SwaggerModule\Options\ModuleOptions');
70-
$analyser = new OpenApiStaticAnalyser();
71-
$analysis = new OpenApiAnalysis();
70+
OpenApi::class => function ($serviceManager) {
71+
/** @var $options SwaggerModuleOptions */
72+
$options = $serviceManager->get('SwaggerModule\Options\ModuleOptions');
73+
$analyser = new OpenApiStaticAnalyser();
74+
$analysis = new OpenApiAnalysis();
7275
$processors = OpenApiAnalysis::processors();
7376

7477
// Crawl directory and parse all files
7578
$paths = $options->getPaths();
76-
foreach($paths as $directory) {
79+
foreach ($paths as $directory) {
7780
$finder = OpenApiUtil::finder($directory);
7881
foreach ($finder as $file) {
7982
$analysis->addAnalysis($analyser->fromFile($file->getPathname()));
@@ -86,22 +89,22 @@ public function getServiceConfig()
8689

8790
// Pass options to analyzer
8891
$resourceOptions = $options->getResourceOptions();
89-
if(! empty($resourceOptions['servers'])) {
92+
if (! empty($resourceOptions['servers'])) {
9093
$analysis->openapi->servers = $resourceOptions['servers'];
9194
}
92-
if(! empty($resourceOptions['defaultBasePath'])) {
95+
if (! empty($resourceOptions['defaultBasePath'])) {
9396
$analysis->openapi->servers['basePath'] = $resourceOptions['defaultBasePath'];
9497
}
95-
if(! empty($resourceOptions['defaultHost'])) {
98+
if (! empty($resourceOptions['defaultHost'])) {
9699
$analysis->openapi->servers['host'] = $resourceOptions['defaultHost'];
97100
}
98-
if(! empty($resourceOptions['schemes'])) {
101+
if (! empty($resourceOptions['schemes'])) {
99102
$analysis->openapi->servers['schemes'] = $resourceOptions['schemes'];
100103
}
101104

102105
return $analysis->openapi;
103106
},
104-
)
105-
);
107+
],
108+
];
106109
}
107110
}

0 commit comments

Comments
 (0)