src/Kernel.php line 147

Open in your IDE?
  1. <?php
  2.     namespace App;
  3.     use Exception;
  4.     use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  5.     use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
  6.     use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  7.     use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  8.     use function dirname;
  9.     class Kernel extends BaseKernel
  10.     {
  11.         use MicroKernelTrait;
  12.         /**
  13.          * Chaque platform a son propre cache
  14.          *
  15.          * @return string
  16.          *
  17.          * @throws Exception
  18.          */
  19.         public function getCacheDir(): string
  20.         {
  21.             return dirname__DIR__ ) . '/var/cache/' $this->environment '/' $this->getDomain();
  22.         }
  23.         /**
  24.          * Chaque platform a ses propres logs
  25.          *
  26.          * @return string
  27.          * @throws Exception
  28.          */
  29.         public function getLogDir(): string
  30.         {
  31.             return dirname__DIR__ ) . '/var/log/' $this->getDomain();
  32.         }
  33.         public function boot()
  34.         {
  35.             parent::boot();
  36.             StaticContainer::init($this->getContainer());
  37.         }
  38.         /**
  39.          * @param ContainerConfigurator $container
  40.          *
  41.          * @return void
  42.          * @throws Exception
  43.          */
  44.         protected function configureContainerContainerConfigurator $container ): void
  45.         {
  46.             $container->importdirname__DIR__ ) . '/config/{packages}/*.yaml' );
  47.             $container->importdirname__DIR__ ) . '/config/{packages}/' $this->environment '/*.yaml' );
  48.             if ( is_filedirname__DIR__ ) . '/config/services.yaml' ) ) {
  49.                 $folder 'platform';
  50.                 // Utilise le dossier ".loc" si on est en local
  51.                 $data explode'.'$this->getDomain() );
  52.                 if ( end$data ) == 'loc' ) {
  53.                     $folder 'platform.loc';
  54.                 }
  55.                 elseif ( end$data ) == '__test' ) {
  56.                     $folder 'tests/platform';
  57.                 }
  58.                 // fin
  59.                 $container->importdirname__DIR__ ) . '/config/services.yaml' );
  60.                 // Importe les réglages d'une platform depuis l'url déduite
  61.                 $configFile dirname__DIR__ ) . "/config/$folder/" $this->getDomain() . ".yaml";
  62.                 if ( !is_file$configFile ) ) {
  63.                     $src dirname__DIR__ ) . "/config/_platform_dtv/default.yaml";
  64.                     copy$src$configFile );
  65.                 }
  66.                 $container->import$configFile );
  67.                 $container->importdirname__DIR__ ) . '/config/{services}_' $this->environment '.yaml' );
  68.             }
  69.             elseif ( is_file$path dirname__DIR__ ) . '/config/services.php' ) ) {
  70.                 ( require $path )( $container->withPath$path ), $this );
  71.             }
  72.         }
  73.         /**
  74.          * Déduit le domain depuis l'url
  75.          *
  76.          * @return mixed|string
  77.          * @throws Exception
  78.          */
  79.         private function getDomain()
  80.         {
  81.             // On check si on est dans une commande
  82.             if ( !isset( $_SERVER'HTTP_HOST' ] ) && count$_SERVER'argv' ] ) > ) {
  83.                 // Check que l'on est dans une commande bin/console
  84.                 if ( str_contains$_SERVER'argv' ][ ], 'bin/console' ) && array_key_exists1$_SERVER'argv' ] ) ) {
  85.                     $re '/^dtv:.*$/';
  86.                     preg_match$re$_SERVER'argv' ][ ], $matchesPREG_OFFSET_CAPTURE );
  87.                     // Check que l'on est dans une commande DTV
  88.                     if ( count$matches ) > ) {
  89.                         if ( !array_key_exists2$_SERVER'argv' ] ) ) {
  90.                             throw new Exception'Aucun subdomain trouvé dans la commande' );
  91.                         }
  92.                         return $_SERVER'argv' ][ ];
  93.                     }
  94.                 }
  95.                 // La clé DTV_PLATFORM est utilisé pour les tests unitaires
  96.                 // Check que l'on lance notre commande de tests unitaires
  97.                 elseif ( array_key_exists'DTV_PLATFORM'$_SERVER ) ) {
  98.                     return $_SERVER'DTV_PLATFORM' ];
  99.                 }
  100.                 // @TODO Erreur pour les  migrations d'acl en local,
  101.                 // @TODO il prend le mauvais yaml : celui dans platform au lieu de platform.loc
  102.                 return 'developpetesventes.com';
  103.             } //Si il n'y as pas de HOST
  104.             elseif ( !isset( $_SERVER'HTTP_HOST' ] ) ) {
  105.                 return 'developpetesventes.com';
  106.             }
  107.             // On retire le www.
  108.             if ( strpos$_SERVER'HTTP_HOST' ], 'www.' ) === ) {
  109.                 $subdomain substr$_SERVER'HTTP_HOST' ], );
  110.             }
  111.             else {
  112.                 $subdomain $_SERVER'HTTP_HOST' ];
  113.             }
  114.             return $subdomain;
  115.         }
  116.         /**
  117.          * @param RoutingConfigurator $routes
  118.          *
  119.          * @return void
  120.          */
  121.         protected function configureRoutesRoutingConfigurator $routes ): void
  122.         {
  123.             $routes->importdirname__DIR__ ) . '/config/{routes}/' $this->environment '/*.yaml' );
  124.             $routes->importdirname__DIR__ ) . '/config/{routes}/*.yaml' );
  125.             if ( is_filedirname__DIR__ ) . '/config/routes.yaml' ) ) {
  126.                 $routes->importdirname__DIR__ ) . '/config/routes.yaml' );
  127.             }
  128.             elseif ( is_file$path dirname__DIR__ ) . '/config/routes.php' ) ) {
  129.                 ( require $path )( $routes->withPath$path ), $this );
  130.             }
  131.         }
  132.     }