loadServices: tighten up file match regex
authorElliott Eggleston <ejegg@ejegg.com>
Fri, 24 Jan 2020 21:28:57 +0000 (16:28 -0500)
committerElliott Eggleston <ejegg@ejegg.com>
Fri, 24 Jan 2020 21:45:21 +0000 (16:45 -0500)
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

CRM/Api4/Services.php

index 95fd4a2202cc006863768cf3a1a25c25799d0e79..ec8190348ccd3c7a63107cdf5279eae49f5760b8 100644 (file)
@@ -86,7 +86,7 @@ class CRM_Api4_Services {
         $container->addResource($resource);
         foreach (glob("$path*.php") as $file) {
           $matches = [];
-          preg_match('/(\w*).php/', $file, $matches);
+          preg_match('/(\w*)\.php$/', $file, $matches);
           $serviceName = $namespace . array_pop($matches);
           $serviceClass = new \ReflectionClass($serviceName);
           if ($serviceClass->isInstantiable()) {