-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autowiring for actions and views
- Loading branch information
Showing
12 changed files
with
188 additions
and
15 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,39 @@ | ||
<?php | ||
|
||
namespace Sys25\RnBase\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Sys25\RnBase\Frontend\Controller\AbstractAction; | ||
use Sys25\RnBase\Frontend\Service\FrontendServiceProvider; | ||
use Sys25\RnBase\Frontend\View\AbstractView; | ||
|
||
class FrontendServicePass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
// always first check if the primary service is defined | ||
if (!$container->has(FrontendServiceProvider::class)) { | ||
return; | ||
} | ||
|
||
$definition = $container->findDefinition(FrontendServiceProvider::class); | ||
|
||
// find all tagged service IDs | ||
$taggedServices = $container->findTaggedServiceIds(AbstractAction::SERVICE_TAG); | ||
|
||
foreach ($taggedServices as $id => $tags) { | ||
// add the service to the ServiceProvider service | ||
$definition->addMethodCall('addFrontendAction', [new Reference($id)]); | ||
} | ||
|
||
// find all tagged service IDs | ||
$taggedServices = $container->findTaggedServiceIds(AbstractView::SERVICE_TAG); | ||
|
||
foreach ($taggedServices as $id => $tags) { | ||
// add the service to the ServiceProvider service | ||
$definition->addMethodCall('addFrontendView', [new Reference($id)]); | ||
} | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
namespace Sys25\RnBase\Frontend\Service; | ||
|
||
use ReflectionClass; | ||
use Sys25\RnBase\Frontend\Controller\AbstractAction; | ||
use Sys25\RnBase\Frontend\View\AbstractView; | ||
|
||
/*************************************************************** | ||
* Copyright notice | ||
* | ||
* (c) 2007-2024 Rene Nitzsche <rene@system25.de> | ||
* All rights reserved | ||
* | ||
* This script is part of the TYPO3 project. The TYPO3 project is | ||
* free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The GNU General Public License can be found at | ||
* http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This script is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* This copyright notice MUST APPEAR in all copies of the script! | ||
***************************************************************/ | ||
|
||
class FrontendServiceProvider | ||
{ | ||
private $actions = []; | ||
private $views = []; | ||
private $filters = []; | ||
|
||
public function addFrontendAction(AbstractAction $action): void | ||
{ | ||
$this->actions[get_class($action)] = $action; | ||
} | ||
|
||
public function getActionForClass(string $actionClass): ?AbstractAction | ||
{ | ||
if (!array_key_exists($actionClass, $this->actions) && class_exists($actionClass)) { | ||
// Hier werden häufig aliases verwendet. | ||
$reflection = new ReflectionClass($actionClass); | ||
$action = $reflection->getName(); | ||
$this->actions[$actionClass] = $this->actions[$action] ?? null; | ||
} | ||
|
||
return $this->actions[$actionClass] ?? null; | ||
} | ||
|
||
public function addFrontendView(AbstractView $view): void | ||
{ | ||
$this->views[get_class($view)] = $view; | ||
} | ||
|
||
public function getViewForClass(string $viewClass): ?AbstractView | ||
{ | ||
return $this->views[$viewClass] ?? null; | ||
} | ||
} |
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