• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 13724522058

07 Mar 2025 04:04PM UTC coverage: 8.175% (-0.3%) from 8.518%
13724522058

Pull #7005

github

web-flow
Merge 322407532 into 1e0bc9dc8
Pull Request #7005: fix(validation): deprecate string message for ValidationException con…

4 of 6 new or added lines in 1 file covered. (66.67%)

159 existing lines in 24 files now uncovered.

12839 of 157045 relevant lines covered (8.18%)

13.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/docs/guides/declare-a-resource.php
1
<?php
2
// ---
3
// slug: declare-a-resource
4
// name: Declare a Resource
5
// position: 1
6
// executable: true
7
// tags: design
8
// ---
9

10
// This class represents an API resource
11

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

23
    // Each resource has its set of Operations.
24
    // Note that the uriTemplate may use the `id` variable which is our unique
25
    // identifier on this `Book`.
26
    #[ApiResource(
27
        operations: [
×
28
            new Get(uriTemplate: '/books/{id}'),
×
29
            // The GetCollection operation returns a list of Books.
30
            new GetCollection(uriTemplate: '/books'),
×
31
            new Post(uriTemplate: '/books'),
×
32
            new Patch(uriTemplate: '/books/{id}'),
×
33
            new Delete(uriTemplate: '/books/{id}'),
×
34
        ],
×
35
        // This is a configuration that is shared accross every operations. More details are available at [ApiResource::exceptionToStatus](/reference/Metadata/ApiResource#exceptionToStatus).
36
        exceptionToStatus: [
×
37
            ValidationException::class => 422,
×
38
        ]
×
39
    )]
×
40
    // If a property named `id` is found it is the property used in your URI template
41
    // we recommend to use public properties to declare API resources.
42
    class Book
43
    {
44
        public string $id;
45
    }
46
}
47

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

50
namespace App\Playground {
51
    use Symfony\Component\HttpFoundation\Request;
52

53
    function request(): Request
54
    {
55
        return Request::create('/docs', 'GET');
×
56
    }
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc