-use Rapsys\UserBundle\Utils\Slugger;
-
-
-class DefaultController {
- use ControllerTrait {
- //Rename render as _render
- render as protected _render;
- }
-
- ///Config array
- protected $config;
-
- ///Context array
- protected $context;
-
- ///Router instance
- protected $router;
-
- ///Translator instance
- protected $translator;
-
- ///Packages instance
- protected $asset;
-
- ///RequestStack instance
- protected $stack;
-
- ///Request instance
- protected $request;
-
- ///Locale instance
- protected $locale;
-
- /**
- * @var ContainerInterface
- */
- protected $container;
-
- ///Facebook image array
- protected $facebookImage = [];
-
- /**
- * Inject container and translator interface
- *
- * @param ContainerInterface $container The container instance
- * @param RouterInterface $router The router instance
- * @param RequestStack $stack The request stack
- * @param TranslatorInterface $translator The translator instance
- */
- public function __construct(ContainerInterface $container, RouterInterface $router, RequestStack $stack, TranslatorInterface $translator, Packages $asset) {
- //Retrieve config
- $this->config = $container->getParameter($this->getAlias());
-
- //Set the container
- $this->container = $container;
-
- //Set the router
- $this->router = $router;
-
- //Set the translator
- $this->translator = $translator;
-
- //Set the asset
- $this->asset = $asset;
-
- //Set the request stack
- $this->stack = $stack;
-
- //Set the context
- $this->context = [
- 'contact' => [
- 'title' => $translator->trans($this->config['contact']['title']),
- 'mail' => $this->config['contact']['mail']
- ],
- 'copy' => [
- 'by' => $translator->trans($this->config['copy']['by']),
- 'link' => $this->config['copy']['link'],
- 'long' => $translator->trans($this->config['copy']['long']),
- 'short' => $translator->trans($this->config['copy']['short']),
- 'title' => $this->config['copy']['title']
- ],
- 'page' => [
- 'description' => null,
- 'section' => null,
- 'title' => null
- ],
- 'site' => [
- 'donate' => $this->config['site']['donate'],
- 'ico' => $this->config['site']['ico'],
- 'logo' => $this->config['site']['logo'],
- 'png' => $this->config['site']['png'],
- 'svg' => $this->config['site']['svg'],
- 'title' => $translator->trans($this->config['site']['title']),
- 'url' => $router->generate($this->config['site']['url'])
- ],
- 'canonical' => null,
- 'alternates' => [],
- 'ogps' => [
- 'type' => 'article',
- 'site_name' => $this->translator->trans($this->config['site']['title'])
- ],
- 'facebooks' => [
- #'admins' => $this->config['facebook']['admins'],
- 'app_id' => $this->config['facebook']['apps']
- ],
- 'forms' => []
- ];
-
- //Get current request
- $this->request = $stack->getCurrentRequest();
-
- //Get current locale
- #$this->locale = $router->getContext()->getParameters()['_locale'];
- $this->locale = $this->request->getLocale();
-
- //Set translator locale
- //XXX: allow LocaleSubscriber on the fly locale change for first page
- $this->translator->setLocale($this->locale);
-
- //Iterate on locales excluding current one
- foreach($this->config['locales'] as $locale) {
- //Set titles
- $titles = [];
-
- //Iterate on other locales
- foreach(array_diff($this->config['locales'], [$locale]) as $other) {
- $titles[$other] = $translator->trans($this->config['languages'][$locale], [], null, $other);
- }
-
- //Get context path
- $path = $router->getContext()->getPathInfo();
-
- //Retrieve route matching path
- $route = $router->match($path);
-
- //Get route name
- $name = $route['_route'];
-
- //Unset route name
- unset($route['_route']);
-
- //With current locale
- if ($locale == $this->locale) {
- //Set locale locales context
- $this->context['canonical'] = $router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL);
- } else {
- //Set locale locales context
- $this->context['alternates'][$locale] = [
- 'absolute' => $router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL),
- 'relative' => $router->generate($name, ['_locale' => $locale]+$route),
- 'title' => implode('/', $titles),
- 'translated' => $translator->trans($this->config['languages'][$locale], [], null, $locale)
- ];
- }
-
- //Add shorter locale
- if (empty($this->context['alternates'][$shortLocale = substr($locale, 0, 2)])) {
- //Set locale locales context
- $this->context['alternates'][$shortLocale] = [
- 'absolute' => $router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL),
- 'relative' => $router->generate($name, ['_locale' => $locale]+$route),
- 'title' => implode('/', $titles),
- 'translated' => $translator->trans($this->config['languages'][$locale], [], null, $locale)
- ];
- }
- }
- }