-
Couldn't load subscription status.
- Fork 3
Refactor Dependencies::process() with exceptions #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,26 +94,30 @@ private function __construct() | |
| * | ||
| * @param array $dependencies Dependencies | ||
| * @param bool $required Whether dependencies are required or not. | ||
| * | ||
| * @throws \RuntimeException If required and no file is successfully loaded | ||
| * via {@link requireFile()}. | ||
| */ | ||
| protected static function process(array $dependencies, $required) | ||
| { | ||
| foreach ($dependencies as $dependency) { | ||
| if (is_array($dependency)) { | ||
| $dependencyToLoad = null; | ||
| $loadedDependency = null; | ||
|
|
||
| foreach ($dependency as $firstExistsDependency) { | ||
| if (file_exists($firstExistsDependency)) { | ||
| $dependencyToLoad = $firstExistsDependency; | ||
| try { | ||
| requireFile($firstExistsDependency); | ||
| $loadedDependency = $firstExistsDependency; | ||
| break; | ||
| } catch (\RuntimeException $e) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the change here, I was trying to make this block of code use the same conditionals logic as |
||
| } | ||
| } | ||
|
|
||
| if ($required || isset($dependencyToLoad)) { | ||
| if (!isset($dependencyToLoad)) { | ||
| $dependencyToLoad = end($dependency); | ||
| } | ||
|
|
||
| requireFile($dependencyToLoad); | ||
| if ($required && empty($loadedDependency)) { | ||
| throw new \RuntimeException(sprintf( | ||
| 'Files not found: "%s"', | ||
|
||
| implode('" || "', $dependency) | ||
| )); | ||
| } | ||
| } elseif ($required || file_exists($dependency)) { | ||
| requireFile($dependency); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A boolean can be enough ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Updated.