Permalink
Browse files

Support the count() interface

  • Loading branch information...
1 parent a8fa315 commit 30c3a6da391a1cdc27dc85cc14fbdbb3e61a91c3 @kevinburke kevinburke committed Nov 5, 2012
Showing with 18 additions and 1 deletion.
  1. +18 −1 Services/Twilio/ListResource.php
@@ -11,8 +11,9 @@
*/
abstract class Services_Twilio_ListResource
extends Services_Twilio_Resource
- implements IteratorAggregate
+ implements IteratorAggregate, Countable
{
+
public function __construct($client, $uri) {
$name = $this->getResourceName(true);
/*
@@ -128,6 +129,22 @@ public function getPage(
return new Services_Twilio_Page($page, $list_name, $next_page_uri);
}
+ /**
+ * Get the total number of instance members
+ *
+ * If the total is not set, return null
+ *
+ * @return integer|null
+ */
+ public function count() {
+ $page = $this->getPage(0, 1);
+ if ($page) {
+ return $page->total;
+ } else {
+ return null;
+ }
+ }
+
/**
* Returns an iterable list of InstanceResources

0 comments on commit 30c3a6d

Please sign in to comment.