-
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] Load config from configurable path, make controllers public…
… services
- Loading branch information
1 parent
096aab6
commit 75c7baf
Showing
22 changed files
with
292 additions
and
117 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
return []; |
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,7 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
|
||
VerteXVaaR\BlueDist\: | ||
resource: '../src/*' |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VerteXVaaR\BlueContainer\Helper; | ||
|
||
use Closure; | ||
use Composer\Composer; | ||
|
||
readonly class PackageIterator | ||
{ | ||
public function __construct(private Composer $composer) | ||
{ | ||
} | ||
|
||
/** | ||
* Iterates over all installed packages, passing the package to the closure | ||
* and collecting the return values in an array which is returned. | ||
*/ | ||
public function iterate(Closure $closure): array | ||
{ | ||
$return = []; | ||
$installationManager = $this->composer->getInstallationManager(); | ||
$packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(); | ||
foreach ($packages as $package) { | ||
$installPath = $installationManager->getInstallPath($package); | ||
$return[] = $closure($package, $installPath); | ||
} | ||
return $return; | ||
} | ||
} |
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,25 +1,59 @@ | ||
<?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\Http\Server\Middleware\MiddlewareRegistry; | ||
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'); | ||
$installationManager = $composer->getInstallationManager(); | ||
$packages = $composer->getRepositoryManager()->getLocalRepository()->getPackages(); | ||
$middlewares = []; | ||
foreach ($packages as $package) { | ||
$installPath = $installationManager->getInstallPath($package); | ||
|
||
$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', | ||
]); | ||
|
||
$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) | ||
->addTag('vertexvaar.bluesprints.controller'); | ||
$containerBuilder->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
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
28 changes: 0 additions & 28 deletions
28
packages/bluesprints/src/Http/Server/RequestHandler/MiddlewareHandler.php
This file was deleted.
Oops, something went wrong.
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.