class ResolverGlobalCallback {
private $mode;
- private $path;
+ private $basePath;
+ private $subPath;
/**
* Class constructor.
* @param string $mode
* 'getter' or 'setter'.
* @param string $path
+ * Ex: 'dbLocale' <=> $GLOBALS['dbLocale']
+ * Ex: 'civicrm_setting/domain/debug_enabled' <=> $GLOBALS['civicrm_setting']['domain']['debug_enabled']
*/
public function __construct($mode, $path) {
$this->mode = $mode;
- $this->path = $path;
+ $this->subPath = explode('/', $path);
+ $this->basePath = array_shift($this->subPath);
}
/**
* @return mixed
*/
public function __invoke($arg1 = NULL) {
+ // For PHP 8.1+ compatibility, we resolve the first path-item before doing any array operations.
if ($this->mode === 'getter') {
- return \CRM_Utils_Array::pathGet($GLOBALS, explode('/', $this->path));
+ return \CRM_Utils_Array::pathGet($GLOBALS[$this->basePath], $this->subPath);
}
elseif ($this->mode === 'setter') {
- \CRM_Utils_Array::pathSet($GLOBALS, explode('/', $this->path), $arg1);
+ \CRM_Utils_Array::pathSet($GLOBALS[$this->basePath], $this->subPath, $arg1);
return NULL;
}
else {