Skip to content
Snippets Groups Projects
Commit 9b69b3a1 authored by Seamus Lee's avatar Seamus Lee
Browse files

Resolve #2768 Reinstate code into APIv4 that handled magic functions

Add in test to assert Exception type and exception message that is thrown
parent 061fd2be
No related branches found
No related tags found
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.
Finish editing this message first!
Please register or to comment