Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
f9c24859
Unverified
Commit
f9c24859
authored
3 years ago
by
Eileen McNaughton
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #21235 from seamuslee001/dev_core_2768
Resolve
#2768
Reinstate code into APIv4 that handled magic fu…
parents
e02393e5
9b69b3a1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Civi/Api4/Generic/AbstractAction.php
+27
-0
27 additions, 0 deletions
Civi/Api4/Generic/AbstractAction.php
tests/phpunit/api/v4/Action/AbstractActionFunctionTest.php
+34
-0
34 additions, 0 deletions
tests/phpunit/api/v4/Action/AbstractActionFunctionTest.php
with
61 additions
and
0 deletions
Civi/Api4/Generic/AbstractAction.php
+
27
−
0
View file @
f9c24859
...
...
@@ -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.
*
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/api/v4/Action/AbstractActionFunctionTest.php
0 → 100644
+
34
−
0
View file @
f9c24859
<?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
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment