Browse code

Created repository.

DoubleBastionAdmin authored on 01/03/2022 23:31:10
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,48 @@
1
+<?php
2
+
3
+namespace Phaxio;
4
+
5
+abstract class AbstractResourceCollection extends \ArrayObject
6
+{
7
+    protected $phaxio;
8
+    protected $resource;
9
+    protected $resource_class;
10
+    private $params;
11
+    private $total;
12
+
13
+    public function __construct($phaxio, $params) {
14
+        $this->phaxio = $phaxio;
15
+        $this->params = $params;
16
+
17
+        $this->retrievePage();
18
+
19
+        return $this;
20
+    }
21
+
22
+    public function getTotal() {
23
+        return $this->total;
24
+    }
25
+
26
+    public function getPage() {
27
+        return $this->params['page'];
28
+    }
29
+
30
+    public function getPerPage() {
31
+        return $this->params['per_page'];
32
+    }
33
+
34
+    private function retrievePage() {
35
+        $results = $this->phaxio->doRequest("GET", $this->resource, $this->params);
36
+
37
+        $this->total = $results->getPaging()['total'];
38
+        $this->params['page'] = $results->getPaging()['page'];
39
+        $this->params['per_page'] = $results->getPaging()['per_page'];
40
+
41
+        foreach ($results->getData() as $result) {
42
+            $resource_class = "Phaxio\\{$this->resource_class}";
43
+            $fax = new $resource_class($this->phaxio);
44
+            $fax->exchangeArray($result);
45
+            $this[] = $fax;
46
+        }
47
+    }
48
+}