Skip to content

Commit 4691767

Browse files
Merge pull request #13 from matthiasnoback/12-validator-trips-over-symfony-2-5-form-type-guesser-validator-service
merge #13 Factory service definitions can have a class that actually is an interface (matthiasnoback) This PR was merged into matthiasnoback:master branch. Discussion ---------- |Q |A | |--- |---| |Bug Fix? |y | |New Feature? |n | |BC Breaks? |n | |Deprecations?|n | |Tests Pass? |y | |Fixed Tickets| #12 | |License |MIT| |Doc PR | | Sent using [Gush](https://github.com/gushphp/gush) Commits ------- d110f7d Start working with Gush (matthiasnoback) 7faebc4 Fix bug: factory services are allowed to have an interface as class (matthiasnoback) 29601fc Add compiler pass to fix Symfony validator definition bug (matthiasnoback)
2 parents 1f5d8e8 + 29601fc commit 4691767

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

.gush.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
adapter: github
2+
issue_tracker: github
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyServiceDefinitionValidator\Compiler\Compatibility;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
class FixSymfonyValidatorDefinitionPass implements CompilerPassInterface
9+
{
10+
public function process(ContainerBuilder $container)
11+
{
12+
if ($container->hasDefinition('validator')) {
13+
$container->getDefinition('validator')->setClass('Symfony\Component\Validator\Validator');
14+
}
15+
}
16+
}

ServiceDefinitionValidator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private function validateClass(Definition $definition)
6161
if ($class) {
6262
$class = $this->containerBuilder->getParameterBag()->resolveValue($class);
6363

64+
// TODO only services created using a factory can have an interface
6465
if (!class_exists($class) && !interface_exists($class)) {
6566
throw new ClassNotFoundException($class);
6667
}
@@ -113,7 +114,7 @@ private function validateFactoryService(Definition $definition)
113114

114115
private function validateFactoryClassAndMethod($factoryClass, $factoryMethod)
115116
{
116-
if (!class_exists($factoryClass)) {
117+
if (!class_exists($factoryClass) && !interface_exists($factoryClass)) {
117118
throw new ClassNotFoundException($factoryClass);
118119
}
119120

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyServiceDefinitionValidator\Tests\Functional\Fixtures;
4+
5+
class Validator
6+
{
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyServiceDefinitionValidator\Tests\Functional\Fixtures;
4+
5+
interface ValidatorBuilderInterface
6+
{
7+
public function build();
8+
}

Tests/Functional/Fixtures/reported_problems.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ services:
77
password: "password"
88
calls:
99
- [setAttribute, [3, 2]]
10+
11+
# Issue 12: https://github.com/matthiasnoback/symfony-service-definition-validator/issues/12
12+
# A service created by a factory might itself be created by another factory, in which case it should be possible to
13+
# supply an interface, not a class
14+
validator_builder:
15+
class: Matthias\SymfonyServiceDefinitionValidator\Tests\Functional\Fixtures\ValidatorBuilderInterface
16+
validator:
17+
class: Matthias\SymfonyServiceDefinitionValidator\Tests\Functional\Fixtures\Validator
18+
factory_service: validator_builder
19+
factory_method: build

0 commit comments

Comments
 (0)