Skip to content

Commit

Permalink
Add importFromFile-method
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Sep 13, 2024
1 parent 4fc6b3f commit a1ba0eb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Registry/ElementRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\IOException;
use Symfony\Component\Finder\Finder;

use function array_merge_recursive;
Expand All @@ -22,7 +23,7 @@ final class ElementRegistry
private array $registry = [];


final private function __construct()
private function __construct()
{
// Initialize the registry with all the elements we know
$classesDir = dirname(__FILE__, 6) . '/vendor/simplesamlphp/composer-xmlprovider-installer/classes';
Expand All @@ -31,14 +32,24 @@ final private function __construct()
$finder = Finder::create()->files()->name('element.registry.*.php')->in($classesDir);
if ($finder->hasResults()) {
foreach ($finder as $file) {
$elements = include($file);
$this->registry = array_merge_recursive($this->registry, $elements);
$this->importFromFile($file);

Check failure on line 35 in src/Registry/ElementRegistry.php

View workflow job for this annotation

GitHub Actions / Quality control

Parameter #1 $file of method SimpleSAML\XML\Registry\ElementRegistry::importFromFile() expects string, Symfony\Component\Finder\SplFileInfo given.

Check failure on line 35 in src/Registry/ElementRegistry.php

View workflow job for this annotation

GitHub Actions / Quality control

Parameter #1 $file of method SimpleSAML\XML\Registry\ElementRegistry::importFromFile() expects string, Symfony\Component\Finder\SplFileInfo given.
}
}
}
}


public function importFromFile(string $file): void
{
if (file_exists($file) === true) {
$elements = include($file);
$this->registry = array_merge_recursive($this->registry, $elements);
} else {
throw new IOException('File not found.');
}
}


public static function getInstance(): ElementRegistry
{
if (self::$instance === null) {
Expand Down

0 comments on commit a1ba0eb

Please sign in to comment.