-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable XSD validation for xml mapping driver
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler; | ||
|
||
use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
use function array_keys; | ||
use function count; | ||
use function sprintf; | ||
|
||
final class XmlMappingDriverPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (! $container->hasParameter('doctrine.entity_managers')) { | ||
return; | ||
} | ||
|
||
foreach (array_keys($container->getParameter('doctrine.entity_managers')) as $managerName) { | ||
$xmlDriverId = sprintf('doctrine.orm.%s_xml_metadata_driver', $managerName); | ||
|
||
if (! $container->hasDefinition($xmlDriverId)) { | ||
continue; | ||
} | ||
|
||
$xmlDriverDef = $container->getDefinition($xmlDriverId); | ||
if ($xmlDriverDef->getClass() === null) { | ||
continue; | ||
} | ||
|
||
if ($container->getParameterBag()->resolveValue($xmlDriverDef->getClass()) !== SimplifiedXmlDriver::class) { | ||
continue; | ||
} | ||
|
||
$args = $xmlDriverDef->getArguments(); | ||
$numberOfArgs = count($args); | ||
if ($numberOfArgs === 0 || $numberOfArgs === 3) { | ||
continue; | ||
} | ||
|
||
if (count($args) < 2) { | ||
$args[] = SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION; | ||
} | ||
|
||
// enable validation | ||
$args[] = true; | ||
|
||
$xmlDriverDef->setArguments($args); | ||
} | ||
} | ||
} |
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