-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
RouteCollector: Detect Duplicates Config #72
Changes from all commits
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
use Psr\Container\ContainerInterface; | ||
|
||
use function is_array; | ||
use function is_bool; | ||
use function sprintf; | ||
|
||
/** | ||
|
@@ -21,6 +22,8 @@ | |
*/ | ||
final class RouteCollectorFactory | ||
{ | ||
private const DETECT_DUPLICATES_BY_DEFAULT = true; | ||
|
||
/** | ||
* @throws Exception\MissingDependencyException If the RouterInterface service is missing. | ||
*/ | ||
|
@@ -42,24 +45,26 @@ public function __invoke(ContainerInterface $container): RouteCollector | |
private function getDetectDuplicatesFlag(ContainerInterface $container): bool | ||
{ | ||
if (! $container->has('config')) { | ||
return true; | ||
return self::DETECT_DUPLICATES_BY_DEFAULT; | ||
} | ||
|
||
$config = $container->get('config'); | ||
if (! is_array($config) && ! $config instanceof ArrayAccess) { | ||
throw new LogicException(sprintf('Config must be an array or implement %s.', ArrayAccess::class)); | ||
} | ||
|
||
if (! isset($config[RouteCollector::class])) { | ||
return true; | ||
} | ||
$options = $config['router'] ?? []; | ||
Comment on lines
-53
to
+56
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. Do we need to adjust any docs for this? 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. Yes #62 is tracking this - but I think all the docs are in 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. Also added mezzio/mezzio#183 to |
||
|
||
$collectorOptions = $config[RouteCollector::class] ?? []; | ||
if (! is_array($options)) { | ||
return self::DETECT_DUPLICATES_BY_DEFAULT; | ||
} | ||
|
||
if (! is_array($collectorOptions) || ! isset($collectorOptions['detect_duplicates'])) { | ||
return true; | ||
if (! isset($options['detect_duplicates'])) { | ||
return self::DETECT_DUPLICATES_BY_DEFAULT; | ||
} | ||
|
||
return (bool) $collectorOptions['detect_duplicates']; | ||
return is_bool($options['detect_duplicates']) | ||
? $options['detect_duplicates'] | ||
: self::DETECT_DUPLICATES_BY_DEFAULT; | ||
} | ||
} |
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.
I had to squint a few times, because adding a constant for this felt a bit excessive, but then it makes sense :-)