Add APIv4 architecture docs
Created by: colemanw
Fills in missing docs about how to build onto the api.
Merge request reports
Activity
21 - The `$_entityName` and `$_actionName` vars are set when the Action object is constructed (by the Entity class factory fn, see above). The underscore makes them hidden parameters as they cannot be changed. 22 - Adding a `protected` var to your Action named e.g. `$thing` will automatically: 23 - Provide a getter/setter (via `__call` MagicMethod) named `getThing()` and `setThing()`. 24 - Expose the param in the Api Explorer (be sure to add a doc-block as it displays in the help panel). 25 - Require a value for the param if you add the `@required` annotation. 26 27 2. Define a `_run()` function to execute the call and return the results. 28 - The `_run()` function is invoked by `execute()` 29 - It gets passed a `Result` object into which it places an array of values from whatever logic it executes. 30 31 ## The Result Class 32 33 An API [`Result`](https://github.com/civicrm/civicrm-core/blob/master/Civi/Api4/Generic/Result.php) is a PHP ArrayObject. It has three functions: 34 35 1. Store the results of the API call (accessible via ArrayAccess). 36 24 - Expose the param in the Api Explorer (be sure to add a doc-block as it displays in the help panel). 25 - Require a value for the param if you add the `@required` annotation. 26 27 2. Define a `_run()` function to execute the call and return the results. 28 - The `_run()` function is invoked by `execute()` 29 - It gets passed a `Result` object into which it places an array of values from whatever logic it executes. 30 31 ## The Result Class 32 33 An API [`Result`](https://github.com/civicrm/civicrm-core/blob/master/Civi/Api4/Generic/Result.php) is a PHP ArrayObject. It has three functions: 34 35 1. Store the results of the API call (accessible via ArrayAccess). 36 37 2. Store metadata like the Entity & Action names. 38 - Some actions extend the Result object to store extra metadata. For example [`BasicReplaceAction`](https://github.com/civicrm/civicrm-core/blob/master/Civi/Api4/Generic/BasicReplaceAction.php) returns [`\Civi\Api4\Result\ReplaceResult`](https://github.com/civicrm/civicrm-core/blob/master/Civi/Api4/Result/ReplaceResult.php) which includes the additional `$deleted` property to list any items deleted by the operation. 39
Please register or sign in to reply