Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
php-version: 8.2
extensions: xdebug
tools: composer:2
ini-file: development
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Setup problem matchers for PHPUnit
Expand Down
22 changes: 18 additions & 4 deletions src/Definition/Serializer/XmlContainerDefinitionSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ private function addServiceDefinitionsToBuilder(ContainerDefinitionBuilder $buil

foreach ($serviceDefinitions as $serviceDefinition) {
$serviceType = $xpath->query('cd:type/text()', $serviceDefinition)[0]->nodeValue;
assert(class_exists($serviceType));
assert(
class_exists($serviceType) || interface_exists($serviceType),
"The type $serviceType does not exist"
);
$isConcrete = $xpath->query('@isConcrete', $serviceDefinition)[0]->nodeValue === 'true';
$attr = unserialize(base64_decode(
$xpath->query('cd:attribute/text()', $serviceDefinition)[0]?->nodeValue
Expand All @@ -331,7 +334,11 @@ private function addAliasDefinitionsToBuilder(ContainerDefinitionBuilder $builde
$abstract = $xpath->query('cd:abstractService/text()', $aliasDefinition)[0]->nodeValue;
$concrete = $xpath->query('cd:concreteService/text()', $aliasDefinition)[0]->nodeValue;

assert(class_exists($abstract));
assert(
class_exists($abstract) || interface_exists($abstract),
"The type $abstract does not exist"
);
// we are not checking for interface_exists() here because an interface cannot be a concrete service
assert(class_exists($concrete));

$builder = $builder->withAliasDefinition(
Expand All @@ -351,7 +358,10 @@ private function addServicePrepareDefinitionsToBuilder(ContainerDefinitionBuilde
$method = $xpath->query('cd:method/text()', $prepareDefinition)[0]->nodeValue;
$attr = unserialize(base64_decode($xpath->query('cd:attribute/text()', $prepareDefinition)[0]?->nodeValue));

assert(class_exists($service));
assert(
class_exists($service) || interface_exists($service),
"The type $service does not exist"
);
assert($method !== null && $method !== '');

$builder = $builder->withServicePrepareDefinition(
Expand All @@ -372,7 +382,11 @@ private function addServiceDelegateDefinitionsToBuilder(ContainerDefinitionBuild
$delegateMethod = $xpath->query('cd:delegateMethod/text()', $delegateDefinition)[0]->nodeValue;
$attr = unserialize(base64_decode($xpath->query('cd:attribute/text()', $delegateDefinition)[0]?->nodeValue));

assert(class_exists($service));
assert(
class_exists($service) || interface_exists($service),
"The type $service does not exist"
);
// we are not checking for interface_exists() because a delegate must be a concrete type
assert(class_exists($delegateType));
assert($delegateMethod !== null && $delegateMethod !== '');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ private function getConcreteServicesInstanceOf(ContainerDefinition $containerDef
foreach ($containerDefinition->serviceDefinitions() as $service) {
if ($service->isConcrete()) {
$serviceDefinitionType = $serviceDefinition->type()->name();
assert(class_exists($serviceDefinitionType));
assert(
class_exists($serviceDefinitionType) || interface_exists($serviceDefinitionType),
"The type $serviceDefinitionType does not exist"
);
if (is_subclass_of($service->type()->name(), $serviceDefinitionType)) {
yield $service;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Reflection/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public function fromName(string $name) : Type {
default => null,
};
if ($type === null) {
assert(class_exists($name));
assert(
class_exists($name) || interface_exists($name),
"The type $name does not exist"
);
$type = $this->class($name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ private function addAnnotatedDefinitions(
foreach ($abstractPrepareDefinitions as $abstractPrepareDefinition) {
$concreteServiceName = $concretePrepareDefinition->service()->name();
$abstractServiceName = $abstractPrepareDefinition->service()->name();
assert(class_exists($abstractServiceName));
assert(
class_exists($abstractServiceName) || interface_exists($abstractServiceName),
"The type $abstractServiceName does not exist"
);
if (is_subclass_of($concreteServiceName, $abstractServiceName)) {
$hasAbstractPrepare = true;
break;
Expand Down Expand Up @@ -277,9 +280,12 @@ private function addAliasDefinitions(ContainerDefinitionBuilder $containerDefini
}

foreach ($abstractTypes as $abstractType) {
$abstractTypeString = $abstractType->name();
assert(
class_exists($abstractTypeString) || interface_exists($abstractTypeString),
"The type $abstractTypeString does not exist"
);
foreach ($concreteTypes as $concreteType) {
$abstractTypeString = $abstractType->name();
assert(class_exists($abstractTypeString), "The type $abstractTypeString does not exist");
if (is_subclass_of($concreteType->name(), $abstractTypeString)) {
$aliasDefinition = definitionFactory()->aliasDefinition($abstractType, $concreteType);
$containerDefinitionBuilder = $containerDefinitionBuilder->withAliasDefinition($aliasDefinition);
Expand Down