Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
AddConstraintValidatorsPass example
public
function
testThatConstraintValidatorServicesAreProcessed
(
)
{
$container
=
new
ContainerBuilder
(
)
;
$validatorFactory
=
$container
->
register
(
'validator.validator_factory'
)
->
addArgument
(
[
]
)
;
$container
->
register
(
'my_constraint_validator_service1', Validator1::
class
)
->
addTag
(
'validator.constraint_validator',
[
'alias' => 'my_constraint_validator_alias1'
]
)
;
$container
->
register
(
'my_constraint_validator_service2', Validator2::
class
)
->
addTag
(
'validator.constraint_validator'
)
;
$addConstraintValidatorsPass
=
new
AddConstraintValidatorsPass
(
)
;
$addConstraintValidatorsPass
->
process
(
$container
)
;
$locator
=
$container
->
getDefinition
(
(string)
$validatorFactory
->
getArgument
(
0
)
)
;
$this
->
assertTrue
(
!
$locator
->
isPublic
(
)
||
$locator
->
isPrivate
(
)
)
;
$expected
=
(
new
Definition
(
ServiceLocator::
class
,
[
[
Validator1::
class
=>
new
ServiceClosureArgument
(
new
Reference
(
'my_constraint_validator_service1'
)
)
,
'my_constraint_validator_alias1' =>
new
ServiceClosureArgument
(
new
Reference
(
'my_constraint_validator_service1'
)
)
,
Validator2::
class
=>
new
ServiceClosureArgument
(
new
Reference
(
'my_constraint_validator_service2'
)
)
,
]
]
)
)
->
addTag
(
'container.service_locator'
)
;
$this
->
assertEquals
(
$expected
,
$locator
)
;
}
if
(
is_file
(
$file
= __DIR__ . '/Components/DependencyInjection/services_local.xml'
)
)
{
$loader
->
load
(
$file
)
;
}
$this
->
addShopwareConfig
(
$container
, 'shopware',
$this
->config
)
;
$this
->
addResources
(
$container
)
;
$container
->
addCompilerPass
(
new
EventListenerCompilerPass
(
)
, PassConfig::TYPE_BEFORE_REMOVING
)
;
$container
->
addCompilerPass
(
new
EventSubscriberCompilerPass
(
)
, PassConfig::TYPE_BEFORE_REMOVING
)
;
$container
->
addCompilerPass
(
new
DoctrineEventSubscriberCompilerPass
(
)
)
;
$container
->
addCompilerPass
(
new
FormPass
(
)
)
;
$container
->
addCompilerPass
(
new
AddConstraintValidatorsPass
(
)
)
;
$container
->
addCompilerPass
(
new
StaticResourcesCompilerPass
(
)
)
;
$container
->
addCompilerPass
(
new
AddConsoleCommandPass
(
)
)
;
$container
->
addCompilerPass
(
new
ConfigureContainerAwareCommands
(
)
)
;
$container
->
addCompilerPass
(
new
LegacyApiResourcesPass
(
)
)
;
$container
->
addCompilerPass
(
new
ConfigureApiResourcesPass
(
)
, PassConfig::TYPE_OPTIMIZE, -500
)
;
$container
->
addCompilerPass
(
new
RegisterFieldsCompilerPass
(
)
, PassConfig::TYPE_BEFORE_OPTIMIZATION, 500
)
;
$container
->
addCompilerPass
(
new
RegisterDynamicController
(
)
)
;
$container
->
addCompilerPass
(
new
RegisterTypeRepositories
(
)
)
;
$container
->
addCompilerPass
(
new
ControllerCompilerPass
(
)
)
;
$container
->
addCompilerPass
(
new
RegisterControllerArgumentLocatorsPass
(
'argument_resolver.service', 'shopware.controller'
)
)
;
$container
->
addCompilerPass
(
new
VersionCompilerPass
(
)
)
;
$container
=
$this
->
createContainer
(
$data
)
;
$container
->
registerExtension
(
$extension
?:
new
FrameworkExtension
(
)
)
;
$this
->
loadFromFile
(
$container
,
$file
)
;
if
(
$resetCompilerPasses
)
{
$container
->
getCompilerPassConfig
(
)
->
setOptimizationPasses
(
[
]
)
;
$container
->
getCompilerPassConfig
(
)
->
setRemovingPasses
(
[
]
)
;
$container
->
getCompilerPassConfig
(
)
->
setAfterRemovingPasses
(
[
]
)
;
}
$container
->
getCompilerPassConfig
(
)
->
setBeforeOptimizationPasses
(
[
new
LoggerPass
(
)
]
)
;
$container
->
getCompilerPassConfig
(
)
->
setBeforeRemovingPasses
(
[
new
AddConstraintValidatorsPass
(
)
,
new
TranslatorPass
(
)
]
)
;
$container
->
getCompilerPassConfig
(
)
->
setAfterRemovingPasses
(
[
new
AddAnnotationsCachedReaderPass
(
)
]
)
;
if
(
!
$compile
)
{
return
$container
;
}
$container
->
compile
(
)
;
return
self::
$containerCache
[
$cacheKey
]
=
$container
;
}
protected
function
createContainerFromClosure
(
$closure
,
$data
=
[
]
)
{