Skip to content

Commit

Permalink
[PHP][Symfony] Add a Symfony server generator swagger-api#3486
Browse files Browse the repository at this point in the history
  • Loading branch information
ksm2 committed Jul 3, 2017
1 parent 1187950 commit caac062
Show file tree
Hide file tree
Showing 25 changed files with 2,077 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,12 @@ public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "");
}

protected String extractSimpleName(String phpClassName) {
if (phpClassName == null) {
return null;
}

final int lastBackslashIndex = phpClassName.lastIndexOf('\\');
return phpClassName.substring(lastBackslashIndex + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void processOpts() {
additionalProperties.put("modelDocPath", modelDocPath);

// make test path available in mustache template
additionalProperties.put("testBasePath", testBasePath);
additionalProperties.put("testDirName", testBasePath);

supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiClient.php"));
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ io.swagger.codegen.languages.NodeJSServerCodegen
io.swagger.codegen.languages.ObjcClientCodegen
io.swagger.codegen.languages.PerlClientCodegen
io.swagger.codegen.languages.PhpClientCodegen
io.swagger.codegen.languages.SymfonyServerCodegen
io.swagger.codegen.languages.PowerShellClientCodegen
io.swagger.codegen.languages.PistacheServerCodegen
io.swagger.codegen.languages.PythonClientCodegen
Expand Down
18 changes: 18 additions & 0 deletions modules/swagger-codegen/src/main/resources/php-symfony/.php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return Symfony\CS\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->setUsingCache(true)
->fixers(
[
'ordered_use',
'phpdoc_order',
'short_array_syntax',
'strict',
'strict_param'
]
)
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
);
10 changes: 10 additions & 0 deletions modules/swagger-codegen/src/main/resources/php-symfony/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: php
sudo: false
php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
before_install: "composer install"
script: "vendor/bin/phpunit"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* ObjectSerializer
*
* PHP version 5
*
* @category Class
* @package {{invokerPackage}}
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/

{{>partial_header}}
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/

namespace {{invokerPackage}};

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Bundle Class Doc Comment
*
* @category Class
* @package {{invokerPackage}}
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class {{bundleName}} extends Bundle
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Controller
*
* PHP version 5
*
* @category Class
* @package {{controllerPackage}}
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/

{{>partial_header}}
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/

namespace {{controllerPackage}};

use Symfony\Bundle\FrameworkBundle\Controller\Controller as BaseController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;

/**
* Controller Class Doc Comment
*
* @category Class
* @package {{controllerPackage}}
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class Controller extends BaseController
{
/**
* This will return a response with code 400. Usage example:
*
* return $this->createBadRequestResponse('Unable to access this page!');
*
* @param string $message A message
*
* @return Response
*/
public function createBadRequestResponse($message = 'Bad Request.')
{
return new Response($message, 400);
}

/**
* This will return an error response. Usage example:
*
* return $this->createErrorResponse(new UnauthorizedHttpException());
*
* @param HttpException $exception An HTTP exception
*
* @return Response
*/
public function createErrorResponse(HttpException $exception)
{
return new Response($exception->getMessage(), $exception->getStatusCode(), $exception->getHeaders());
}

/**
* Serializes data to a given type format.
*
* @param mixed $data The data to serialize.
* @param string $class The source data class.
* @param string $format The target serialization format.
* @return string A serialized data string.
*/
public function serialize($data, $class, $format)
{
return $this->get('jms_serializer')->serialize($data, $format);
}

/**
* Deserializes data from a given type format.
*
* @param string $data The data to deserialize.
* @param string $class The target data class.
* @param string $format The source serialization format.
* @return mixed A deserialized data.
*/
public function deserialize($data, $class, $format)
{
return $this->get('jms_serializer')->deserialize($data, $class, $format);
}
}
Loading

0 comments on commit caac062

Please sign in to comment.