From 00820715ea826f62e9e24db583bf96461a63c22a Mon Sep 17 00:00:00 2001 From: krzysiej Date: Thu, 9 Jun 2022 11:46:15 +0200 Subject: [PATCH] Installed api platform. --- .env | 4 + composer.json | 2 + composer.lock | 341 +++++++++++++++++++++++++++++- config/bundles.php | 2 + config/packages/api_platform.yaml | 7 + config/packages/nelmio_cors.yaml | 10 + config/routes/api_platform.yaml | 4 + src/Entity/File.php | 2 + symfony.lock | 32 +++ templates/book/index.html.twig | 4 +- 10 files changed, 404 insertions(+), 4 deletions(-) create mode 100644 config/packages/api_platform.yaml create mode 100644 config/packages/nelmio_cors.yaml create mode 100644 config/routes/api_platform.yaml diff --git a/.env b/.env index f42868a..13c2fec 100644 --- a/.env +++ b/.env @@ -41,3 +41,7 @@ DATABASE_URL="mysql://root:root@127.0.0.1:3306/biblio?serverVersion=5.7&charset= ###> symfony/mailer ### # MAILER_DSN=null://null ###< symfony/mailer ### + +###> nelmio/cors-bundle ### +CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' +###< nelmio/cors-bundle ### diff --git a/composer.json b/composer.json index 8386df8..f1d20a9 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,12 @@ "php": ">=8.0.2", "ext-ctype": "*", "ext-iconv": "*", + "api-platform/core": "^2.6", "doctrine/annotations": "^1.0", "doctrine/doctrine-bundle": "^2.6", "doctrine/doctrine-migrations-bundle": "^3.2", "doctrine/orm": "^2.12", + "nelmio/cors-bundle": "^2.2", "phpdocumentor/reflection-docblock": "^5.3", "phpstan/phpdoc-parser": "^1.5", "sensio/framework-extra-bundle": "^6.1", diff --git a/composer.lock b/composer.lock index 894fbcc..831d352 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,169 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "38958ff5221180c36bc97324f82755b6", + "content-hash": "7102d8819fdf13b2459783afe8ecb539", "packages": [ + { + "name": "api-platform/core", + "version": "v2.6.8", + "source": { + "type": "git", + "url": "https://github.com/api-platform/core.git", + "reference": "ff3aab5b196709c721960c0bb4f1d52759af737d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/api-platform/core/zipball/ff3aab5b196709c721960c0bb4f1d52759af737d", + "reference": "ff3aab5b196709c721960c0bb4f1d52759af737d", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^1.0 || ^2.0", + "fig/link-util": "^1.0", + "php": ">=7.1", + "psr/cache": "^1.0 || ^2.0 || ^3.0", + "psr/container": "^1.0 || ^2.0", + "symfony/http-foundation": "^4.4 || ^5.1 || ^6.0", + "symfony/http-kernel": "^4.4 || ^5.1 || ^6.0", + "symfony/property-access": "^3.4.19 || ^4.4 || ^5.1 || ^6.0", + "symfony/property-info": "^3.4 || ^4.4 || ^5.2.1 || ^6.0", + "symfony/serializer": "^4.4 || ^5.1 || ^6.0", + "symfony/web-link": "^4.4 || ^5.1 || ^6.0", + "willdurand/negotiation": "^2.0.3 || ^3.0" + }, + "conflict": { + "doctrine/common": "<2.7", + "doctrine/dbal": "<2.10", + "doctrine/mongodb-odm": "<2.2", + "doctrine/persistence": "<1.3" + }, + "require-dev": { + "behat/behat": "^3.1", + "behat/mink": "^1.9@dev", + "doctrine/annotations": "^1.7", + "doctrine/cache": "^1.11 || ^2.1", + "doctrine/common": "^2.11 || ^3.0", + "doctrine/data-fixtures": "^1.2.2", + "doctrine/dbal": "^2.6 || ^3.0", + "doctrine/doctrine-bundle": "^1.12 || ^2.0", + "doctrine/mongodb-odm": "^2.2", + "doctrine/mongodb-odm-bundle": "^4.0", + "doctrine/orm": "^2.6.4", + "elasticsearch/elasticsearch": "^6.0 || ^7.0", + "friends-of-behat/mink-browserkit-driver": "^1.3.1", + "friends-of-behat/mink-extension": "^2.2", + "friends-of-behat/symfony-extension": "^2.1", + "guzzlehttp/guzzle": "^6.0 || ^7.0", + "jangregor/phpstan-prophecy": "^1.0", + "justinrainbow/json-schema": "^5.2.1", + "phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.1", + "phpdocumentor/type-resolver": "^0.3 || ^0.4 || ^1.4", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.1", + "phpstan/phpstan-doctrine": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-symfony": "^1.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "ramsey/uuid": "^3.7 || ^4.0", + "ramsey/uuid-doctrine": "^1.4", + "soyuka/contexts": "dev-main", + "soyuka/stubs-mongodb": "^1.0", + "symfony/asset": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/browser-kit": "^4.4 || ^5.1 || ^6.0", + "symfony/cache": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/config": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/console": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/css-selector": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/debug": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/dependency-injection": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/doctrine-bridge": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/dom-crawler": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/expression-language": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/finder": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/form": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/framework-bundle": "^4.4 || ^5.1 || ^6.0", + "symfony/http-client": "^4.4 || ^5.1 || ^6.0", + "symfony/mercure-bundle": "*", + "symfony/messenger": "^4.4 || ^5.1 || ^6.0", + "symfony/phpunit-bridge": "^5.4 || ^6.0", + "symfony/routing": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/security-bundle": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/security-core": "^4.4 || ^5.1 || ^6.0", + "symfony/twig-bundle": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/validator": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "symfony/web-profiler-bundle": "^4.4 || ^5.1 || ^6.0", + "symfony/yaml": "^3.4 || ^4.4 || ^5.1 || ^6.0", + "twig/twig": "^1.42.3 || ^2.12 || ^3.0", + "webonyx/graphql-php": "^14.0" + }, + "suggest": { + "doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.", + "elasticsearch/elasticsearch": "To support Elasticsearch.", + "guzzlehttp/guzzle": "To use the HTTP cache invalidation system.", + "ocramius/package-versions": "To display the API Platform's version in the debug bar.", + "phpdocumentor/reflection-docblock": "To support extracting metadata from PHPDoc.", + "psr/cache-implementation": "To use metadata caching.", + "ramsey/uuid": "To support Ramsey's UUID identifiers.", + "symfony/cache": "To have metadata caching when using Symfony integration.", + "symfony/config": "To load XML configuration files.", + "symfony/expression-language": "To use authorization features.", + "symfony/security": "To use authorization features.", + "symfony/twig-bundle": "To use the Swagger UI integration.", + "symfony/uid": "To support Symfony UUID/ULID identifiers.", + "symfony/web-profiler-bundle": "To use the data collector.", + "webonyx/graphql-php": "To support GraphQL." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.6.x-dev" + }, + "symfony": { + "require": "^3.4 || ^4.4 || ^5.1 || ^6.0" + } + }, + "autoload": { + "psr-4": { + "ApiPlatform\\Core\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Dunglas", + "email": "kevin@dunglas.fr", + "homepage": "https://dunglas.fr" + } + ], + "description": "Build a fully-featured hypermedia or GraphQL API in minutes!", + "homepage": "https://api-platform.com", + "keywords": [ + "Hydra", + "JSON-LD", + "api", + "graphql", + "hal", + "jsonapi", + "openapi", + "rest", + "swagger" + ], + "support": { + "issues": "https://github.com/api-platform/core/issues", + "source": "https://github.com/api-platform/core/tree/v2.6.8" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/api-platform/core", + "type": "tidelift" + } + ], + "time": "2022-01-11T10:29:54+00:00" + }, { "name": "doctrine/annotations", "version": "1.13.2", @@ -1443,6 +1604,67 @@ ], "time": "2021-10-11T09:18:27+00:00" }, + { + "name": "fig/link-util", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/link-util.git", + "reference": "10e52348a2e9ad4581f2bf3e16458f0861a88c6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/link-util/zipball/10e52348a2e9ad4581f2bf3e16458f0861a88c6a", + "reference": "10e52348a2e9ad4581f2bf3e16458f0861a88c6a", + "shasum": "" + }, + "require": { + "php": ">=8.0.0", + "psr/link": "^1.1.0 | ^2.0.0" + }, + "provide": { + "psr/link-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "^9", + "squizlabs/php_codesniffer": "^2.3.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Fig\\Link\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common utility implementations for HTTP links", + "keywords": [ + "http", + "http-link", + "link", + "psr", + "psr-13", + "rest" + ], + "support": { + "issues": "https://github.com/php-fig/link-util/issues", + "source": "https://github.com/php-fig/link-util/tree/1.2.0" + }, + "time": "2021-03-11T23:09:19+00:00" + }, { "name": "friendsofphp/proxy-manager-lts", "version": "v1.0.12", @@ -2070,6 +2292,67 @@ ], "time": "2022-05-10T09:36:00+00:00" }, + { + "name": "nelmio/cors-bundle", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/nelmio/NelmioCorsBundle.git", + "reference": "0ee5ee30b0ee08ea122d431ae6e0ddeb87f035c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nelmio/NelmioCorsBundle/zipball/0ee5ee30b0ee08ea122d431ae6e0ddeb87f035c0", + "reference": "0ee5ee30b0ee08ea122d431ae6e0ddeb87f035c0", + "shasum": "" + }, + "require": { + "symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0" + }, + "require-dev": { + "mockery/mockery": "^1.2", + "symfony/phpunit-bridge": "^4.3 || ^5.0 || ^6.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Nelmio\\CorsBundle\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nelmio", + "homepage": "http://nelm.io" + }, + { + "name": "Symfony Community", + "homepage": "https://github.com/nelmio/NelmioCorsBundle/contributors" + } + ], + "description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application", + "keywords": [ + "api", + "cors", + "crossdomain" + ], + "support": { + "issues": "https://github.com/nelmio/NelmioCorsBundle/issues", + "source": "https://github.com/nelmio/NelmioCorsBundle/tree/2.2.0" + }, + "time": "2021-12-01T09:34:27+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.2.0", @@ -8324,6 +8607,62 @@ "source": "https://github.com/webmozarts/assert/tree/1.10.0" }, "time": "2021-03-09T10:59:23+00:00" + }, + { + "name": "willdurand/negotiation", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/willdurand/Negotiation.git", + "reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/willdurand/Negotiation/zipball/68e9ea0553ef6e2ee8db5c1d98829f111e623ec2", + "reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Negotiation\\": "src/Negotiation" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "William Durand", + "email": "will+git@drnd.me" + } + ], + "description": "Content Negotiation tools for PHP provided as a standalone library.", + "homepage": "http://williamdurand.fr/Negotiation/", + "keywords": [ + "accept", + "content", + "format", + "header", + "negotiation" + ], + "support": { + "issues": "https://github.com/willdurand/Negotiation/issues", + "source": "https://github.com/willdurand/Negotiation/tree/3.1.0" + }, + "time": "2022-01-30T20:08:53+00:00" } ], "packages-dev": [ diff --git a/config/bundles.php b/config/bundles.php index f1ed3df..fd566ef 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -14,4 +14,6 @@ return [ Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Symfony\UX\Dropzone\DropzoneBundle::class => ['all' => true], + Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], + ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], ]; diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml new file mode 100644 index 0000000..2eb7b4c --- /dev/null +++ b/config/packages/api_platform.yaml @@ -0,0 +1,7 @@ +api_platform: + mapping: + paths: ['%kernel.project_dir%/src/Entity'] + patch_formats: + json: ['application/merge-patch+json'] + swagger: + versions: [3] diff --git a/config/packages/nelmio_cors.yaml b/config/packages/nelmio_cors.yaml new file mode 100644 index 0000000..c766508 --- /dev/null +++ b/config/packages/nelmio_cors.yaml @@ -0,0 +1,10 @@ +nelmio_cors: + defaults: + origin_regex: true + allow_origin: ['%env(CORS_ALLOW_ORIGIN)%'] + allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE'] + allow_headers: ['Content-Type', 'Authorization'] + expose_headers: ['Link'] + max_age: 3600 + paths: + '^/': null diff --git a/config/routes/api_platform.yaml b/config/routes/api_platform.yaml new file mode 100644 index 0000000..38f11cb --- /dev/null +++ b/config/routes/api_platform.yaml @@ -0,0 +1,4 @@ +api_platform: + resource: . + type: api_platform + prefix: /api diff --git a/src/Entity/File.php b/src/Entity/File.php index 24852fa..a8a646e 100644 --- a/src/Entity/File.php +++ b/src/Entity/File.php @@ -2,9 +2,11 @@ namespace App\Entity; +use ApiPlatform\Core\Annotation\ApiResource; use App\Repository\FileRepository; use Doctrine\ORM\Mapping as ORM; +#[ApiResource] #[ORM\Entity(repositoryClass: FileRepository::class)] class File { diff --git a/symfony.lock b/symfony.lock index 9d8402a..989c64d 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,18 @@ { + "api-platform/core": { + "version": "2.6", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "2.5", + "ref": "05b57782a78c21a664a42055dc11cf1954ca36bb" + }, + "files": [ + "./config/packages/api_platform.yaml", + "./config/routes/api_platform.yaml", + "./src/Entity/.gitignore" + ] + }, "doctrine/annotations": { "version": "1.13", "recipe": { @@ -77,6 +91,9 @@ "egulias/email-validator": { "version": "3.1.2" }, + "fig/link-util": { + "version": "1.2.0" + }, "friendsofphp/proxy-manager-lts": { "version": "v1.0.12" }, @@ -98,6 +115,18 @@ "monolog/monolog": { "version": "2.6.0" }, + "nelmio/cors-bundle": { + "version": "2.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "1.5", + "ref": "6bea22e6c564fba3a1391615cada1437d0bde39c" + }, + "files": [ + "./config/packages/nelmio_cors.yaml" + ] + }, "nikic/php-parser": { "version": "v4.13.2" }, @@ -544,5 +573,8 @@ }, "webmozart/assert": { "version": "1.10.0" + }, + "willdurand/negotiation": { + "version": "3.1.0" } } diff --git a/templates/book/index.html.twig b/templates/book/index.html.twig index c7a58cc..e5834aa 100644 --- a/templates/book/index.html.twig +++ b/templates/book/index.html.twig @@ -18,10 +18,9 @@ Title - Language Description Publisher - Publish_date + Publish date actions @@ -38,7 +37,6 @@ {{ book.title }} - {{ book.language }} {{ book.description | slice(0, 200) }} {{ book.publisher }} {{ book.publishDate ? book.publishDate|date('Y-m-d') : '' }}