-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Rewrite services to use more compiler passes, use more conc…
…at_paths
- Loading branch information
1 parent
8b91c4c
commit 97da220
Showing
23 changed files
with
251 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
<?php | ||
|
||
use VerteXVaaR\BlueSprints\Utility\Context; | ||
|
||
return [ | ||
'permissions' => [ | ||
'files' => 0660, | ||
'folders' => 0770, | ||
], | ||
'context' => Context::CONTEXT_DEVELOPMENT, | ||
]; |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
|
||
namespace PHPSTORM_META { | ||
override(\Symfony\Component\DependencyInjection\Container::get(), type(0)); | ||
override(\VerteXVaaR\BlueSprints\Mvc\Repository::findByUuid(), type(0)); | ||
override(\VerteXVaaR\BlueSprints\Mvc\Repository::findAll(), map(['' => '@[]'])); | ||
} |
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 |
---|---|---|
@@ -1,74 +1,22 @@ | ||
<?php | ||
|
||
use Composer\Composer; | ||
use Composer\Package\Package; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use VerteXVaaR\BlueContainer\Helper\PackageIterator; | ||
use VerteXVaaR\BlueSprints\Config; | ||
use VerteXVaaR\BlueSprints\Http\Server\Middleware\MiddlewareRegistry; | ||
use VerteXVaaR\BlueSprints\Environment\DependencyInjection\ConfigCompilerPass; | ||
use VerteXVaaR\BlueSprints\Environment\DependencyInjection\EnvironmentCompilerPass; | ||
use VerteXVaaR\BlueSprints\Environment\DependencyInjection\PathsCompilerPass; | ||
use VerteXVaaR\BlueSprints\Http\DependencyInjection\MiddlewareCompilerPass; | ||
use VerteXVaaR\BlueSprints\Mvc\Controller; | ||
use VerteXVaaR\BlueSprints\Mvc\DependencyInjection\PublicServicePass; | ||
use VerteXVaaR\BlueSprints\Paths; | ||
use VerteXVaaR\BlueSprints\Routing\DependencyInjection\RouteCollectorCompilerPass; | ||
|
||
return static function (ContainerBuilder $containerBuilder): void { | ||
/** @var Composer $composer */ | ||
$composer = $containerBuilder->get('composer'); | ||
return static function (ContainerBuilder $container): void { | ||
$container->addCompilerPass(new EnvironmentCompilerPass()); | ||
$container->addCompilerPass(new PathsCompilerPass()); | ||
$container->addCompilerPass(new ConfigCompilerPass()); | ||
$container->addCompilerPass(new MiddlewareCompilerPass()); | ||
$container->addCompilerPass(new RouteCollectorCompilerPass()); | ||
|
||
$packageIterator = new PackageIterator($composer); | ||
$middlewares = $packageIterator->iterate(static function (Package $package, string $installPath): array { | ||
$middlewares = []; | ||
if (file_exists($installPath . '/config/middlewares.php')) { | ||
$packageMiddlewares = require $installPath . '/config/middlewares.php'; | ||
foreach ($packageMiddlewares as $packageMiddleware) { | ||
$middlewares[] = new Reference($packageMiddleware['service']); | ||
} | ||
} | ||
return $middlewares; | ||
}); | ||
|
||
$packageConfig = $composer->getPackage()->getConfig(); | ||
$config = $packageConfig['vertexvaar/bluesprints']; | ||
$pathsDefinition = $containerBuilder->getDefinition(Paths::class); | ||
$pathsDefinition->setArguments([ | ||
'$logs' => $config['logs'] ?? 'var/logs', | ||
'$locks' => $config['locks'] ?? 'var/locks', | ||
'$cache' => $config['cache'] ?? 'var/cache', | ||
'$database' => $config['database'] ?? 'var/database', | ||
'$config' => $config['config'] ?? 'config', | ||
'$view' => $config['view'] ?? 'view', | ||
'$translations' => $config['translations'] ?? 'translations', | ||
]); | ||
$pathsDefinition->setShared(true); | ||
$pathsDefinition->setPublic(true); | ||
|
||
$systemSettings = []; | ||
if (file_exists('config/system.php')) { | ||
$systemSettings = require 'config/system.php'; | ||
} | ||
$configDefinition = $containerBuilder->getDefinition(Config::class); | ||
$configDefinition->setArguments([ | ||
'$filePermissions' => $config['permissions']['files'] ?? 0660, | ||
'$folderPermissions' => $config['permissions']['folders'] ?? 0770, | ||
]); | ||
$configDefinition->setShared(true); | ||
$configDefinition->setPublic(true); | ||
|
||
$packageMiddlewares = []; | ||
$middlewaresPath = $pathsDefinition->getArgument('$config') . '/middlewares.php'; | ||
if (file_exists($middlewaresPath)) { | ||
$packageMiddlewares = require $middlewaresPath; | ||
} | ||
|
||
$middlewares = array_replace($packageMiddlewares, ...$middlewares); | ||
|
||
$registry = $containerBuilder->getDefinition(MiddlewareRegistry::class); | ||
$registry->setArgument('$middlewares', $middlewares); | ||
|
||
$containerBuilder->addCompilerPass(new RouteCollectorCompilerPass()); | ||
|
||
$containerBuilder->registerForAutoconfiguration(Controller::class) | ||
$container->registerForAutoconfiguration(Controller::class) | ||
->addTag('vertexvaar.bluesprints.controller'); | ||
$containerBuilder->addCompilerPass(new PublicServicePass('vertexvaar.bluesprints.controller')); | ||
$container->addCompilerPass(new PublicServicePass('vertexvaar.bluesprints.controller')); | ||
}; |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueSprints\Environment; | ||
|
||
use JetBrains\PhpStorm\Pure; | ||
|
||
use function str_starts_with; | ||
use function strtolower; | ||
|
||
enum Context | ||
{ | ||
case Production; | ||
case Development; | ||
|
||
#[Pure] | ||
public static function fromString(string $context): Context | ||
{ | ||
if (str_starts_with(strtolower($context), 'dev')) { | ||
return self::Development; | ||
} | ||
return self::Production; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/bluesprints/src/Environment/DependencyInjection/ConfigCompilerPass.php
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueSprints\Environment\DependencyInjection; | ||
|
||
use Composer\Composer; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use VerteXVaaR\BlueSprints\Environment\Config; | ||
|
||
class ConfigCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
/** @var Composer $composer */ | ||
$composer = $container->get('composer'); | ||
$packageConfig = $composer->getPackage()->getConfig(); | ||
$permissions = $packageConfig['vertexvaar/bluesprints']['permissions'] ?? []; | ||
|
||
$configDefinition = $container->getDefinition(Config::class); | ||
$configDefinition->setArguments([ | ||
'$filePermissions' => $permissions['files'] ?? 0660, | ||
'$folderPermissions' => $permissions['folders'] ?? 0770, | ||
]); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/bluesprints/src/Environment/DependencyInjection/EnvironmentCompilerPass.php
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueSprints\Environment\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use VerteXVaaR\BlueSprints\Environment\Context; | ||
use VerteXVaaR\BlueSprints\Environment\Environment; | ||
|
||
use function getenv; | ||
|
||
class EnvironmentCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$definition = $container->getDefinition(Environment::class); | ||
$definition->setArgument('$context', Context::fromString((string)getenv('VXVR_BS_CONTEXT'))); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/bluesprints/src/Environment/DependencyInjection/PathsCompilerPass.php
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueSprints\Environment\DependencyInjection; | ||
|
||
use Composer\Composer; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use VerteXVaaR\BlueSprints\Environment\Paths; | ||
|
||
class PathsCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
/** @var Composer $composer */ | ||
$composer = $container->get('composer'); | ||
$packageConfig = $composer->getPackage()->getConfig(); | ||
$config = $packageConfig['vertexvaar/bluesprints']; | ||
|
||
$pathsDefinition = $container->getDefinition(Paths::class); | ||
$pathsDefinition->setArguments([ | ||
'$logs' => $config['logs'] ?? 'var/logs', | ||
'$locks' => $config['locks'] ?? 'var/locks', | ||
'$cache' => $config['cache'] ?? 'var/cache', | ||
'$database' => $config['database'] ?? 'var/database', | ||
'$config' => $config['config'] ?? 'config', | ||
'$view' => $config['view'] ?? 'view', | ||
'$translations' => $config['translations'] ?? 'translations', | ||
]); | ||
} | ||
|
||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueSprints\Environment; | ||
|
||
final readonly class Environment | ||
{ | ||
public function __construct( | ||
public Context $context, | ||
) { | ||
} | ||
} |
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
Oops, something went wrong.