Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ node_modules
composer.lock
vendor
var
.php-cs-fixer.cache
92 changes: 92 additions & 0 deletions docs/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/guides');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'align_multiline_comment' => [
'comment_type' => 'phpdocs_like',
],
'array_indentation' => true,
'compact_nullable_typehint' => true,
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'doctrine_annotation_spaces' => [
'after_array_assignments_equals' => false,
'before_array_assignments_equals' => false,
],
'explicit_indirect_variable' => true,
'fully_qualified_strict_types' => true,
'logical_operators' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'no_alternative_syntax' => true,
'no_extra_blank_lines' => [
'tokens' => [
'break',
'continue',
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'return',
'square_brace_block',
'throw',
'use',
],
],
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => false,
],
'no_unset_cast' => true,
'no_unset_on_property' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'php_unit_method_casing' => [
'case' => 'camel_case',
],
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_test_annotation' => [
'style' => 'prefix',
],
'phpdoc_add_missing_param_annotation' => [
'only_untyped' => true,
],
'phpdoc_no_alias_tag' => true,
'phpdoc_order' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_var_annotation_correct_order' => true,
'return_assignment' => true,
'strict_param' => true,
'blank_line_after_opening_tag' => false,
'declare_strict_types' => false,
'visibility_required' => [
'elements' => [
'const',
'method',
'property',
],
],
])
->setFinder($finder);
5 changes: 3 additions & 2 deletions docs/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"api-platform/core": "^3.1",
"api-platform/core": "dev-main",
"symfony/expression-language": "6.2.*",
"nelmio/cors-bundle": "^2.2",
"phpstan/phpdoc-parser": "^1.15",
Expand Down Expand Up @@ -43,5 +43,6 @@
},
"require-dev": {
"phpunit/phpunit": "^10"
}
},
"minimum-stability": "dev"
}
2 changes: 1 addition & 1 deletion docs/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
doctrine:
dbal:
url: 'sqlite:///%kernel.project_dir%/var/data.db'
url: 'sqlite:///%kernel.project_dir%/var/%guide%.db'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
Expand Down
21 changes: 13 additions & 8 deletions docs/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
when@test:
framework:
test: true
framework:
test: true
api_platform:
formats:
jsonld: ['application/ld+json']
json: ['application/json']
defaults:
extraProperties:
standard_put: true
formats:
jsonld: ['application/ld+json']
json: ['application/json']
docs_formats:
jsonopenapi: ['application/vnd.openapi+json']
event_listeners_backward_compatibility_layer: false
keep_legacy_inflector: false
defaults:
extra_properties:
rfc_7807_compliant_errors: true
standard_put: true
8 changes: 4 additions & 4 deletions docs/guides/create-a-custom-doctrine-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// name: Create a Custom Doctrine Filter
// executable: true
// position: 10
// tags: doctrine
// tags: doctrine, expert
// ---

// Custom filters can be written by implementing the `ApiPlatform\Api\FilterInterface` interface.
Expand Down Expand Up @@ -39,8 +39,8 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
* Otherwise this filter is applied to order and page as well.
*/
if (
!$this->isPropertyEnabled($property, $resourceClass) ||
!$this->isPropertyMapped($property, $resourceClass)
!$this->isPropertyEnabled($property, $resourceClass)
|| !$this->isPropertyMapped($property, $resourceClass)
) {
return;
}
Expand Down Expand Up @@ -138,9 +138,9 @@ public function up(Schema $schema): void
}

namespace App\Tests {
use ApiPlatform\Playground\Test\TestGuideTrait;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Entity\Book;
use ApiPlatform\Playground\Test\TestGuideTrait;

final class BookTest extends ApiTestCase
{
Expand Down
10 changes: 4 additions & 6 deletions docs/guides/custom-pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
// name: Custom pagination
// executable: true
// position: 12
// tags: state
// tags: expert
// ---

// In case you're using a custom collection (through a Provider), make sure you return the `Paginator` object to get the full hydra response with `hydra:view` (which contains information about first, last, next and previous page).
//
// The following example shows how to handle it using a custom Provider. You will need to use the Doctrine Paginator and pass it to the API Platform Paginator.

namespace App\Entity {

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use App\Repository\BookRepository;
Expand All @@ -22,7 +21,7 @@
/* Use custom Provider on operation to retrieve the custom collection */
#[ApiResource(
operations: [
new GetCollection(provider: BooksListProvider::class)
new GetCollection(provider: BooksListProvider::class),
]
)]
#[ORM\Entity(repositoryClass: BookRepository::class)]
Expand Down Expand Up @@ -71,7 +70,6 @@ public function getPublishedBooks(int $page = 1, int $itemsPerPage = 30): Doctri
}

namespace App\State {

use ApiPlatform\Doctrine\Orm\Paginator;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\Pagination\Pagination;
Expand Down Expand Up @@ -105,7 +103,6 @@ function request(): Request
}

namespace DoctrineMigrations {

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

Expand All @@ -123,6 +120,7 @@ public function up(Schema $schema): void
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Zenstruck\Foundry\AnonymousFactory;

use function Zenstruck\Foundry\faker;

final class BookFixtures extends Fixture
Expand All @@ -148,9 +146,9 @@ public function load(ObjectManager $manager): void
}

namespace App\Tests {
use ApiPlatform\Playground\Test\TestGuideTrait;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use App\Entity\Book;
use ApiPlatform\Playground\Test\TestGuideTrait;

final class BookTest extends ApiTestCase
{
Expand Down
10 changes: 5 additions & 5 deletions docs/guides/declare-a-resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
// position: 1
// executable: true
// tags: design
// homepage: true
// ---

// # Declare a Resource
// This class represents an API resource

namespace App\ApiResource {
// The `#[ApiResource]` attribute registers this class as an HTTP resource.
use ApiPlatform\Metadata\ApiResource;
// These are the list of HTTP operations we use to declare a "CRUD" (Create, Read, Update, Delete).
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Validator\Exception\ValidationException;

// Each resource has its set of Operations.
Expand All @@ -35,7 +35,7 @@
],
// This is a configuration that is shared accross every operations. More details are available at [ApiResource::exceptionToStatus](/reference/Metadata/ApiResource#exceptionToStatus).
exceptionToStatus: [
ValidationException::class => 422
ValidationException::class => 422,
]
)]
// If a property named `id` is found it is the property used in your URI template
Expand All @@ -47,6 +47,7 @@ class Book
}

// Check our next guide to [provide the resource state](./provide-the-resource-state).

namespace App\Playground {
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -55,4 +56,3 @@ function request(): Request
return Request::create('/docs', 'GET');
}
}

Loading