-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
loadServices: tighten up file match regex #16377
Conversation
Before: Civi code living under a path containing the characters php (such as ~/src/php/civicrm) will crash trying to load services with a message like the following: ReflectionException: Class Civi\Api4\Service\Spec\Provider\src does not exist in ReflectionClass->__construct() After: Civi loads services normally no matter what the enclosing path
(Standard links)
|
@@ -86,7 +86,7 @@ public static function loadServices($namespace, $tag, $container) { | |||
$container->addResource($resource); | |||
foreach (glob("$path*.php") as $file) { | |||
$matches = []; | |||
preg_match('/(\w*).php/', $file, $matches); | |||
preg_match('/(\w*)\.php$/', $file, $matches); |
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 haven't tested this scenario, but this does look like a more correct implementation of "find things ending in *.php
" 👍
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.
@totten i'm guessing also if there was a problem with this right then the api_v4_unit tests would fail right because this merges in the core resources + extension resources
Given Tim's supportive comment, i tested this out by applying the regex locally and installed the deduper and afform extensions and confirmed that this still worked as expected. |
Before: Civi code living under a path containing the characters php (such as ~/src/php/civicrm) will fail to load the API4 explorer with a message like the following: ReflectionException: "Class \Civi\Api4\src does not exist" After: API4 explorer loads no matter what the enclosing path Very similar to PR civicrm#16377
Before: Civi code living under a path containing the characters php (such as ~/src/php/civicrm) will fail to load the API4 explorer with a message like the following: ReflectionException: "Class \Civi\Api4\src does not exist" After: API4 explorer loads no matter what the enclosing path Very similar to PR civicrm#16377
Before: Civi code living under a path containing the characters php (such as ~/src/php/civicrm) will fail to load the API4 explorer with a message like the following: ReflectionException: "Class \Civi\Api4\src does not exist" After: API4 explorer loads no matter what the enclosing path Very similar to PR civicrm#16377
Overview
Tighten up a regular expression used to find files so that it doesn't match a partial path.
Before
Civi code living under a path containing the characters 'php'
(such as ~/src/php/civicrm) will crash trying to load services with
a message like the following:
ReflectionException: Class Civi\Api4\Service\Spec\Provider\src
does not exist in ReflectionClass->__construct()
After
Civi loads services normally no matter what the enclosing path
Technical Details
The regex needs a $ anchor at the end because it's looking for files ending in php. It also needed the '.' escaped so it only matches a literal '.' and not any character.
Comments
There's another PR against master: #16376