forked from sofascore/purgatory-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimalController.php
More file actions
209 lines (191 loc) · 6.17 KB
/
AnimalController.php
File metadata and controls
209 lines (191 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
declare(strict_types=1);
namespace Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Controller;
use Sofascore\PurgatoryBundle\Attribute\PurgeOn;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\CompoundValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\DynamicValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\EnumValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\ExpressionValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\RawValues;
use Sofascore\PurgatoryBundle\Attribute\Target\ForGroups;
use Sofascore\PurgatoryBundle\Attribute\Target\ForProperties;
use Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Entity\Animal;
use Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Entity\Person;
use Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Enum\Country;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Attribute\Route;
#[AsController]
#[Route('/animal')]
class AnimalController
{
#[Route('/{animal_id}', 'animal_details')]
#[PurgeOn(Animal::class,
target: new ForGroups('common'),
routeParams: [
'animal_id' => 'id',
],
)]
public function detailAction(Animal $animal)
{
}
#[Route('/{animal_id}/measurements', 'animal_measurements')]
#[PurgeOn(Animal::class,
target: new ForProperties(['measurements.height', 'measurements.weight']),
routeParams: [
'animal_id' => 'id',
],
)]
public function measurementsAction(Animal $animal)
{
}
#[Route('/{animal_id}/measurements-alt', 'animal_measurements_alt')]
#[PurgeOn(Animal::class,
target: new ForProperties(['goodBoy']),
routeParams: [
'animal_id' => 'id',
],
)]
public function measurementsAltAction(Animal $animal)
{
}
#[Route('/{id}/route1', 'animal_route_1')]
#[Route('/{id}/route2', 'animal_route_2')]
#[PurgeOn(Animal::class,
target: 'measurements.height',
)]
#[PurgeOn(Animal::class,
target: 'measurements.weight',
route: 'animal_route_1',
)]
#[PurgeOn(Animal::class,
target: 'measurements.width',
route: 'animal_route_2',
)]
public function someRandomRouteAction(Animal $animal)
{
}
#[Route('/pet-of-the-day/{country}', 'pet_of_the_day')]
#[PurgeOn(Animal::class,
target: new ForGroups('common'),
routeParams: [
'country' => new EnumValues(Country::class),
],
)]
public function petOfTheDayAction(Country $country)
{
}
#[Route('/pet-of-the-month/{country}', 'pet_of_the_month')]
#[PurgeOn(Animal::class,
target: new ForGroups('common'),
routeParams: [
'country' => new CompoundValues(
new EnumValues(Country::class),
new RawValues('ar'),
),
],
)]
public function petOfTheMonthAction(string $country)
{
}
#[Route('/tag/{tag}', 'animal_tag')]
#[PurgeOn(Animal::class,
target: 'tags',
routeParams: [
'tag' => 'tags',
],
)]
public function tagAction(string $tag)
{
}
#[Route('/for-rating/{rating}', 'animals_with_rating')]
#[PurgeOn(Animal::class,
target: ['measurements'],
routeParams: [
'rating' => new CompoundValues(
new DynamicValues(alias: 'purgatory.animal_rating2'),
new DynamicValues(alias: 'purgatory.animal_rating1'),
new DynamicValues(alias: 'purgatory.animal_rating3', propertyPath: 'owner'),
),
],
)]
#[PurgeOn(Person::class,
target: ['pets'],
routeParams: [
'rating' => new CompoundValues(
new DynamicValues(alias: 'purgatory.animal_rating3'),
),
],
)]
public function animalsForRatingAction(int $rating)
{
}
#[Route('/{id}/owner-details', 'pet_owner_details')]
#[PurgeOn(Person::class,
routeParams: [
'id' => 'pets[*].id',
],
)]
public function petOwnerDetails(Animal $animal)
{
}
#[Route('/{id}/owner-details-alt', 'pet_owner_details_alternative')]
#[PurgeOn(Person::class,
routeParams: [
'id' => 'petsIds',
],
)]
public function petOwnerDetailsAlternative(Animal $animal)
{
}
#[Route('/good-boy-ranking', 'good_boy_ranking')]
#[PurgeOn(Animal::class,
target: new ForProperties(['isGoodBoy']),
)]
public function goodBoyRankingAction()
{
}
#[Route('/for-veterinarian/{id}', 'animals_for_veterinarian')]
#[PurgeOn(Animal::class,
target: 'veterinarian',
routeParams: [
'id' => 'veterinarian?.id',
],
if: 'obj.name === "Sharp Dressed Dog"', // temporary because sf5 does not support optional property accesses
)]
public function animalsForVeterinarianAction(Person $veterinarian)
{
}
#[Route('/for-owner-and-veterinarian/{owner_id}-{vet_id}', 'animals_for_owner_and_veterinarian')]
#[PurgeOn(Animal::class,
target: 'owner',
routeParams: [
'owner_id' => 'owner.id',
'vet_id' => 'veterinarian?.id',
],
if: 'obj.name === "Sharp Dressed Dog"', // temporary because sf5 does not support optional property accesses
)]
public function animalsForOwnerAndVeterinarianAction(Person $veterinarian)
{
}
#[Route('/owner-full-name/{full_name}', 'list_by_owner_full_name')]
#[PurgeOn(Person::class,
target: ['firstName', 'lastName', 'pets'],
routeParams: [
'full_name' => new ExpressionValues('obj.firstName~"-"~obj.lastName'),
],
)]
public function listByOwnerFullName()
{
}
#[Route('/veterinarian-full-name/{full_name}', 'list_by_veterinarian_full_name')]
#[PurgeOn(Person::class,
target: ['firstName', 'lastName', 'animalPatients'],
routeParams: [
'full_name' => new ExpressionValues('obj.firstName~"-"~obj.lastName'),
],
if: 'obj.isVeterinarian === true',
)]
public function listByVeterinarianFullName()
{
}
}