Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monorepo v6 refactoring: EasySwoole #1440

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"EonX\\EasySchedule\\": "packages/EasySchedule/src",
"EonX\\EasySecurity\\": "packages/EasySecurity/src",
"EonX\\EasySwoole\\": "packages/EasySwoole/src",
"EonX\\EasySwoole\\Bundle\\": "packages/EasySwoole/bundle",
"EonX\\EasyTemplatingBlock\\": "packages/EasyTemplatingBlock/src",
"EonX\\EasyTemplatingBlock\\Bundle\\": "packages/EasyTemplatingBlock/bundle",
"EonX\\EasyTest\\": "packages/EasyTest/src",
Expand Down Expand Up @@ -187,6 +188,8 @@
"EonX\\EasySchedule\\Tests\\": "packages/EasySchedule/tests",
"EonX\\EasySecurity\\Tests\\": "packages/EasySecurity/tests",
"EonX\\EasySwoole\\Tests\\": "packages/EasySwoole/tests",
"EonX\\EasySwoole\\Tests\\Unit\\": "packages/EasySwoole/tests/Unit/src",
"EonX\\EasySwoole\\Tests\\Unit\\Bundle\\": "packages/EasySwoole/tests/Unit/bundle",
"EonX\\EasyTemplatingBlock\\Tests\\": "packages/EasyTemplatingBlock/tests",
"EonX\\EasyTemplatingBlock\\Tests\\Unit\\": "packages/EasyTemplatingBlock/tests/Unit/src",
"EonX\\EasyTemplatingBlock\\Tests\\Unit\\Bundle\\": "packages/EasyTemplatingBlock/tests/Unit/bundle",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler;
namespace EonX\EasySwoole\Bundle\CompilerPass;

use EonX\EasySwoole\Bridge\Doctrine\Coroutine\Enum\CoroutinePdoDriverOption;
use EonX\EasySwoole\Bridge\Doctrine\Coroutine\PDO\CoroutineConnectionFactory;
use EonX\EasySwoole\Doctrine\Enum\CoroutinePdoDriverOption;
use EonX\EasySwoole\Doctrine\Factory\CoroutineConnectionFactory;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

use function Symfony\Component\String\u;

final class AddDoctrineDbalConnectionNameToParamsPass implements CompilerPassInterface
final class AddDoctrineDbalConnectionNameToParamsCompilerPass implements CompilerPassInterface
{
private const CONNECTION_REGEX = '/doctrine.dbal.(.+)_connection/';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler;
namespace EonX\EasySwoole\Bundle\CompilerPass;

use EonX\EasyErrorHandler\Interfaces\ErrorHandlerInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class EasyErrorHandlerPublicPass implements CompilerPassInterface
final class EasyErrorHandlerPublicCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler;
namespace EonX\EasySwoole\Bundle\CompilerPass;

use EonX\EasyBatch\Processors\BatchProcessor;
use EonX\EasySwoole\Bridge\BridgeConstantsInterface;
use EonX\EasySwoole\Bridge\EasyBatch\BatchProcessorResetter;
use EonX\EasySwoole\Bundle\Enum\ConfigParam;
use EonX\EasySwoole\Bundle\Enum\ConfigTag;
use EonX\EasySwoole\EasyBatch\Resetter\BatchProcessorResetter;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

final class ResetEasyBatchProcessorPass implements CompilerPassInterface
final class ResetEasyBatchProcessorCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
Expand All @@ -23,14 +24,14 @@ public function process(ContainerBuilder $container): void

$def = (new Definition(BatchProcessorResetter::class))
->setArgument('$batchProcessor', new Reference(BatchProcessor::class))
->addTag(BridgeConstantsInterface::TAG_APP_STATE_RESETTER);
->addTag(ConfigTag::AppStateResetter->value);

$container->setDefinition(BatchProcessorResetter::class, $def);
}

private function isEnabled(ContainerBuilder $container): bool
{
return $container->hasParameter(BridgeConstantsInterface::PARAM_RESET_EASY_BATCH_PROCESSOR)
&& $container->getParameter(BridgeConstantsInterface::PARAM_RESET_EASY_BATCH_PROCESSOR);
return $container->hasParameter(ConfigParam::ResetEasyBatchProcessor->value)
&& $container->getParameter(ConfigParam::ResetEasyBatchProcessor->value);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler;
namespace EonX\EasySwoole\Bundle\CompilerPass;

use EonX\EasySwoole\Bridge\Symfony\AppStateResetters\SymfonyServicesAppStateResetter;
use EonX\EasySwoole\Common\Resetter\SymfonyServicesAppStateResetter;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class SymfonyServicesResetPass implements CompilerPassInterface
final class SymfonyServicesResetCompilerPass implements CompilerPassInterface
{
private const SERVICES_RESETTER = 'services_resetter';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bridge\Symfony;
namespace EonX\EasySwoole\Bundle;

use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EonX\EasyBugsnag\Interfaces\ClientConfiguratorInterface;
use EonX\EasyLogging\Interfaces\Config\ProcessorConfigProviderInterface;
use EonX\EasySwoole\Bridge\BridgeConstantsInterface;
use EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler\AddDoctrineDbalConnectionNameToParamsPass;
use EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler\EasyErrorHandlerPublicPass;
use EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler\ResetEasyBatchProcessorPass;
use EonX\EasySwoole\Bridge\Symfony\DependencyInjection\Compiler\SymfonyServicesResetPass;
use EonX\EasySwoole\Interfaces\AppStateCheckerInterface;
use EonX\EasySwoole\Interfaces\AppStateInitializerInterface;
use EonX\EasySwoole\Interfaces\AppStateResetterInterface;
use EonX\EasySwoole\Bundle\CompilerPass\AddDoctrineDbalConnectionNameToParamsCompilerPass;
use EonX\EasySwoole\Bundle\CompilerPass\EasyErrorHandlerPublicCompilerPass;
use EonX\EasySwoole\Bundle\CompilerPass\ResetEasyBatchProcessorCompilerPass;
use EonX\EasySwoole\Bundle\CompilerPass\SymfonyServicesResetCompilerPass;
use EonX\EasySwoole\Bundle\Enum\ConfigParam;
use EonX\EasySwoole\Bundle\Enum\ConfigTag;
use EonX\EasySwoole\Common\Checker\AppStateCheckerInterface;
use EonX\EasySwoole\Common\Initializer\AppStateInitializerInterface;
use EonX\EasySwoole\Common\Resetter\AppStateResetterInterface;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
use Symfony\Contracts\Service\ResetInterface;

final class EasySwooleSymfonyBundle extends AbstractBundle
final class EasySwooleBundle extends AbstractBundle
{
private const ACCESS_LOG_CONFIG = [
'do_not_log_paths' => BridgeConstantsInterface::PARAM_ACCESS_LOG_DO_NOT_LOG_PATHS,
'timezone' => BridgeConstantsInterface::PARAM_ACCESS_LOG_TIMEZONE,
'do_not_log_paths' => ConfigParam::AccessLogDoNotLogPaths,
'timezone' => ConfigParam::AccessLogTimezone,
];

private const DOCTRINE_CONFIG = [
'reset_dbal_connections' => BridgeConstantsInterface::PARAM_RESET_DOCTRINE_DBAL_CONNECTIONS,
'reset_dbal_connections' => ConfigParam::ResetDoctrineDbalConnections,
];

private const DOCTRINE_COROUTINE_PDO_CONFIG = [
'default_heartbeat' => BridgeConstantsInterface::PARAM_DOCTRINE_COROUTINE_PDO_DEFAULT_HEARTBEAT,
'default_max_idle_time' => BridgeConstantsInterface::PARAM_DOCTRINE_COROUTINE_PDO_DEFAULT_MAX_IDLE_TIME,
'default_pool_size' => BridgeConstantsInterface::PARAM_DOCTRINE_COROUTINE_PDO_DEFAULT_POOL_SIZE,
'default_heartbeat' => ConfigParam::DoctrineCoroutinePdoDefaultHeartbeat,
'default_max_idle_time' => ConfigParam::DoctrineCoroutinePdoDefaultMaxIdleTime,
'default_pool_size' => ConfigParam::DoctrineCoroutinePdoDefaultPoolSize,
];

private const EASY_BATCH_CONFIG = [
'reset_batch_processor' => BridgeConstantsInterface::PARAM_RESET_EASY_BATCH_PROCESSOR,
'reset_batch_processor' => ConfigParam::ResetEasyBatchProcessor,
];

private const REQUEST_LIMITS_CONFIG = [
'max' => BridgeConstantsInterface::PARAM_REQUEST_LIMITS_MAX,
'min' => BridgeConstantsInterface::PARAM_REQUEST_LIMITS_MIN,
'max' => ConfigParam::RequestLimitsMax,
'min' => ConfigParam::RequestLimitsMin,
];

private const STATIC_PHP_FILES_CONFIG = [
'allowed_dirs' => BridgeConstantsInterface::PARAM_STATIC_PHP_FILES_ALLOWED_DIRS,
'allowed_filenames' => BridgeConstantsInterface::PARAM_STATIC_PHP_FILES_ALLOWED_FILENAMES,
'allowed_dirs' => ConfigParam::StaticPhpFilesAllowedDirs,
'allowed_filenames' => ConfigParam::StaticPhpFilesAllowedFilenames,
];

protected string $extensionAlias = 'easy_swoole';

public function __construct()
{
$this->path = \realpath(__DIR__);
Expand All @@ -62,107 +61,107 @@ public function __construct()
public function build(ContainerBuilder $container): void
{
$container
->addCompilerPass(new AddDoctrineDbalConnectionNameToParamsPass())
->addCompilerPass(new EasyErrorHandlerPublicPass())
->addCompilerPass(new ResetEasyBatchProcessorPass())
->addCompilerPass(new SymfonyServicesResetPass(), priority: -33);
->addCompilerPass(new AddDoctrineDbalConnectionNameToParamsCompilerPass())
->addCompilerPass(new EasyErrorHandlerPublicCompilerPass())
->addCompilerPass(new ResetEasyBatchProcessorCompilerPass())
->addCompilerPass(new SymfonyServicesResetCompilerPass(), priority: -33);
}

public function configure(DefinitionConfigurator $definition): void
{
$definition->import(__DIR__ . '/Resources/config/definition.php');
$definition->import('config/definition.php');
}

public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$container->import(__DIR__ . '/Resources/config/services.php');
$container->import('config/services.php');

$builder
->registerForAutoconfiguration(AppStateCheckerInterface::class)
->addTag(BridgeConstantsInterface::TAG_APP_STATE_CHECKER);
->addTag(ConfigTag::AppStateChecker->value);

$builder
->registerForAutoconfiguration(AppStateInitializerInterface::class)
->addTag(BridgeConstantsInterface::TAG_APP_STATE_INITIALIZER);
->addTag(ConfigTag::AppStateInitializer->value);

$builder
->registerForAutoconfiguration(AppStateResetterInterface::class)
->addTag(BridgeConstantsInterface::TAG_APP_STATE_RESETTER);
->addTag(ConfigTag::AppStateResetter->value);

if ($config['access_log']['enabled'] ?? true) {
foreach (self::ACCESS_LOG_CONFIG as $configName => $param) {
$container
->parameters()
->set($param, $config['access_log'][$configName]);
->set($param->value, $config['access_log'][$configName]);
}

$container->import(__DIR__ . '/Resources/config/access_log.php');
$container->import('config/access_log.php');
}

if (($config['doctrine']['enabled'] ?? true) && \interface_exists(ManagerRegistry::class)) {
foreach (self::DOCTRINE_CONFIG as $configName => $param) {
$container
->parameters()
->set($param, $config['doctrine'][$configName]);
->set($param->value, $config['doctrine'][$configName]);
}

if ($config['doctrine']['coroutine_pdo']['enabled'] ?? false) {
foreach (self::DOCTRINE_COROUTINE_PDO_CONFIG as $configName => $param) {
$container
->parameters()
->set($param, $config['doctrine']['coroutine_pdo'][$configName]);
->set($param->value, $config['doctrine']['coroutine_pdo'][$configName]);
}

$container->import(__DIR__ . '/Resources/config/doctrine_coroutine_pdo.php');
$container->import('config/doctrine_coroutine_pdo.php');
}

$container->import(__DIR__ . '/Resources/config/doctrine.php');
$container->import('config/doctrine.php');
}

if (($config['easy_admin']['enabled'] ?? true) && \class_exists(EA::class)) {
$container->import(__DIR__ . '/Resources/config/easy_admin.php');
$container->import('config/easy_admin.php');
}

if ($config['easy_batch']['enabled'] ?? true) {
foreach (self::EASY_BATCH_CONFIG as $configName => $param) {
$container
->parameters()
->set($param, $config['easy_batch'][$configName]);
->set($param->value, $config['easy_batch'][$configName]);
}
}

if (($config['easy_bugsnag']['enabled'] ?? true)
&& \interface_exists(ClientConfiguratorInterface::class)) {
$container->import(__DIR__ . '/Resources/config/easy_bugsnag.php');
$container->import('config/easy_bugsnag.php');
}

if (($config['easy_logging']['enabled'] ?? true)
&& \interface_exists(ProcessorConfigProviderInterface::class)) {
$container->import(__DIR__ . '/Resources/config/easy_logging.php');
$container->import('config/easy_logging.php');
}

if ($config['request_limits']['enabled'] ?? true) {
foreach (self::REQUEST_LIMITS_CONFIG as $configName => $param) {
$container
->parameters()
->set($param, $config['request_limits'][$configName]);
->set($param->value, $config['request_limits'][$configName]);
}

$container->import(__DIR__ . '/Resources/config/request_limits.php');
$container->import('config/request_limits.php');
}

if (($config['reset_services']['enabled'] ?? true) && \interface_exists(ResetInterface::class)) {
$container->import(__DIR__ . '/Resources/config/reset_services.php');
$container->import('config/reset_services.php');
}

if ($config['static_php_files']['enabled'] ?? false) {
foreach (self::STATIC_PHP_FILES_CONFIG as $configName => $param) {
$container
->parameters()
->set($param, $config['static_php_files'][$configName]);
->set($param->value, $config['static_php_files'][$configName]);
}

$container->import(__DIR__ . '/Resources/config/static_php_files.php');
$container->import('config/static_php_files.php');
}
}
}
29 changes: 29 additions & 0 deletions packages/EasySwoole/bundle/Enum/ConfigParam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bundle\Enum;

enum ConfigParam: string
{
case AccessLogDoNotLogPaths = 'easy_swoole.access_log_do_not_log_paths';

case AccessLogTimezone = 'easy_swoole.access_log_timezone';

case DoctrineCoroutinePdoDefaultHeartbeat = 'easy_swoole.doctrine.coroutine_pdo.default_heartbeat';

case DoctrineCoroutinePdoDefaultMaxIdleTime = 'easy_swoole.doctrine.coroutine_pdo.default_max_idle_time';

case DoctrineCoroutinePdoDefaultPoolSize = 'easy_swoole.doctrine.coroutine_pdo.default_pool_size';

case RequestLimitsMax = 'easy_swoole.request_limits.max';

case RequestLimitsMin = 'easy_swoole.request_limits.min';

case ResetDoctrineDbalConnections = 'easy_swoole.reset_doctrine_dbal_connections';

case ResetEasyBatchProcessor = 'easy_swoole.reset_easy_batch_processor';

case StaticPhpFilesAllowedDirs = 'easy_swoole.static_php_files_allowed_dirs';

case StaticPhpFilesAllowedFilenames = 'easy_swoole.static_php_files_allowed_filenames';
}
11 changes: 11 additions & 0 deletions packages/EasySwoole/bundle/Enum/ConfigServiceId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bundle\Enum;

enum ConfigServiceId: string
{
case AccessLogLogger = 'easy_swoole.access_log_logger';

case Filesystem = 'easy_swoole.filesystem';
}
13 changes: 13 additions & 0 deletions packages/EasySwoole/bundle/Enum/ConfigTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace EonX\EasySwoole\Bundle\Enum;

enum ConfigTag: string
{
case AppStateChecker = 'easy_swoole.app_state_checker';

case AppStateInitializer = 'easy_swoole.app_state_initializer';

case AppStateResetter = 'easy_swoole.app_state_resetter';
}
Loading