From 4979b0b6de2617d396efeaea279117f3261f023a Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 26 Mar 2008 14:14:08 -0400 Subject: [PATCH] Add a way to quick-set API fields via an array * Api.php: (BSApi::setArray): New method to set API fields via an array --- Api.php | 19 +++++++++++++++++++ CHANGES | 1 + 2 files changed, 20 insertions(+) diff --git a/Api.php b/Api.php index 3f5d860..89d8dd9 100644 --- a/Api.php +++ b/Api.php @@ -174,6 +174,25 @@ abstract class BSApi } } + /** + * Sets an array of data into the API, ignoring things in $exclude. Keys + * in the array that don't exist in the API will be ignored. + * + * @param array A dictionary of field names and values to set + * @param array Array of keys to exclude + */ + public function setArray(Array $data, $exclude = array()) + { + foreach ($data as $key => $value) + { + if (in_array($key, $exclude) || !isset($this->fields[$key])) + { + continue; + } + $this->set($key, $value); + } + } + /** * Sets a value, sanitizes it, and validates it * diff --git a/CHANGES b/CHANGES index 8e8553e..632bce0 100644 --- a/CHANGES +++ b/CHANGES @@ -3,3 +3,4 @@ - Change: BSPrinterElementTable:__construct() can now take straight strings and convert them into BSPrinterElementLabel's - New: BSPrinterRootPage::setHeaderCode() allows injecting in between the tag of the root page element (creates BSPrinterRootPage::$headerCode) - New: BSPrinterAbstract::setId() allows all elements to have an id attribute added in _prepareStyle() +- New: Added an ability to quick-set API information via an array with BSApi::setArray() -- 2.22.5