Skip to content

Commit

Permalink
Zend Expressive fix and upgrade to version 2 (#6461)
Browse files Browse the repository at this point in the history
* upgraded zend-expressive from version 1 to 2

* Changed error handler for compatibility with Zend Expressive 2

* generated newest sample files for Petstore ze-ph

* removed ErrorMiddleware because it is never been used anymore. Regenerated samples

* removed ErrorMiddleware Template from Codegen

* remove ErrorMiddleware from petstore sample

* Fixed some code styles

* regenerated ze-ph samples with corrected code styles

* added new line at the end of the file
  • Loading branch information
BradCrumb authored and wing328 committed Sep 23, 2017
1 parent ccc980e commit c5c639b
Show file tree
Hide file tree
Showing 77 changed files with 274 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public ZendExpressivePathHandlerServerCodegen() {
supportingFiles.add(new SupportingFile("Date.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Strategy", "Date.php"));
supportingFiles.add(new SupportingFile("DateTime.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Strategy", "DateTime.php"));
supportingFiles.add(new SupportingFile("Type.php.mustache", packagePath + File.separator + srcBasePath + File.separator + "Validator", "Type.php"));
supportingFiles.add(new SupportingFile("ErrorMiddleware.php.mustache", packagePath + File.separator + srcBasePath, "ErrorMiddleware.php"));

additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, "1.0.0");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class Date extends DateTime
*/
protected function parseDateString($arrayValue)
{
return \DateTime::createFromFormat(static::DATE_TIME_FORMAT.' H:i:sP', $arrayValue.' 00:00:00+00:00', new \DateTimeZone('UTC'));
return \DateTime::createFromFormat(
static::DATE_TIME_FORMAT . ' H:i:sP',
$arrayValue . ' 00:00:00+00:00',
new \DateTimeZone('UTC')
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

namespace {{invokerPackage}}\Strategy;

use Articus\DataTransfer\Strategy\StrategyInterface;

class DateTime implements StrategyInterface
{
const DATE_TIME_FORMAT = \DateTime::RFC3339;
/**
* @inheritDoc
*/
Expand Down Expand Up @@ -41,4 +43,4 @@ class DateTime implements StrategyInterface
{
return \DateTime::createFromFormat(static::DATE_TIME_FORMAT, $arrayValue, new \DateTimeZone('UTC'));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ class Type extends AbstractValidator
throw new \InvalidArgumentException(sprintf('Can not check for type %s.', $this->type));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use Articus\PathHandler\Exception as PHException;
use Psr\Http\Message\ServerRequestInterface;

{{#operations}}

{{#description}}
/**
* {{&description}}
Expand Down Expand Up @@ -40,7 +39,11 @@ class {{classname}} implements {{interfacesToImplement}}
* TODO check if producer is valid, if it has correct priority and if it can be moved to class annotation
* @PHA\Producer(name=PHProducer\Transfer::class, mediaType="{{mediaType}}")
{{/produces}}
* @param ServerRequestInterface $request
*
* @throws PHException\HttpCode 500 if the method is not implemented
{{#returnType}}
*
* @return {{returnType}}
{{/returnType}}
*/
Expand Down
17 changes: 12 additions & 5 deletions modules/swagger-codegen/src/main/resources/ze-ph/app.yml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ dependencies:
#Has to add this line because currently router is strict requirement for Zend\Expressive\Application even if only middleware_pipeline is used
Zend\Expressive\Router\RouterInterface: Zend\Expressive\Router\ZendRouter
Zend\Diactoros\Response\EmitterInterface: Zend\Diactoros\Response\SapiStreamEmitter
{{invokerPackage}}\ErrorMiddleware: {{invokerPackage}}\ErrorMiddleware
factories:
Zend\Expressive\Application: Zend\Expressive\Container\ApplicationFactory
Articus\PathHandler\Middleware: Articus\PathHandler\MiddlewareFactory
Articus\DataTransfer\Service: Articus\DataTransfer\ServiceFactory
Zend\Stratigility\Middleware\ErrorHandler: Zend\Expressive\Container\ErrorHandlerFactory
Zend\Expressive\Middleware\ErrorResponseGenerator: Zend\Expressive\Container\WhoopsErrorResponseGeneratorFactory
Zend\Expressive\Whoops: Zend\Expressive\Container\WhoopsFactory
Zend\Expressive\WhoopsPageHandler: Zend\Expressive\Container\WhoopsPageHandlerFactory

middleware_pipeline:
error:
middleware: Zend\Stratigility\Middleware\ErrorHandler
api:
middleware: Articus\PathHandler\Middleware
path: {{basePathWithoutHost}}
error:
middleware: {{invokerPackage}}\ErrorMiddleware
error: true
priority: -10000

whoops:
json_exceptions:
display: true
show_trace: true
ajax_only: true
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"require": {
"php": "^5.6 || ^7.0",
"ext-yaml" : "^1.2 || ^2.0",
"zendframework/zend-expressive": "^1.0",
"zendframework/zend-expressive-router": "1.2.*",
"articus/path-handler": "0.1.*",
"zendframework/zend-expressive": "^2.0",
"zendframework/zend-expressive-router": "^2.1",
"zendframework/zend-expressive-zendrouter": "^2.0",
"articus/path-handler": "0.2.*",
"articus/data-transfer": "*",
"zendframework/zend-serializer": "*",
"zendframework/zend-config": "*"
"zendframework/zend-config": "*",
"filp/whoops": "^2.1.7"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#App
cache_configuration: false
debug: true
2 changes: 1 addition & 1 deletion modules/swagger-codegen/src/main/resources/ze-ph/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

/** @var \Zend\Expressive\Application $app */
$app = $container->get(\Zend\Expressive\Application::class);
$app->run();
$app->run();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Articus\DataTransfer\Annotation as DTA;
* {{description}}
{{/description}}
*/
class {{classname}}
class {{classname}}
{
{{#vars}}
/**
Expand Down Expand Up @@ -127,5 +127,4 @@ class {{classname}}
*/
public ${{name}};
{{/vars}}
}
{{/model}}{{/models}}
}{{/model}}{{/models}}
2 changes: 1 addition & 1 deletion samples/server/petstore/ze-ph/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3-SNAPSHOT
2.3.0-SNAPSHOT
1 change: 1 addition & 0 deletions samples/server/petstore/ze-ph/application/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#App
cache_configuration: false
debug: true
17 changes: 12 additions & 5 deletions samples/server/petstore/ze-ph/application/config/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ dependencies:
#Has to add this line because currently router is strict requirement for Zend\Expressive\Application even if only middleware_pipeline is used
Zend\Expressive\Router\RouterInterface: Zend\Expressive\Router\ZendRouter
Zend\Diactoros\Response\EmitterInterface: Zend\Diactoros\Response\SapiStreamEmitter
App\ErrorMiddleware: App\ErrorMiddleware
factories:
Zend\Expressive\Application: Zend\Expressive\Container\ApplicationFactory
Articus\PathHandler\Middleware: Articus\PathHandler\MiddlewareFactory
Articus\DataTransfer\Service: Articus\DataTransfer\ServiceFactory
Zend\Stratigility\Middleware\ErrorHandler: Zend\Expressive\Container\ErrorHandlerFactory
Zend\Expressive\Middleware\ErrorResponseGenerator: Zend\Expressive\Container\WhoopsErrorResponseGeneratorFactory
Zend\Expressive\Whoops: Zend\Expressive\Container\WhoopsFactory
Zend\Expressive\WhoopsPageHandler: Zend\Expressive\Container\WhoopsPageHandlerFactory

middleware_pipeline:
error:
middleware: Zend\Stratigility\Middleware\ErrorHandler
api:
middleware: Articus\PathHandler\Middleware
path: /v2
error:
middleware: App\ErrorMiddleware
error: true
priority: -10000

whoops:
json_exceptions:
display: true
show_trace: true
ajax_only: true
14 changes: 14 additions & 0 deletions samples/server/petstore/ze-ph/application/config/path_handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ path_handler:
handler: Fake
may_terminate: true
child_routes:
'jsonFormData':
type: Literal
options:
route: /jsonFormData
defaults:
handler: FakeJsonFormData
'outer':
type: Literal
options:
Expand Down Expand Up @@ -38,6 +44,12 @@ path_handler:
route: /string
defaults:
handler: FakeOuterString
'fake_classname_test':
type: Literal
options:
route: /fake_classname_test
defaults:
handler: FakeClassnameTest
'pet':
type: Literal
options:
Expand Down Expand Up @@ -150,10 +162,12 @@ path_handler:
handlers:
invokables:
Fake: App\Handler\Fake
FakeJsonFormData: App\Handler\FakeJsonFormData
FakeOuterBoolean: App\Handler\FakeOuterBoolean
FakeOuterComposite: App\Handler\FakeOuterComposite
FakeOuterNumber: App\Handler\FakeOuterNumber
FakeOuterString: App\Handler\FakeOuterString
FakeClassnameTest: App\Handler\FakeClassnameTest
Pet: App\Handler\Pet
PetFindByStatus: App\Handler\PetFindByStatus
PetFindByTags: App\Handler\PetFindByTags
Expand Down
10 changes: 6 additions & 4 deletions samples/server/petstore/ze-ph/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"require": {
"php": "^5.6 || ^7.0",
"ext-yaml" : "^1.2 || ^2.0",
"zendframework/zend-expressive": "^1.0",
"zendframework/zend-expressive-router": "1.2.*",
"articus/path-handler": "0.1.*",
"zendframework/zend-expressive": "^2.0",
"zendframework/zend-expressive-router": "^2.1",
"zendframework/zend-expressive-zendrouter": "^2.0",
"articus/path-handler": "0.2.*",
"articus/data-transfer": "*",
"zendframework/zend-serializer": "*",
"zendframework/zend-config": "*"
"zendframework/zend-config": "*",
"filp/whoops": "^2.1.7"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/ze-ph/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

/** @var \Zend\Expressive\Application $app */
$app = $container->get(\Zend\Expressive\Application::class);
$app->run();
$app->run();
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class AdditionalPropertiesClass
class AdditionalPropertiesClass
{
/**
* @DTA\Data(field="map_property", nullable=true)
Expand All @@ -21,4 +21,3 @@ class AdditionalPropertiesClass
*/
public $map_of_map_property;
}

3 changes: 1 addition & 2 deletions samples/server/petstore/ze-ph/src/App/DTO/Animal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class Animal
class Animal
{
/**
* @DTA\Data(field="className")
Expand All @@ -21,4 +21,3 @@ class Animal
*/
public $color;
}

3 changes: 1 addition & 2 deletions samples/server/petstore/ze-ph/src/App/DTO/AnimalFarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

/**
*/
class AnimalFarm
class AnimalFarm
{
}

3 changes: 1 addition & 2 deletions samples/server/petstore/ze-ph/src/App/DTO/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class ApiResponse
class ApiResponse
{
/**
* @DTA\Data(field="code", nullable=true)
Expand All @@ -27,4 +27,3 @@ class ApiResponse
*/
public $message;
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class ArrayOfArrayOfNumberOnly
class ArrayOfArrayOfNumberOnly
{
/**
* @DTA\Data(field="ArrayArrayNumber", nullable=true)
Expand All @@ -18,4 +18,3 @@ class ArrayOfArrayOfNumberOnly
*/
public $array_array_number;
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class ArrayOfNumberOnly
class ArrayOfNumberOnly
{
/**
* @DTA\Data(field="ArrayNumber", nullable=true)
Expand All @@ -17,4 +17,3 @@ class ArrayOfNumberOnly
*/
public $array_number;
}

3 changes: 1 addition & 2 deletions samples/server/petstore/ze-ph/src/App/DTO/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class ArrayTest
class ArrayTest
{
/**
* @DTA\Data(field="array_of_string", nullable=true)
Expand Down Expand Up @@ -35,4 +35,3 @@ class ArrayTest
*/
public $array_array_of_model;
}

3 changes: 1 addition & 2 deletions samples/server/petstore/ze-ph/src/App/DTO/Capitalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class Capitalization
class Capitalization
{
/**
* @DTA\Data(field="smallCamel", nullable=true)
Expand Down Expand Up @@ -46,4 +46,3 @@ class Capitalization
*/
public $att_name;
}

3 changes: 1 addition & 2 deletions samples/server/petstore/ze-ph/src/App/DTO/Cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
*/
class Cat
class Cat
{
/**
* @DTA\Data(field="className")
Expand All @@ -27,4 +27,3 @@ class Cat
*/
public $declawed;
}

Loading

0 comments on commit c5c639b

Please sign in to comment.