Skip to content

Commit

Permalink
Change routeScope
Browse files Browse the repository at this point in the history
  • Loading branch information
Isengo1989 committed Dec 18, 2023
1 parent 2af0b74 commit 8c96a12
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 49 deletions.
4 changes: 1 addition & 3 deletions guides/plugins/plugins/checkout/cart/add-cart-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ use Shopware\Storefront\Framework\Routing\StorefrontResponse;
use Symfony\Component\Routing\Annotation\Route;
use Shopware\Core\Checkout\Cart\Cart;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
private LineItemFactoryRegistry $factory;
Expand Down
4 changes: 1 addition & 3 deletions guides/plugins/plugins/content/seo/add-custom-seo-url.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
#[Route(path: '/example', name: 'frontend.example.example', methods: ['GET'])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ namespace Swag\BasicExample\Core\Content\Example\SalesChannel;
use Shopware\Core\Framework\RateLimiter\RateLimiter;
...
/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
#[Route(defaults: ['_routeScope' => ['store-api']])]
class ExampleRoute extends AbstractExampleRoute
{
private RateLimiter $rateLimiter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
#[Route(defaults: ['_routeScope' => ['store-api']])]
class CachedExampleRoute extends AbstractExampleRoute
{
private AbstractExampleRoute $decorated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ use Shopware\Core\Framework\Routing\Annotation\Entity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
#[Route(defaults: ['_routeScope' => ['store-api']])]
class ExampleRoute extends AbstractExampleRoute
{
protected EntityRepository $exampleRepository;
Expand Down Expand Up @@ -315,9 +313,7 @@ use Swag\BasicExample\Core\Content\Example\SalesChannel\AbstractExampleRoute;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
private AbstractExampleRoute $route;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ use Shopware\Core\Framework\Routing\Annotation\Entity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
#[Route(defaults: ['_routeScope' => ['store-api']])]
class ExampleRouteDecorator extends AbstractExampleRoute
{
protected EntityRepository $exampleRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{

Expand Down
16 changes: 4 additions & 12 deletions guides/plugins/plugins/storefront/add-custom-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ namespace Swag\BasicExample\Storefront\Controller;

use Shopware\Storefront\Controller\StorefrontController;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
}
Expand All @@ -63,9 +61,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
#[Route(path: '/example', name: 'frontend.example.example', methods: ['GET'])]
Expand Down Expand Up @@ -96,9 +92,7 @@ use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
#[Route(path: '/example', name: 'frontend.example.example', methods: ['GET'], defaults: ['_routeScope' => 'storefront'])]
Expand Down Expand Up @@ -185,9 +179,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
#[Route(path: '/example', name: 'frontend.example.example', methods: ['GET'])]
Expand Down
4 changes: 1 addition & 3 deletions guides/plugins/plugins/storefront/add-custom-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
#[Route(path: '/example-page', name: 'frontend.example.page', methods: ['GET'])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
#[Route(defaults: ['_routeScope' => ['store-api']])]
abstract class AbstractProductCountRoute
{
abstract public function getDecorated(): AbstractProductCountRoute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
#[Route(defaults: ['_routeScope' => ['storefront']])]
class ExampleController extends StorefrontController
{
#[Route(path: '/example', name: 'frontend.example.example', methods: ['GET'], defaults: ['XmlHttpRequest' => 'true'])]
Expand Down
7 changes: 3 additions & 4 deletions resources/guidelines/code/storefront-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ nav:

## Controller

* Each controller action has to be declared with a `@Since` tag.
* Each controller action requires a `@Route` annotation.
* Each controller action requires a `#Route` attribute.
* The name of the route should start with "frontend".
* Each route should define the corresponding HTTP Method \(GET, POST, DELETE, PATCH\).
* The function name should be concise.
Expand All @@ -19,7 +18,7 @@ nav:
* Use Symfony flash bags for error reporting.
* Each storefront functionality has to be available inside the Store API too.
* A Storefront controller should never contain business logic.
* The class requires the annotation: `@Route(defaults={"_routeScope"={"storefront"}})`.
* The class requires the attribute: `#[Route(defaults: ['_routeScope' => ['storefront']])]`.
* Depending services have to be injected over the class constructor.
* Depending services have to be defined in the DI-Container service definition.
* Depending services have to be assigned to a private class property.
Expand All @@ -29,7 +28,7 @@ nav:

* A Storefront controller should never use a repository directly. The data should be fetched over a route or page loader.
* Routes that load a full Storefront page should use a page loader class to load all corresponding data.
* Pages that contain data that are the same for all customers should have the `@HttpCache` annotation.
* Pages that contain data that are the same for all customers should have the `_httpCache` annotation.

## Write operations inside Storefront controllers

Expand Down

0 comments on commit 8c96a12

Please sign in to comment.