<?php
namespace Support;
use Doctrine\DBAL\Connection;
use Flagship\Components\Entities\Attribute\Services\Attributes;
use Flagship\Components\Entities\CreditCard\Services\MonerisService;
use Flagship\Components\Entities\Invoicing\Services\AccountingService;
use Psr\Log\LoggerInterface;
use Silex\Application;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use Shipping\Services\ShipSessionDataManager;
use User\Objects\UserProvider;
class SilexAppProxy extends Application
{
protected Application $app;
public function __construct(
Connection $db,
protected Security $security,
?UrlGeneratorInterface $urlGenerator,
Environment $twig,
FormFactoryInterface $formFactory,
TranslatorInterface $translator,
EventDispatcherInterface $dispatcher,
TokenStorageInterface $tokenStorage,
RequestStack $requestStack,
ShipSessionDataManager $dataManager,
UserProvider $userProvider,
AccountingService $accountingService,
MonerisService $monerisService,
Connection $logDb,
LoggerInterface $logger,
array $monerisCredentials,
string $projectRoot,
string $env
) {
$app = new Application();
$this->app = $app;
$this->app['db'] = $db;
$this->app['session'] = $requestStack->getSession();
$this->app['security.token_storage'] = $tokenStorage;
$this->app['security'] = $security;
$this->app['url_generator'] = $urlGenerator;
$this->app['twig'] = $twig;
$this->app['form.factory'] = $formFactory;
$this->app['translator'] = $translator;
$this->app['dispatcher'] = $dispatcher;
$this->app['user'] = fn () => $security->getUser();
$this->app['request_stack'] = $requestStack;
$this->app['shipping.services.session_data_manager'] = $dataManager;
$this->app['security.user_provider.secured'] = $userProvider;
$this->app['smartship.attributes'] = Attributes::getInstance();
$this->app['invoicing.services.accounting'] = $accountingService;
// $this->app['dbs'] = ['logging' => $logDb];
if ('prod' !== $env) {
$this->app['swiftmailer.delivery_address'] = $_ENV['MAIL_SINK'];
}
require $projectRoot.'/src/app.php';
require $projectRoot.'/config/'.$env.'.php';
// require $projectRoot.'/src/controllers.php';
// Service overrides
$app['moneris_credentials'] = $monerisCredentials;
$app['payment.service.credit_card'] = $monerisService;
$this->app['twig'] = $twig;
$this->app['monolog'] = $logger;
}
public function __call($name, $args)
{
return call_user_func_array([$this->app, $name], $args);
}
public function offsetGet($id)
{
// The user cannot be retrieved early enough to put it in the constructor
// if ('user' === $id) {
// return $this->security->getUser();
// }
return $this->app[$id];
}
public function offsetSet($id, $value)
{
$this->app->offsetSet($id, $value);
}
public function offsetUnset($id)
{
return $this->app->offsetUnset($id);
}
}