diff --git a/application/composer.json b/application/composer.json index f82d574..aa6502b 100644 --- a/application/composer.json +++ b/application/composer.json @@ -8,6 +8,7 @@ "fresh/doctrine-enum-bundle": "~6.2", "friendsofsymfony/rest-bundle": "^2.4", "friendsofsymfony/user-bundle": "~2.1", + "jms/serializer-bundle": "^2.4", "knplabs/knp-menu-bundle": "^2.0", "sensio/framework-extra-bundle": "^5.1", "symfony/asset": "*", diff --git a/application/composer.lock b/application/composer.lock index 21f27a4..609e8fb 100644 --- a/application/composer.lock +++ b/application/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ea89b479cd43fa4f2bfb407f9583cc94", + "content-hash": "40ecc53c7d5df95c14346f7ae2faf283", "packages": [ { "name": "doctrine/annotations", @@ -1589,6 +1589,250 @@ ], "time": "2014-01-12T16:20:24+00:00" }, + { + "name": "jms/metadata", + "version": "1.6.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/metadata.git", + "reference": "6a06970a10e0a532fb52d3959547123b84a3b3ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/6a06970a10e0a532fb52d3959547123b84a3b3ab", + "reference": "6a06970a10e0a532fb52d3959547123b84a3b3ab", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "doctrine/cache": "~1.0", + "symfony/cache": "~3.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "Metadata\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Class/method/property metadata management in PHP", + "keywords": [ + "annotations", + "metadata", + "xml", + "yaml" + ], + "time": "2016-12-05T10:18:33+00:00" + }, + { + "name": "jms/parser-lib", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/parser-lib.git", + "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/parser-lib/zipball/c509473bc1b4866415627af0e1c6cc8ac97fa51d", + "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d", + "shasum": "" + }, + "require": { + "phpoption/phpoption": ">=0.9,<2.0-dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-0": { + "JMS\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "description": "A library for easily creating recursive-descent parsers.", + "time": "2012-11-18T18:08:43+00:00" + }, + { + "name": "jms/serializer", + "version": "1.13.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/serializer.git", + "reference": "00863e1d55b411cc33ad3e1de09a4c8d3aae793c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/00863e1d55b411cc33ad3e1de09a4c8d3aae793c", + "reference": "00863e1d55b411cc33ad3e1de09a4c8d3aae793c", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.0", + "doctrine/instantiator": "^1.0.3", + "jms/metadata": "^1.3", + "jms/parser-lib": "1.*", + "php": "^5.5|^7.0", + "phpcollection/phpcollection": "~0.1", + "phpoption/phpoption": "^1.1" + }, + "conflict": { + "twig/twig": "<1.12" + }, + "require-dev": { + "doctrine/orm": "~2.1", + "doctrine/phpcr-odm": "^1.3|^2.0", + "ext-pdo_sqlite": "*", + "jackalope/jackalope-doctrine-dbal": "^1.1.5", + "phpunit/phpunit": "^4.8|^5.0", + "propel/propel1": "~1.7", + "psr/container": "^1.0", + "symfony/dependency-injection": "^2.7|^3.3|^4.0", + "symfony/expression-language": "^2.6|^3.0", + "symfony/filesystem": "^2.1", + "symfony/form": "~2.1|^3.0", + "symfony/translation": "^2.1|^3.0", + "symfony/validator": "^2.2|^3.0", + "symfony/yaml": "^2.1|^3.0", + "twig/twig": "~1.12|~2.0" + }, + "suggest": { + "doctrine/cache": "Required if you like to use cache functionality.", + "doctrine/collections": "Required if you like to use doctrine collection types as ArrayCollection.", + "symfony/yaml": "Required if you'd like to serialize data to YAML format." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-1.x": "1.13-dev" + } + }, + "autoload": { + "psr-0": { + "JMS\\Serializer": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Asmir Mustafic", + "email": "goetas@gmail.com" + }, + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.", + "homepage": "http://jmsyst.com/libs/serializer", + "keywords": [ + "deserialization", + "jaxb", + "json", + "serialization", + "xml" + ], + "time": "2018-07-25T13:58:54+00:00" + }, + { + "name": "jms/serializer-bundle", + "version": "2.4.2", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/JMSSerializerBundle.git", + "reference": "22eb9a2f7983394b0770237ca91e879eb2a4b4a6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/JMSSerializerBundle/zipball/22eb9a2f7983394b0770237ca91e879eb2a4b4a6", + "reference": "22eb9a2f7983394b0770237ca91e879eb2a4b4a6", + "shasum": "" + }, + "require": { + "jms/serializer": "^1.10", + "php": "^5.4|^7.0", + "phpoption/phpoption": "^1.1.0", + "symfony/framework-bundle": "~2.3|~3.0|~4.0" + }, + "require-dev": { + "doctrine/orm": "*", + "phpunit/phpunit": "^4.8.35|^5.4.3|^6.0", + "symfony/expression-language": "~2.6|~3.0|~4.0", + "symfony/finder": "^2.3|^3.0|^4.0", + "symfony/form": "*", + "symfony/stopwatch": "*", + "symfony/twig-bundle": "*", + "symfony/validator": "*", + "symfony/yaml": "*" + }, + "suggest": { + "jms/di-extra-bundle": "Required to get lazy loading (de)serialization visitors, ~1.3", + "symfony/finder": "Required for cache warmup, supported versions ^2.3|^3.0|^4.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-4": { + "JMS\\SerializerBundle\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Asmir Mustafic", + "email": "goetas@gmail.com" + }, + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Allows you to easily serialize, and deserialize data of any complexity", + "homepage": "http://jmsyst.com/bundles/JMSSerializerBundle", + "keywords": [ + "deserialization", + "jaxb", + "json", + "serialization", + "xml" + ], + "time": "2018-06-19T13:39:25+00:00" + }, { "name": "knplabs/knp-menu", "version": "2.3.0", @@ -1909,6 +2153,54 @@ ], "time": "2018-08-26T15:07:25+00:00" }, + { + "name": "phpcollection/phpcollection", + "version": "0.5.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-collection.git", + "reference": "f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-collection/zipball/f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6", + "reference": "f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6", + "shasum": "" + }, + "require": { + "phpoption/phpoption": "1.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.4-dev" + } + }, + "autoload": { + "psr-0": { + "PhpCollection": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "General-Purpose Collection Library for PHP", + "keywords": [ + "collection", + "list", + "map", + "sequence", + "set" + ], + "time": "2015-05-17T12:39:23+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -2061,6 +2353,56 @@ ], "time": "2017-07-14T14:27:02+00:00" }, + { + "name": "phpoption/phpoption", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-option.git", + "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/94e644f7d2051a5f0fcf77d81605f152eecff0ed", + "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "4.7.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-0": { + "PhpOption\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache2" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Option Type for PHP", + "keywords": [ + "language", + "option", + "php", + "type" + ], + "time": "2015-07-25T16:39:46+00:00" + }, { "name": "psr/cache", "version": "1.0.1", diff --git a/application/config/bundles.php b/application/config/bundles.php index f67670d..0e12396 100644 --- a/application/config/bundles.php +++ b/application/config/bundles.php @@ -17,4 +17,5 @@ return [ Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true], FOS\UserBundle\FOSUserBundle::class => ['all' => true], FOS\RestBundle\FOSRestBundle::class => ['all' => true], + JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], ]; diff --git a/application/config/packages/dev/jms_serializer.yaml b/application/config/packages/dev/jms_serializer.yaml new file mode 100644 index 0000000..353e460 --- /dev/null +++ b/application/config/packages/dev/jms_serializer.yaml @@ -0,0 +1,7 @@ +jms_serializer: + visitors: + json: + options: + - JSON_PRETTY_PRINT + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/application/config/packages/jms_serializer.yaml b/application/config/packages/jms_serializer.yaml new file mode 100644 index 0000000..bab42da --- /dev/null +++ b/application/config/packages/jms_serializer.yaml @@ -0,0 +1,13 @@ +jms_serializer: + visitors: + xml: + format_output: '%kernel.debug%' +# metadata: +# auto_detection: false +# directories: +# any-name: +# namespace_prefix: "My\\FooBundle" +# path: "@MyFooBundle/Resources/config/serializer" +# another-name: +# namespace_prefix: "My\\BarBundle" +# path: "@MyBarBundle/Resources/config/serializer" diff --git a/application/config/packages/prod/jms_serializer.yaml b/application/config/packages/prod/jms_serializer.yaml new file mode 100644 index 0000000..bc97faf --- /dev/null +++ b/application/config/packages/prod/jms_serializer.yaml @@ -0,0 +1,6 @@ +jms_serializer: + visitors: + json: + options: + - JSON_UNESCAPED_SLASHES + - JSON_PRESERVE_ZERO_FRACTION diff --git a/application/src/Controller/SourceController.php b/application/src/Controller/SourceController.php index 0f27252..1299eb0 100644 --- a/application/src/Controller/SourceController.php +++ b/application/src/Controller/SourceController.php @@ -8,11 +8,15 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use App\Source\Generator\StringGenerator; +use FOS\RestBundle\FOSRestBundle; +use App\Creator\Factory\Template\SourceTemplateFactory; +use FOS\RestBundle\Controller\FOSRestController; +use FOS\RestBundle\Controller\Annotations\View; /** * @author kevinfrantz */ -class SourceController extends AbstractController +class SourceController extends FOSRestController { public function modify(int $id): Response { @@ -29,8 +33,9 @@ class SourceController extends AbstractController if (!$source) { throw $this->createNotFoundException('No source found for id '.$id); } - $templateGenerator = new StringGenerator($request, $source, $this->container->get('twig')); - - return new Response($templateGenerator->render()); + $view = $this->view($source, 200) + ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) + ->setTemplateVar('source'); + return $this->handleView($view); } } diff --git a/application/symfony.lock b/application/symfony.lock index 8ad2575..a62c708 100644 --- a/application/symfony.lock +++ b/application/symfony.lock @@ -119,6 +119,24 @@ "jdorn/sql-formatter": { "version": "v1.2.17" }, + "jms/metadata": { + "version": "1.6.0" + }, + "jms/parser-lib": { + "version": "1.0.0" + }, + "jms/serializer": { + "version": "1.13.0" + }, + "jms/serializer-bundle": { + "version": "2.0", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "master", + "version": "2.0", + "ref": "fe60ce509ef04a3f40da96e3979bc8d9b13b2372" + } + }, "knplabs/knp-menu": { "version": "2.3.0" }, @@ -146,6 +164,9 @@ "php-cs-fixer/diff": { "version": "v1.3.0" }, + "phpcollection/phpcollection": { + "version": "0.5.0" + }, "phpdocumentor/reflection-common": { "version": "1.0.1" }, @@ -155,6 +176,9 @@ "phpdocumentor/type-resolver": { "version": "0.4.0" }, + "phpoption/phpoption": { + "version": "1.5.0" + }, "phpspec/prophecy": { "version": "1.8.0" },