Merge pull request #21850 from mariav0/patch-1
[civicrm-core.git] / Civi / Api4 / Generic / AbstractAction.php
index 8924c6c831cbdaab4f6192aa15311efd9cf38a00..08daf23954f7bd9336a4249e019380ad35ea0113 100644 (file)
@@ -35,6 +35,8 @@ use Civi\Api4\Utils\ReflectionUtils;
  */
 abstract class AbstractAction implements \ArrayAccess {
 
+  use \Civi\Schema\Traits\MagicGetterSetterTrait;
+
   /**
    * Api version number; cannot be changed.
    *
@@ -251,12 +253,9 @@ abstract class AbstractAction implements \ArrayAccess {
    */
   public function getParams() {
     $params = [];
-    foreach ($this->reflect()->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
-      $name = $property->getName();
-      // Skip variables starting with an underscore
-      if ($name[0] != '_') {
-        $params[$name] = $this->$name;
-      }
+    $magicProperties = $this->getMagicProperties();
+    foreach ($magicProperties as $name => $bool) {
+      $params[$name] = $this->$name;
     }
     return $params;
   }
@@ -282,8 +281,13 @@ abstract class AbstractAction implements \ArrayAccess {
       foreach ($this->reflect()->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
         $name = $property->getName();
         if ($name != 'version' && $name[0] != '_') {
-          $this->_paramInfo[$name] = ReflectionUtils::getCodeDocs($property, 'Property', $vars);
-          $this->_paramInfo[$name]['default'] = $defaults[$name];
+          $docs = ReflectionUtils::getCodeDocs($property, 'Property', $vars);
+          $docs['default'] = $defaults[$name];
+          if (!empty($docs['optionsCallback'])) {
+            $docs['options'] = $this->{$docs['optionsCallback']}();
+            unset($docs['optionsCallback']);
+          }
+          $this->_paramInfo[$name] = $docs;
         }
       }
     }
@@ -310,14 +314,14 @@ abstract class AbstractAction implements \ArrayAccess {
    * @return bool
    */
   public function paramExists($param) {
-    return array_key_exists($param, $this->getParams());
+    return array_key_exists($param, $this->getMagicProperties());
   }
 
   /**
    * @return array
    */
   protected function getParamDefaults() {
-    return array_intersect_key($this->reflect()->getDefaultProperties(), $this->getParams());
+    return array_intersect_key($this->reflect()->getDefaultProperties(), $this->getMagicProperties());
   }
 
   /**