From 27ca7a6f0f739093a0a43439b7c1883985923153 Mon Sep 17 00:00:00 2001 From: Ryan Sundberg Date: Wed, 13 Nov 2013 11:27:27 -0800 Subject: [PATCH] Added add/remove methods to ItemList --- lib/PayPal/Api/ItemList.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/PayPal/Api/ItemList.php b/lib/PayPal/Api/ItemList.php index ea38da6..55ad715 100644 --- a/lib/PayPal/Api/ItemList.php +++ b/lib/PayPal/Api/ItemList.php @@ -4,6 +4,21 @@ namespace PayPal\Api; use PayPal\Common\PPModel; class ItemList extends PPModel { + + /** + * Construct an empty list. + */ + function __construct() { + $this->items = array(); + } + + /** + * Is this list empty? + */ + public function isEmpty() { + return empty($this->items); + } + /** * List of items. * @array @@ -22,6 +37,26 @@ class ItemList extends PPModel { return $this->items; } + /** + * Append an item to the list. + * @return PayPal\Api\Item + */ + public function addItem($item) { + return $this->setItems( + array_merge($this->items, array($item)) + ); + } + + /** + * Remove an item from the list. + * Items are compared using === comparision (PHP.net) + * @return PayPal\Api\Item + */ + public function removeItem($item) { + return $this->setItems( + array_diff($this->items, array($item)) + ); + } /** * Shipping address.