This repository has been archived by the owner on Aug 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing symfony4 structure in test app
- Loading branch information
1 parent
6f3349a
commit 9d63238
Showing
81 changed files
with
885 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file | ||
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. | ||
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration | ||
|
||
###> symfony/framework-bundle ### | ||
APP_ENV=dev | ||
APP_DEBUG=1 | ||
APP_SECRET=EDITME | ||
###< symfony/framework-bundle ### | ||
|
||
###> doctrine/doctrine-bundle ### | ||
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url | ||
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" | ||
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls | ||
DATABASE_URL=mysql://root@127.0.0.1/sylius_rbac_plugin_%kernel.environment%?serverVersion=5.5 | ||
###< doctrine/doctrine-bundle ### | ||
|
||
###> symfony/swiftmailer-bundle ### | ||
# For Gmail as a transport, use: "gmail://username:password@localhost" | ||
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" | ||
# Delivery is disabled by default via "null://localhost" | ||
MAILER_URL=smtp://localhost | ||
###< symfony/swiftmailer-bundle ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file | ||
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. | ||
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration | ||
|
||
###> symfony/framework-bundle ### | ||
APP_ENV=prod | ||
APP_DEBUG=0 | ||
APP_SECRET=EDITME | ||
###< symfony/framework-bundle ### | ||
|
||
###> doctrine/doctrine-bundle ### | ||
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url | ||
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" | ||
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls | ||
DATABASE_URL=mysql://root@127.0.0.1/sylius_rbac_plugin_%kernel.environment%?serverVersion=5.5 | ||
###< doctrine/doctrine-bundle ### | ||
|
||
###> symfony/swiftmailer-bundle ### | ||
# For Gmail as a transport, use: "gmail://username:password@localhost" | ||
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" | ||
# Delivery is disabled by default via "null://localhost" | ||
MAILER_URL=smtp://localhost | ||
###< symfony/swiftmailer-bundle ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file | ||
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production. | ||
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration | ||
|
||
###> symfony/framework-bundle ### | ||
APP_ENV=test | ||
APP_DEBUG=1 | ||
APP_SECRET=EDITME | ||
###< symfony/framework-bundle ### | ||
|
||
###> doctrine/doctrine-bundle ### | ||
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url | ||
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db" | ||
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls | ||
DATABASE_URL=mysql://root@127.0.0.1/sylius_rbac_plugin_%kernel.environment%?serverVersion=5.5 | ||
###< doctrine/doctrine-bundle ### | ||
|
||
###> symfony/swiftmailer-bundle ### | ||
# For Gmail as a transport, use: "gmail://username:password@localhost" | ||
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" | ||
# Delivery is disabled by default via "null://localhost" | ||
MAILER_URL=smtp://localhost | ||
###< symfony/swiftmailer-bundle ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\RbacPlugin\Application; | ||
|
||
use ProxyManager\Proxy\VirtualProxyInterface; | ||
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer; | ||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\Config\Resource\FileResource; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpKernel\Kernel as BaseKernel; | ||
use Symfony\Component\Routing\RouteCollectionBuilder; | ||
|
||
final class Kernel extends BaseKernel | ||
{ | ||
use MicroKernelTrait; | ||
|
||
private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; | ||
|
||
private const IGNORED_SERVICES_DURING_CLEANUP = [ | ||
'kernel', | ||
'http_kernel', | ||
'liip_imagine.mime_type_guesser', | ||
'liip_imagine.extension_guesser', | ||
]; | ||
|
||
public function getCacheDir(): string | ||
{ | ||
return $this->getProjectDir() . '/var/cache/' . $this->environment; | ||
} | ||
|
||
public function getLogDir(): string | ||
{ | ||
return $this->getProjectDir() . '/var/log'; | ||
} | ||
|
||
public function registerBundles(): iterable | ||
{ | ||
$contents = require $this->getProjectDir() . '/config/bundles.php'; | ||
foreach ($contents as $class => $envs) { | ||
if (isset($envs['all']) || isset($envs[$this->environment])) { | ||
yield new $class(); | ||
} | ||
} | ||
} | ||
|
||
public function shutdown(): void | ||
{ | ||
if (!$this->isTestEnvironment()) { | ||
parent::shutdown(); | ||
|
||
return; | ||
} | ||
|
||
if (false === $this->booted) { | ||
return; | ||
} | ||
|
||
$container = $this->getContainer(); | ||
|
||
parent::shutdown(); | ||
|
||
$this->cleanupContainer($container); | ||
} | ||
|
||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void | ||
{ | ||
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php')); | ||
$container->setParameter('container.dumper.inline_class_loader', true); | ||
$confDir = $this->getProjectDir() . '/config'; | ||
|
||
$loader->load($confDir . '/{packages}/*' . self::CONFIG_EXTS, 'glob'); | ||
$loader->load($confDir . '/{packages}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, 'glob'); | ||
$loader->load($confDir . '/{services}' . self::CONFIG_EXTS, 'glob'); | ||
$loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); | ||
} | ||
|
||
protected function configureRoutes(RouteCollectionBuilder $routes): void | ||
{ | ||
$confDir = $this->getProjectDir() . '/config'; | ||
|
||
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); | ||
$routes->import($confDir . '/{routes}/' . $this->environment . '/**/*' . self::CONFIG_EXTS, '/', 'glob'); | ||
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); | ||
} | ||
|
||
protected function getContainerBaseClass(): string | ||
{ | ||
if ($this->isTestEnvironment()) { | ||
return MockerContainer::class; | ||
} | ||
|
||
return parent::getContainerBaseClass(); | ||
} | ||
|
||
private function isTestEnvironment(): bool | ||
{ | ||
return 0 === strpos($this->getEnvironment(), 'test'); | ||
} | ||
|
||
/** | ||
* Remove all container references from all loaded services | ||
*/ | ||
private function cleanupContainer(ContainerInterface $container): void | ||
{ | ||
$containerReflection = new \ReflectionObject($container); | ||
$containerServicesPropertyReflection = $containerReflection->getProperty('services'); | ||
$containerServicesPropertyReflection->setAccessible(true); | ||
|
||
$services = $containerServicesPropertyReflection->getValue($container) ?: []; | ||
foreach ($services as $serviceId => $service) { | ||
if (null === $service) { | ||
continue; | ||
} | ||
|
||
if (in_array($serviceId, self::IGNORED_SERVICES_DURING_CLEANUP, true)) { | ||
continue; | ||
} | ||
|
||
$serviceReflection = new \ReflectionObject($service); | ||
|
||
if ($serviceReflection->implementsInterface(VirtualProxyInterface::class)) { | ||
continue; | ||
} | ||
|
||
$servicePropertiesReflections = $serviceReflection->getProperties(); | ||
$servicePropertiesDefaultValues = $serviceReflection->getDefaultProperties(); | ||
foreach ($servicePropertiesReflections as $servicePropertyReflection) { | ||
$defaultPropertyValue = null; | ||
if (isset($servicePropertiesDefaultValues[$servicePropertyReflection->getName()])) { | ||
$defaultPropertyValue = $servicePropertiesDefaultValues[$servicePropertyReflection->getName()]; | ||
} | ||
|
||
$servicePropertyReflection->setAccessible(true); | ||
$servicePropertyReflection->setValue($service, $defaultPropertyValue); | ||
} | ||
} | ||
|
||
$containerServicesPropertyReflection->setValue($container, null); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.