idField = array_values((array) $idField)[0]; parent::__construct($entityName, $actionName); } /** * @throws \API_Exception */ protected function validateValues() { $unmatched = []; foreach ($this->records as $record) { if (empty($record[$this->idField])) { $unmatched = array_unique(array_merge($unmatched, $this->checkRequiredFields($record))); } } if ($unmatched) { throw new \API_Exception("Mandatory values missing from Api4 {$this->getEntityName()}::{$this->getActionName()}: " . implode(", ", $unmatched), "mandatory_missing", ["fields" => $unmatched]); } } /** * @return string */ protected function getIdField() { return $this->idField; } /** * Add one or more records to be saved. * @param array ...$records * @return $this */ public function addRecord(array ...$records) { $this->records = array_merge($this->records, $records); return $this; } /** * Set default value for a field. * @param string $fieldName * @param mixed $defaultValue * @return $this */ public function addDefault(string $fieldName, $defaultValue) { $this->defaults[$fieldName] = $defaultValue; return $this; } }