-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
209 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
|
||
namespace Pfilsx\DataGrid\DependencyInjection\Compiler; | ||
|
||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class GridPass implements CompilerPassInterface | ||
{ | ||
private $gridExtensionService; | ||
private $gridTypeTag; | ||
|
||
public function __construct(string $gridExtensionService = 'data_grid.extension', string $gridTypeTag = 'data_grid.type') | ||
{ | ||
$this->gridExtensionService = $gridExtensionService; | ||
$this->gridTypeTag = $gridTypeTag; | ||
} | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition($this->gridExtensionService)) { | ||
return; | ||
} | ||
|
||
$definition = $container->getDefinition($this->gridExtensionService); | ||
$definition->replaceArgument(0, $this->processGridTypes($container)); | ||
} | ||
|
||
private function processGridTypes(ContainerBuilder $container) | ||
{ | ||
// Get service locator argument | ||
$servicesMap = []; | ||
$namespaces = []; | ||
|
||
// Builds an array with fully-qualified type class names as keys and service IDs as values | ||
foreach ($container->findTaggedServiceIds($this->gridTypeTag, true) as $serviceId => $tag) { | ||
// Add form type service to the service locator | ||
$serviceDefinition = $container->getDefinition($serviceId); | ||
$servicesMap[$formType = $serviceDefinition->getClass()] = new Reference($serviceId); | ||
$namespaces[substr($formType, 0, strrpos($formType, '\\'))] = true; | ||
} | ||
|
||
return ServiceLocatorTagPass::register($container, $servicesMap); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Extension/DependencyInjection/DependencyInjectionExtension.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,35 @@ | ||
<?php | ||
|
||
|
||
namespace Pfilsx\DataGrid\Extension\DependencyInjection; | ||
|
||
|
||
use InvalidArgumentException; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
class DependencyInjectionExtension | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $typeContainer; | ||
|
||
public function __construct($typeContainer) | ||
{ | ||
$this->typeContainer = $typeContainer; | ||
} | ||
|
||
public function getType($name) | ||
{ | ||
if (!$this->typeContainer->has($name)) { | ||
throw new InvalidArgumentException(sprintf('The field type "%s" is not registered in the service container.', $name)); | ||
} | ||
|
||
return $this->typeContainer->get($name); | ||
} | ||
|
||
public function hasType($name) | ||
{ | ||
return $this->typeContainer->has($name); | ||
} | ||
} |
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
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,12 @@ | ||
<?php | ||
|
||
|
||
namespace Pfilsx\DataGrid\Grid; | ||
|
||
|
||
interface GridTypeInterface | ||
{ | ||
public function buildGrid(DataGridBuilderInterface $builder): void; | ||
|
||
public function handleFilters(DataGridFiltersBuilderInterface $builder, array $filters): void; | ||
} |
Oops, something went wrong.