Skip to content

Commit

Permalink
minor #44742 [Validator] check for file existence lazily in loaders (…
Browse files Browse the repository at this point in the history
…nicolas-grekas)

This PR was merged into the 6.1 branch.

Discussion
----------

[Validator] check for file existence lazily in loaders

| Q             | A
| ------------- | ---
| Branch?       | 6.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #39945
| License       | MIT
| Doc PR        | -

Commits
-------

9135405 [Validator] check for file existence lazily in loaders
  • Loading branch information
nicolas-grekas committed Jan 31, 2022
2 parents 4c0e021 + 9135405 commit 003254d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class XmlFileLoader extends FileLoader
*/
protected $classes;

public function __construct(string $file)
{
$this->file = $file;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -179,6 +184,8 @@ protected function parseFile(string $path): \SimpleXMLElement

private function loadClassesFromXml()
{
parent::__construct($this->file);

// This method may throw an exception. Do not modify the class'
// state before it completes
$xml = $this->parseFile($this->file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class YamlFileLoader extends FileLoader
*/
protected $classes = null;

public function __construct(string $file)
{
$this->file = $file;
}

/**
* Caches the used YAML parser.
*/
Expand Down Expand Up @@ -131,6 +136,8 @@ private function parseFile(string $path): array

private function loadClassesFromYaml()
{
parent::__construct($this->file);

$this->yamlParser ??= new YamlParser();
$this->classes = $this->parseFile($this->file);

Expand Down

0 comments on commit 003254d

Please sign in to comment.