Skip to content

Commit 57ce38a

Browse files
committed
php8-mod: DefinitionGlob to specify a pattern for definition files
1 parent bee3103 commit 57ce38a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Definition/Source/DefinitionGlob.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace DI\Definition\Source;
66

7+
use DI\Definition\Definition;
8+
79
/**
810
* Reads DI definitions from files matching glob pattern.
911
*/
@@ -38,16 +40,16 @@ public function __construct(string $pattern)
3840
$this->pattern = $pattern;
3941
}
4042

41-
public function setAutowiring(Autowiring $autowiring)
43+
public function setAutowiring(Autowiring $autowiring): void
4244
{
4345
$this->autowiring = $autowiring;
4446
}
4547

46-
public function getDefinition(string $name, int $startIndex = 0)
48+
public function getDefinition(string $name): Definition|null
4749
{
4850
$this->initialize();
4951

50-
return $this->sourceChain->getDefinition($name, $startIndex);
52+
return $this->sourceChain->getDefinition($name);
5153
}
5254

5355
public function getDefinitions() : array
@@ -60,13 +62,15 @@ public function getDefinitions() : array
6062
/**
6163
* Lazy-loading of the definitions.
6264
*/
63-
private function initialize()
65+
private function initialize(): void
6466
{
6567
if ($this->initialized === true) {
6668
return;
6769
}
6870

69-
$paths = glob($this->pattern, \GLOB_BRACE);
71+
// prevent errors due to GLOB_BRACE that does not exist e.g. Alpine Linux
72+
$flags = defined('GLOB_BRACE') ? GLOB_BRACE : 0;
73+
$paths = glob($this->pattern, $flags);
7074
$sources = array_map(function ($path) {
7175
return new DefinitionFile($path, $this->autowiring);
7276
}, $paths);

0 commit comments

Comments
 (0)