Skip to content

Commit

Permalink
minor #757 Use AsResource attribute instead of reserved word Resource…
Browse files Browse the repository at this point in the history
… (loic425)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Bug fix?        | could be one day
| New feature?    | no
| BC breaks?      | yes (but only on alpha version)
| Deprecations?   | no
| Related tickets | 
| License         | MIT

`resource` is a reserved word as Soyuka warned me on API CON.
So I think it will be better to use AsResource attribute instead.

if needed I can add an old Resource attribute with class_alias if we do not want to break users using alpha version.
Or maybe just add a not on the UPGRADE.md

I use a ResourceMetadata (old Resource one) object cause I don't wand to make a `new AsResource()` call which is uggly.


Commits
-------

e237fb0 Use AsResource attribute instead of reserved word Resource
f6c99b7 Fix registering resources
f59d970 Fix Documentation
03dc051 Fix Dummy resources
ec60035 Fix attributes resource metadata collection factory
4121839 Fix debug resource command
931101d Fix coding standard
218bdf5 Fix Phpspec tests
  • Loading branch information
lchrusciel authored Oct 23, 2023
2 parents 3449806 + 218bdf5 commit b0646fe
Show file tree
Hide file tree
Showing 77 changed files with 326 additions and 262 deletions.
62 changes: 31 additions & 31 deletions docs/configure_your_operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ There are some basic CRUD operations and more.
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Index;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Index]
class Book implements ResourceInterface
{
Expand Down Expand Up @@ -68,10 +68,10 @@ namespace App\Entity;

use App\Grid\BookGrid;
use Sylius\Component\Resource\Metadata\Index;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
// You can use either the FQCN of your grid
#[Index(grid: BookGrid::class)]
// Or you can use the grid name
Expand Down Expand Up @@ -101,10 +101,10 @@ The iterator for your books will be available as `books.data` or `resources.data
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create]
class Book implements ResourceInterface
{
Expand Down Expand Up @@ -137,10 +137,10 @@ The iterator for your books will be available as `books.data` or `resources.data
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Update;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Update]
class Book implements ResourceInterface
{
Expand Down Expand Up @@ -171,10 +171,10 @@ On your Twig template, these variables are available
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Delete;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Delete]
class Book implements ResourceInterface
{
Expand All @@ -196,10 +196,10 @@ It will configure this route for your `delete` operation.
namespace App\Entity;

use Sylius\Component\Resource\Metadata\BulkDelete;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[BulkDelete]
class Book implements ResourceInterface
{
Expand All @@ -220,11 +220,11 @@ It will configure this route for your `bulk_delete` operation.
```php
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Show;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Show]
class Book implements ResourceInterface
{
Expand Down Expand Up @@ -258,11 +258,11 @@ As an example, we add a `publish` operation to our book resource.
namespace App\Entity;

use Sylius\Component\Resource\Metadata\ApplyStateMachineTransition;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Show;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[ApplyStateMachineTransition(stateMachineTransition: 'publish')]
class Book implements ResourceInterface
{
Expand All @@ -286,10 +286,10 @@ It customizes the path for your operations.
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create(path: 'register')]
class Customer implements ResourceInterface
{
Expand All @@ -309,10 +309,10 @@ It customizes the path for your operations.
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create(shortName: 'register')]
class Customer implements ResourceInterface
{
Expand All @@ -337,12 +337,12 @@ namespace App\Entity;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Index;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Show;
use Sylius\Component\Resource\Metadata\Update;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(templatesDir: 'book')]
#[AsResource(templatesDir: 'book')]
#[Index]
#[Create]
#[Update]
Expand Down Expand Up @@ -371,12 +371,12 @@ use Sylius\Component\Resource\Metadata\BulkDelete;
use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Delete;
use Sylius\Component\Resource\Metadata\Index;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Show;
use Sylius\Component\Resource\Metadata\Update;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(routePrefix: 'admin')]
#[AsResource(routePrefix: 'admin')]
#[Index]
#[Create]
#[Update]
Expand Down Expand Up @@ -409,19 +409,19 @@ use Sylius\Component\Resource\Metadata\BulkDelete;
use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Delete;
use Sylius\Component\Resource\Metadata\Index;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Show;
use Sylius\Component\Resource\Metadata\Update;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(section: 'admin', routePrefix: 'admin')]
#[AsResource(section: 'admin', routePrefix: 'admin')]
#[Index]
#[Create]
#[Update]
#[Delete]
#[BulkDelete]

#[Resource(section: 'shop')]
#[AsResource(section: 'shop')]
#[Index]
#[Show]
class Book implements ResourceInterface
Expand Down Expand Up @@ -451,12 +451,12 @@ use Sylius\Component\Resource\Metadata\BulkDelete;
use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Delete;
use Sylius\Component\Resource\Metadata\Index;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Show;
use Sylius\Component\Resource\Metadata\Update;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(identifier: 'code')]
#[AsResource(identifier: 'code')]
#[Index]
#[Create]
#[Update]
Expand Down Expand Up @@ -484,10 +484,10 @@ It defines the simple vars that you can use on your templates.
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(vars: ['header' => 'Library', 'subheader' => 'Managing your library'])]
#[AsResource(vars: ['header' => 'Library', 'subheader' => 'Managing your library'])]
#[Create(vars: ['subheader' => 'Adding a book'])]
class Book implements ResourceInterface
{
Expand Down
16 changes: 8 additions & 8 deletions docs/configure_your_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ It will configure your entity as a Sylius resource.
```php
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
class Book implements ResourceInterface
{
}
Expand Down Expand Up @@ -75,10 +75,10 @@ It defines the resource name.
```php
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(name: 'cart')]
#[AsResource(name: 'cart')]
class Order implements ResourceInterface
{
}
Expand All @@ -103,10 +103,10 @@ It defines the resource plural name.
```php
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(pluralName: 'library')]
#[AsResource(pluralName: 'library')]
class Book implements ResourceInterface
{
}
Expand All @@ -131,10 +131,10 @@ It defines the simple vars that you can use on your templates.
```php
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource(vars: ['header' => 'Library', 'subheader' => 'Managing your library'])]
#[AsResource(vars: ['header' => 'Library', 'subheader' => 'Managing your library'])]
class Book implements ResourceInterface
{
}
Expand Down
6 changes: 3 additions & 3 deletions docs/redirect.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ declare(strict_types=1);
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Update;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create(redirectToRoute: 'app_book_update')]
#[Update(redirectToRoute: 'app_book_update')]
class Book implements ResourceInterface
Expand Down Expand Up @@ -66,7 +66,7 @@ declare(strict_types=1);
namespace App\Entity;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Update;
use Sylius\Component\Resource\Model\ResourceInterface;

Expand Down
16 changes: 8 additions & 8 deletions docs/resource_factories.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ declare(strict_types=1);
namespace App\Entity\Book;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create(
path: 'authors/{authorId}/books',
factoryMethod: 'createWithCreator',
Expand Down Expand Up @@ -167,10 +167,10 @@ declare(strict_types=1);
namespace App\Entity\Book;

use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create(
path: 'authors/{authorId}/books',
factoryMethod: 'createForAuthor',
Expand All @@ -193,10 +193,10 @@ declare(strict_types=1);
namespace App\Entity\Book;

use App\Factory\BookFactory;use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create(
path: 'authors/{authorId}/books',
# Here we declared the factory to use with its fully classified class name
Expand Down Expand Up @@ -240,10 +240,10 @@ namespace App\Entity\Book;
use App\Entity\Book;
use App\Factory\BookFactory;
use Sylius\Component\Resource\Metadata\Create;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Create(
factory: [BookFactory::class, 'create'],
)]
Expand Down
4 changes: 2 additions & 2 deletions docs/responders.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ Use it on your operation.

namespace App\Entity;

use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Metadata\AsResource;
use Sylius\Component\Resource\Metadata\Show;
use Sylius\Component\Resource\Model\ResourceInterface;

#[Resource]
#[AsResource]
#[Show(
template: 'subscription/show.html.twig',
twigContextFactory: ShowSubscriptionContextFactory::class,
Expand Down
Loading

0 comments on commit b0646fe

Please sign in to comment.