|
- <?php
-
- namespace Lc\ShopBundle\Routing;
-
- use Lc\ShopBundle\Model\Address;
- use Symfony\Component\Config\Loader\Loader;
- use Symfony\Component\Routing\Route;
- use Symfony\Component\Routing\RouteCollection;
-
- class CrudLoader extends Loader
- {
- private $isLoaded = false;
-
- public function load($resource, $type = null)
- {
- if (true === $this->isLoaded) {
- throw new \RuntimeException('Do not add the "extra" loader twice');
- }
-
- $routes = new RouteCollection();
- $lcShopRoutes = array(
- 'address' => "Address",
- "cart" => "Cart",
- "credit_config" => "CreditConfig",
- "document_nelivery_note" => "DocumentDeliveryNote",
- "document_quotation" => "DocumentQuotation",
- "document_invoice" => "DocumentInvoice",
- "merchant" => "Merchant",
- "merchant_config" => "MerchantConfig",
-
- "point_sale" => "PointSale",
- "tax_rate" => "TaxRate",
- "product" => "Products"
- );
- $actions = [
- 'index' => 'indexAction',
- 'edit' => 'editAction',
- 'delete' => 'deleteAction',
- 'show' => 'showAction'
- ];
-
- foreach ($lcShopRoutes as $entity => $controller) {
- foreach ($actions as $actionName => $action) {
- if ($actionName == 'edit' || $actionName == 'delete' || $actionName == "show") {
- $path = '/' . $entity . '/' . $actionName . '/{id}';
- } else {
- $path = '/' . $entity . '/' . $actionName;
- }
- $defaults = [
- '_controller' => 'Lc\ShopBundle\Controller\\' . $controller . 'Controller::' . $action
- ];
- $requirements = [
- 'parameter' => '\d+',
- ];
- $route = new Route($path, $defaults, $requirements);
-
- $routeName = 'lc_shop_' . $entity . '_' . $actionName;
-
- $routes->add($routeName, $route);
-
- }
- }
- $this->isLoaded = true;
- return $routes;
- }
-
-
- public function supports($resource, $type = null)
- {
- return 'crud' === $type;
- }
- }
|