|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?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;
- }
- }
|