Skip to content

Commit 42314a4

Browse files
authored
Merge pull request #11 from xl32/master
ZF3 support added
2 parents b430353 + bfa6f7a commit 42314a4

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

config/module.config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
),
2929

3030
'controllers' => array(
31-
'invokables' => array(
32-
'SwaggerModule\Controller\Documentation' => 'SwaggerModule\Controller\DocumentationController'
33-
)
31+
'factories' => array(
32+
'SwaggerModule\Controller\Documentation' => 'SwaggerModule\Controller\DocumentationControllerFactory',
33+
),
3434
),
3535

3636
'view_manager' => array(

src/SwaggerModule/Controller/DocumentationController.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace SwaggerModule\Controller;
2222

23+
use Swagger\Annotations\Swagger;
2324
use Zend\Mvc\Controller\AbstractActionController;
2425
use Zend\View\Model\JsonModel;
2526

@@ -28,16 +29,20 @@
2829
*/
2930
class DocumentationController extends AbstractActionController
3031
{
32+
protected $swagger;
33+
34+
public function setSwagger(Swagger $swagger) {
35+
$this->swagger = $swagger;
36+
}
37+
3138
/**
3239
* Display the documentation
3340
*
3441
* @return JsonModel
3542
*/
3643
public function displayAction()
3744
{
38-
/** @var $swagger \Swagger\Annotations\Swagger */
39-
$swagger = $this->serviceLocator->get('Swagger\Annotations\Swagger');
40-
$jsonModel = new JsonModel((array)$swagger->jsonSerialize());
45+
$jsonModel = new JsonModel((array)$this->swagger->jsonSerialize());
4146
return $jsonModel;
4247
}
4348

@@ -48,13 +53,10 @@ public function displayAction()
4853
*/
4954
public function detailsAction()
5055
{
51-
/** @var $swagger \Swagger\Swagger */
52-
$swagger = $this->serviceLocator->get('Swagger\Annotations\Swagger');
53-
5456
/** @var $options \SwaggerModule\Options\ModuleOptions */
5557
$options = $this->serviceLocator->get('SwaggerModule\Options\ModuleOptions');
5658
$resourceOptions = $options->getResourceOptions() ? : array();
57-
$resource = $swagger->getResource('/' . $this->params('resource', null), $resourceOptions);
59+
$resource = $this->swagger->getResource('/' . $this->params('resource', null), $resourceOptions);
5860

5961
if ($resource === false) {
6062
return new JsonModel();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 Zend\ServiceManager\Factory\FactoryInterface;
24+
use Interop\Container\ContainerInterface;
25+
26+
/**
27+
* DocumentationController factory
28+
*/
29+
class DocumentationControllerFactory implements FactoryInterface
30+
{
31+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
32+
{
33+
$controller = new DocumentationController();
34+
/** @var \Swagger\Annotations\Swagger */
35+
$swagger = $container->get('Swagger\Annotations\Swagger');
36+
$controller->setSwagger($swagger);
37+
return $controller;
38+
}
39+
}

0 commit comments

Comments
 (0)