src/Support/SilexAppProxy.php line 22

Open in your IDE?
  1. <?php
  2. namespace Support;
  3. use Doctrine\DBAL\Connection;
  4. use Flagship\Components\Entities\Attribute\Services\Attributes;
  5. use Flagship\Components\Entities\CreditCard\Services\MonerisService;
  6. use Flagship\Components\Entities\Invoicing\Services\AccountingService;
  7. use Psr\Log\LoggerInterface;
  8. use Silex\Application;
  9. use Symfony\Component\Form\FormFactoryInterface;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. use Symfony\Component\Security\Core\Security;
  14. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. use Twig\Environment;
  17. use Shipping\Services\ShipSessionDataManager;
  18. use User\Objects\UserProvider;
  19. class SilexAppProxy extends Application
  20. {
  21.     protected Application $app;
  22.     public function __construct(
  23.         Connection $db,
  24.         protected Security $security,
  25.         ?UrlGeneratorInterface $urlGenerator,
  26.         Environment $twig,
  27.         FormFactoryInterface $formFactory,
  28.         TranslatorInterface $translator,
  29.         EventDispatcherInterface $dispatcher,
  30.         TokenStorageInterface $tokenStorage,
  31.         RequestStack $requestStack,
  32.         ShipSessionDataManager $dataManager,
  33.         UserProvider $userProvider,
  34.         AccountingService $accountingService,
  35.         MonerisService $monerisService,
  36.         Connection $logDb,
  37.         LoggerInterface $logger,
  38.         array $monerisCredentials,
  39.         string $projectRoot,
  40.         string $env
  41.     ) {
  42.         $app = new Application();
  43.         $this->app $app;
  44.         $this->app['db'] = $db;
  45.         $this->app['session'] = $requestStack->getSession();
  46.         $this->app['security.token_storage'] = $tokenStorage;
  47.         $this->app['security'] = $security;
  48.         $this->app['url_generator'] = $urlGenerator;
  49.         $this->app['twig'] = $twig;
  50.         $this->app['form.factory'] = $formFactory;
  51.         $this->app['translator'] = $translator;
  52.         $this->app['dispatcher'] = $dispatcher;
  53.         $this->app['user'] = fn () => $security->getUser();
  54.         $this->app['request_stack'] = $requestStack;
  55.         $this->app['shipping.services.session_data_manager'] = $dataManager;
  56.         $this->app['security.user_provider.secured'] = $userProvider;
  57.         $this->app['smartship.attributes'] = Attributes::getInstance();
  58.         $this->app['invoicing.services.accounting'] = $accountingService;
  59.         // $this->app['dbs'] = ['logging' => $logDb];
  60.         if ('prod' !== $env) {
  61.             $this->app['swiftmailer.delivery_address'] = $_ENV['MAIL_SINK'];
  62.         }
  63.         require $projectRoot.'/src/app.php';
  64.         require $projectRoot.'/config/'.$env.'.php';
  65.         // require $projectRoot.'/src/controllers.php';
  66.         // Service overrides
  67.         $app['moneris_credentials'] = $monerisCredentials;
  68.         $app['payment.service.credit_card'] = $monerisService;
  69.         $this->app['twig'] = $twig;
  70.         $this->app['monolog'] = $logger;
  71.     }
  72.     public function __call($name$args)
  73.     {
  74.         return call_user_func_array([$this->app$name], $args);
  75.     }
  76.     public function offsetGet($id)
  77.     {
  78.         // The user cannot be retrieved early enough to put it in the constructor
  79.         // if ('user' === $id) {
  80.         //     return $this->security->getUser();
  81.         // }
  82.         return $this->app[$id];
  83.     }
  84.     public function offsetSet($id$value)
  85.     {
  86.         $this->app->offsetSet($id$value);
  87.     }
  88.     public function offsetUnset($id)
  89.     {
  90.         return $this->app->offsetUnset($id);
  91.     }
  92. }