Add a way to quick-set API fields via an array
authorRobert Sesek <rsesek@bluestatic.org>
Wed, 26 Mar 2008 18:14:08 +0000 (14:14 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Wed, 26 Mar 2008 18:14:08 +0000 (14:14 -0400)
* Api.php:
(BSApi::setArray): New method to set API fields via an array

Api.php
CHANGES

diff --git a/Api.php b/Api.php
index 3f5d8603c348e5f7c1a00a0373360ea1d87034c0..89d8dd90b318640fef09c625a641551b5dd8ac34 100644 (file)
--- 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 8e8553edb8e6ff1d7aad7fb9482657dde30df2d5..632bce01ddec684e50434cd9174342369718b3a4 100644 (file)
--- 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 <head> 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()