-
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.
No selector yet, just make the first two testers available through the bundle / dependency injection.
- Loading branch information
Showing
5 changed files
with
80 additions
and
5 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,41 @@ | ||
<?php | ||
|
||
namespace Squirrel\StringsBundle\DependencyInjection\Compiler; | ||
|
||
use Squirrel\Strings\Tester\ValidDateTimeTester; | ||
use Squirrel\Strings\Tester\ValidUTF8Tester; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
/** | ||
* Add string testers to service container | ||
*/ | ||
class StringTesterPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $defaultTesters = [ | ||
ValidUTF8Tester::class, | ||
ValidDateTimeTester::class, | ||
]; | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
// Add all default filters to service container | ||
foreach ($this->defaultTesters as $name => $class) { | ||
if (\is_int($name)) { | ||
$name = \str_replace('Squirrel\\Strings\\Tester\\', '', $class); | ||
$name = \preg_replace('/Tester$/si', '', $name); | ||
} | ||
|
||
$definition = new Definition($class); | ||
$definition->addTag('squirrel.strings.tester', [ | ||
'tester' => $name, | ||
]); | ||
|
||
$container->setDefinition($class, $definition); | ||
} | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Squirrel\StringsBundle\Tests; | ||
|
||
use Squirrel\Strings\Tester\ValidDateTimeTester; | ||
use Squirrel\Strings\Tester\ValidUTF8Tester; | ||
use Squirrel\StringsBundle\DependencyInjection\Compiler\StringTesterPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class StringTesterPassTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testDefault() | ||
{ | ||
$container = new ContainerBuilder(); | ||
|
||
$this->processCompilerPass($container); | ||
|
||
// service container + 2 default testers | ||
$this->assertEquals(3, \count($container->getDefinitions())); | ||
|
||
// Make sure all definitions exist that we expect | ||
$this->assertTrue($container->hasDefinition(ValidUTF8Tester::class)); | ||
$this->assertTrue($container->hasDefinition(ValidDateTimeTester::class)); | ||
|
||
$container->compile(); | ||
} | ||
|
||
protected function processCompilerPass(ContainerBuilder $container) | ||
{ | ||
(new StringTesterPass())->process($container); | ||
} | ||
} |