Skip to content
Snippets Groups Projects
Unverified Commit f9c24859 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #21235 from seamuslee001/dev_core_2768

Resolve #2768 Reinstate code into APIv4 that handled magic fu…
parents e02393e5 9b69b3a1
Branches
Tags
No related merge requests found
......@@ -191,6 +191,33 @@ abstract class AbstractAction implements \ArrayAccess {
return $this;
}
/**
* Magic function to provide automatic getter/setter for params.
*
* @param $name
* @param $arguments
* @return static|mixed
* @throws \API_Exception
*/
public function __call($name, $arguments) {
$param = lcfirst(substr($name, 3));
if (!$param || $param[0] == '_') {
throw new \API_Exception('Unknown api parameter: ' . $name);
}
$mode = substr($name, 0, 3);
if ($this->paramExists($param)) {
switch ($mode) {
case 'get':
return $this->$param;
case 'set':
$this->$param = $arguments[0];
return $this;
}
}
throw new \API_Exception('Unknown api parameter: ' . $name);
}
/**
* Invoke api call.
*
......
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
namespace api\v4\Action;
use api\v4\UnitTestCase;
/**
* @group headless
*/
class AbstractActionFunctionTest extends UnitTestCase {
public function testUndefinedParamException(): void {
$this->expectException('API_Exception');
$this->expectExceptionMessage('Unknown api parameter: getLanguage');
\Civi\Api4\System::flush(FALSE)->getLanguage();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment