@@ -10,6 +10,6 @@ |
||
10 | 10 | * @author Seth Battis <[email protected]> |
11 | 11 | **/ |
12 | 12 | class CanvasArray_Exception extends CanvasObject_Exception { |
13 | - const INVALID_PAGE_NUMBER = 200; |
|
14 | - const INVALID_ARRAY_KEY = 201; |
|
13 | + const INVALID_PAGE_NUMBER = 200; |
|
14 | + const INVALID_ARRAY_KEY = 201; |
|
15 | 15 | } |
@@ -16,187 +16,187 @@ |
||
16 | 16 | **/ |
17 | 17 | class CanvasPageLink |
18 | 18 | { |
19 | - /** Name of the current page link */ |
|
20 | - const CURRENT = 'current'; |
|
21 | - |
|
22 | - /** Name of the first page link */ |
|
23 | - const FIRST = 'first'; |
|
24 | - |
|
25 | - /** Name of the last page link */ |
|
26 | - const LAST = 'last'; |
|
27 | - |
|
28 | - /** Name of the next page link */ |
|
29 | - const NEXT = 'next'; |
|
30 | - |
|
31 | - /** Name of the previous page link */ |
|
32 | - const PREV = 'prev'; |
|
33 | - |
|
34 | - |
|
35 | - /** @var string $name Name of the page link */ |
|
36 | - private $name; |
|
37 | - |
|
38 | - /** @var string $endpoint Path of the API endpoint being paginated */ |
|
39 | - private $endpoint; |
|
40 | - |
|
41 | - /** @var array $params Query parameters for the page link API call */ |
|
42 | - private $params; |
|
43 | - |
|
44 | - /** Name of the page number parameter in the page link */ |
|
45 | - const PARAM_PAGE_NUMBER = 'page'; |
|
46 | - |
|
47 | - /** Name of the parameter describing the number of responses per page in the page link */ |
|
48 | - const PARAM_PER_PAGE = 'per_page'; |
|
49 | - |
|
50 | - /** |
|
51 | - * Construct a new Canvas page link object. |
|
52 | - * |
|
53 | - * CanvasPageLinks can be constructed with two possible parameter lists: |
|
54 | - * |
|
55 | - * 1. `__construct(string $pageUrl, string $pageName)` which expects a |
|
56 | - * non-empty string representing the URL of the API endpoint to retrieve the |
|
57 | - * page and a non-empty string representing the canonical name of the page |
|
58 | - * relative to the current page. |
|
59 | - * 2. `__construct(int $pageNumber, CanvasPageLink $modelCanvasPageLink, string $pageName)` |
|
60 | - * which expects a page number greater than zero, any CanvasPageLink object |
|
61 | - * relative to the current page (to be used as a model) and a non-empty string |
|
62 | - * representing the canonical name of the page relative to the current page. |
|
63 | - * |
|
64 | - * @throws CanvasPageLink_Exception INVALID_CONSTRUCTOR If $pageUrl or |
|
65 | - * $pageName is empty or a non-string |
|
66 | - * @throws CanvasPageLink_Exception INVALID_CONSTRUCTOR If $pageNumber is |
|
67 | - * not a number greater than zero, $modelCanvasPageLink is not an |
|
68 | - * instance of CanvasPageLink or $pageName is empty or a non-string |
|
69 | - */ |
|
70 | - public function __construct() |
|
71 | - { |
|
72 | - switch (func_num_args()) { |
|
73 | - case 2: /* __construct($pageUrl, $pageName) */ |
|
74 | - $pageUrl = func_get_arg(0); |
|
75 | - $this->name = func_get_arg(1); |
|
76 | - if (is_string($pageUrl) && !empty($pageUrl) && is_string($this->name) && !empty($this->name)) { |
|
77 | - $this->endpoint = preg_replace('%.*/api/v1(/.*)$%', '$1', parse_url($pageUrl, PHP_URL_PATH)); |
|
78 | - parse_str(parse_url($pageUrl, PHP_URL_QUERY), $this->params); |
|
79 | - } else { |
|
80 | - throw new CanvasPageLink_Exception( |
|
81 | - 'Expected two non-empty strings for page URL and name', |
|
82 | - CanvasPageLink_Exception::INVALID_CONSTRUCTOR |
|
83 | - ); |
|
84 | - } |
|
85 | - break; |
|
86 | - |
|
87 | - case 3: /* __construct($pageNumber, $modelCanvasPageLink, $pageName) */ |
|
88 | - $pageNumber = func_get_arg(0); |
|
89 | - $model = func_get_arg(1); |
|
90 | - $this->name = func_get_arg(2); |
|
91 | - if (is_int($pageNumber) && |
|
92 | - $pageNumber > 0 && |
|
93 | - $model instanceof CanvasPageLink && |
|
94 | - is_string($this->name) && |
|
95 | - !empty($this->name) |
|
96 | - ) { |
|
97 | - $this->endpoint = $model->endpoint; |
|
98 | - $this->params = $model->params; |
|
99 | - switch ($this->name) { |
|
100 | - case self::PREV: |
|
101 | - $this->params[self::PARAM_PAGE_NUMBER] = $pageNumber - 1; |
|
102 | - break; |
|
103 | - |
|
104 | - case self::NEXT: |
|
105 | - $this->params[self::PARAM_PAGE_NUMBER] = $pageNumber + 1; |
|
106 | - break; |
|
107 | - |
|
108 | - case self::FIRST: |
|
109 | - $this->params[self::PARAM_PAGE_NUMBER] = 1; |
|
110 | - break; |
|
111 | - |
|
112 | - case self::LAST: |
|
113 | - default: |
|
114 | - throw new CanvasPageLink_Exception( |
|
115 | - "'{$this->name}' cannot be converted to a page number", |
|
116 | - CanvasPageLink_Exception::INVALID_CONSTRUCTOR |
|
117 | - ); |
|
118 | - } |
|
119 | - } else { |
|
120 | - throw new CanvasPageLink_Exception( |
|
121 | - 'Expected a page number, a model CanvasPageLink object and a non-empty string page name', |
|
122 | - CanvasPageLink_Exception::INVALID_CONSTRUCTOR |
|
123 | - ); |
|
124 | - } |
|
125 | - break; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Canonical name of this page link |
|
131 | - * |
|
132 | - * @return string |
|
133 | - **/ |
|
134 | - public function getName() |
|
135 | - { |
|
136 | - return $this->name; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * API endpoint being paginated |
|
141 | - * |
|
142 | - * @return string |
|
143 | - **/ |
|
144 | - public function getEndpoint() |
|
145 | - { |
|
146 | - return $this->endpoint; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Query parameters to retrieve the linked page |
|
151 | - * |
|
152 | - * @return array |
|
153 | - **/ |
|
154 | - public function getParams() |
|
155 | - { |
|
156 | - return $this->params; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * The (1-indexed) page number of this page |
|
161 | - * |
|
162 | - * @return int |
|
163 | - **/ |
|
164 | - public function getPageNumber() |
|
165 | - { |
|
166 | - if (is_numeric($this->params[self::PARAM_PAGE_NUMBER])) { |
|
167 | - return $this->params[self::PARAM_PAGE_NUMBER]; |
|
168 | - } elseif ($this->params[self::PARAM_PAGE_NUMBER] == 'first') { |
|
169 | - return 1; /* weirdly, api/v1/users/<user_id>/logins returns first instead of page numbers */ |
|
170 | - } else { |
|
171 | - return 1; // FIXME probably not good to assume that this is safe |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * The number of responses per page generating this pagination |
|
177 | - * |
|
178 | - * @return int |
|
179 | - **/ |
|
180 | - public function getPerPage() |
|
181 | - { |
|
182 | - return $this->params[self::PARAM_PER_PAGE]; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * An array representation of the CanvasArray |
|
187 | - * |
|
188 | - * @return array |
|
189 | - **/ |
|
190 | - public function getArrayCopy() |
|
191 | - { |
|
192 | - $arr = array(); |
|
193 | - $_key = $this->key; |
|
194 | - $_page = $this->page; |
|
195 | - foreach ($this as $obj) { |
|
196 | - $arr[] = $obj->getArrayCopy(); |
|
197 | - } |
|
198 | - $this->page = $_page; |
|
199 | - $this->key = $_key; |
|
200 | - return $arr; |
|
201 | - } |
|
19 | + /** Name of the current page link */ |
|
20 | + const CURRENT = 'current'; |
|
21 | + |
|
22 | + /** Name of the first page link */ |
|
23 | + const FIRST = 'first'; |
|
24 | + |
|
25 | + /** Name of the last page link */ |
|
26 | + const LAST = 'last'; |
|
27 | + |
|
28 | + /** Name of the next page link */ |
|
29 | + const NEXT = 'next'; |
|
30 | + |
|
31 | + /** Name of the previous page link */ |
|
32 | + const PREV = 'prev'; |
|
33 | + |
|
34 | + |
|
35 | + /** @var string $name Name of the page link */ |
|
36 | + private $name; |
|
37 | + |
|
38 | + /** @var string $endpoint Path of the API endpoint being paginated */ |
|
39 | + private $endpoint; |
|
40 | + |
|
41 | + /** @var array $params Query parameters for the page link API call */ |
|
42 | + private $params; |
|
43 | + |
|
44 | + /** Name of the page number parameter in the page link */ |
|
45 | + const PARAM_PAGE_NUMBER = 'page'; |
|
46 | + |
|
47 | + /** Name of the parameter describing the number of responses per page in the page link */ |
|
48 | + const PARAM_PER_PAGE = 'per_page'; |
|
49 | + |
|
50 | + /** |
|
51 | + * Construct a new Canvas page link object. |
|
52 | + * |
|
53 | + * CanvasPageLinks can be constructed with two possible parameter lists: |
|
54 | + * |
|
55 | + * 1. `__construct(string $pageUrl, string $pageName)` which expects a |
|
56 | + * non-empty string representing the URL of the API endpoint to retrieve the |
|
57 | + * page and a non-empty string representing the canonical name of the page |
|
58 | + * relative to the current page. |
|
59 | + * 2. `__construct(int $pageNumber, CanvasPageLink $modelCanvasPageLink, string $pageName)` |
|
60 | + * which expects a page number greater than zero, any CanvasPageLink object |
|
61 | + * relative to the current page (to be used as a model) and a non-empty string |
|
62 | + * representing the canonical name of the page relative to the current page. |
|
63 | + * |
|
64 | + * @throws CanvasPageLink_Exception INVALID_CONSTRUCTOR If $pageUrl or |
|
65 | + * $pageName is empty or a non-string |
|
66 | + * @throws CanvasPageLink_Exception INVALID_CONSTRUCTOR If $pageNumber is |
|
67 | + * not a number greater than zero, $modelCanvasPageLink is not an |
|
68 | + * instance of CanvasPageLink or $pageName is empty or a non-string |
|
69 | + */ |
|
70 | + public function __construct() |
|
71 | + { |
|
72 | + switch (func_num_args()) { |
|
73 | + case 2: /* __construct($pageUrl, $pageName) */ |
|
74 | + $pageUrl = func_get_arg(0); |
|
75 | + $this->name = func_get_arg(1); |
|
76 | + if (is_string($pageUrl) && !empty($pageUrl) && is_string($this->name) && !empty($this->name)) { |
|
77 | + $this->endpoint = preg_replace('%.*/api/v1(/.*)$%', '$1', parse_url($pageUrl, PHP_URL_PATH)); |
|
78 | + parse_str(parse_url($pageUrl, PHP_URL_QUERY), $this->params); |
|
79 | + } else { |
|
80 | + throw new CanvasPageLink_Exception( |
|
81 | + 'Expected two non-empty strings for page URL and name', |
|
82 | + CanvasPageLink_Exception::INVALID_CONSTRUCTOR |
|
83 | + ); |
|
84 | + } |
|
85 | + break; |
|
86 | + |
|
87 | + case 3: /* __construct($pageNumber, $modelCanvasPageLink, $pageName) */ |
|
88 | + $pageNumber = func_get_arg(0); |
|
89 | + $model = func_get_arg(1); |
|
90 | + $this->name = func_get_arg(2); |
|
91 | + if (is_int($pageNumber) && |
|
92 | + $pageNumber > 0 && |
|
93 | + $model instanceof CanvasPageLink && |
|
94 | + is_string($this->name) && |
|
95 | + !empty($this->name) |
|
96 | + ) { |
|
97 | + $this->endpoint = $model->endpoint; |
|
98 | + $this->params = $model->params; |
|
99 | + switch ($this->name) { |
|
100 | + case self::PREV: |
|
101 | + $this->params[self::PARAM_PAGE_NUMBER] = $pageNumber - 1; |
|
102 | + break; |
|
103 | + |
|
104 | + case self::NEXT: |
|
105 | + $this->params[self::PARAM_PAGE_NUMBER] = $pageNumber + 1; |
|
106 | + break; |
|
107 | + |
|
108 | + case self::FIRST: |
|
109 | + $this->params[self::PARAM_PAGE_NUMBER] = 1; |
|
110 | + break; |
|
111 | + |
|
112 | + case self::LAST: |
|
113 | + default: |
|
114 | + throw new CanvasPageLink_Exception( |
|
115 | + "'{$this->name}' cannot be converted to a page number", |
|
116 | + CanvasPageLink_Exception::INVALID_CONSTRUCTOR |
|
117 | + ); |
|
118 | + } |
|
119 | + } else { |
|
120 | + throw new CanvasPageLink_Exception( |
|
121 | + 'Expected a page number, a model CanvasPageLink object and a non-empty string page name', |
|
122 | + CanvasPageLink_Exception::INVALID_CONSTRUCTOR |
|
123 | + ); |
|
124 | + } |
|
125 | + break; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Canonical name of this page link |
|
131 | + * |
|
132 | + * @return string |
|
133 | + **/ |
|
134 | + public function getName() |
|
135 | + { |
|
136 | + return $this->name; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * API endpoint being paginated |
|
141 | + * |
|
142 | + * @return string |
|
143 | + **/ |
|
144 | + public function getEndpoint() |
|
145 | + { |
|
146 | + return $this->endpoint; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Query parameters to retrieve the linked page |
|
151 | + * |
|
152 | + * @return array |
|
153 | + **/ |
|
154 | + public function getParams() |
|
155 | + { |
|
156 | + return $this->params; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * The (1-indexed) page number of this page |
|
161 | + * |
|
162 | + * @return int |
|
163 | + **/ |
|
164 | + public function getPageNumber() |
|
165 | + { |
|
166 | + if (is_numeric($this->params[self::PARAM_PAGE_NUMBER])) { |
|
167 | + return $this->params[self::PARAM_PAGE_NUMBER]; |
|
168 | + } elseif ($this->params[self::PARAM_PAGE_NUMBER] == 'first') { |
|
169 | + return 1; /* weirdly, api/v1/users/<user_id>/logins returns first instead of page numbers */ |
|
170 | + } else { |
|
171 | + return 1; // FIXME probably not good to assume that this is safe |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * The number of responses per page generating this pagination |
|
177 | + * |
|
178 | + * @return int |
|
179 | + **/ |
|
180 | + public function getPerPage() |
|
181 | + { |
|
182 | + return $this->params[self::PARAM_PER_PAGE]; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * An array representation of the CanvasArray |
|
187 | + * |
|
188 | + * @return array |
|
189 | + **/ |
|
190 | + public function getArrayCopy() |
|
191 | + { |
|
192 | + $arr = array(); |
|
193 | + $_key = $this->key; |
|
194 | + $_page = $this->page; |
|
195 | + foreach ($this as $obj) { |
|
196 | + $arr[] = $obj->getArrayCopy(); |
|
197 | + } |
|
198 | + $this->page = $_page; |
|
199 | + $this->key = $_key; |
|
200 | + return $arr; |
|
201 | + } |
|
202 | 202 | } |
@@ -11,6 +11,6 @@ |
||
11 | 11 | **/ |
12 | 12 | class CanvasObject_Exception extends CanvasPest_Exception |
13 | 13 | { |
14 | - /** Response values are read-only */ |
|
15 | - const IMMUTABLE = 101; |
|
14 | + /** Response values are read-only */ |
|
15 | + const IMMUTABLE = 101; |
|
16 | 16 | } |
@@ -11,6 +11,6 @@ |
||
11 | 11 | **/ |
12 | 12 | class CanvasPageLink_Exception extends CanvasArray_Exception |
13 | 13 | { |
14 | - /** Invalid parameters were passed to the constructor */ |
|
15 | - const INVALID_CONSTRUCTOR = 301; |
|
14 | + /** Invalid parameters were passed to the constructor */ |
|
15 | + const INVALID_CONSTRUCTOR = 301; |
|
16 | 16 | } |
@@ -18,214 +18,214 @@ |
||
18 | 18 | class CanvasObject implements \ArrayAccess, \Serializable |
19 | 19 | { |
20 | 20 | |
21 | - /** @var array $data Backing store */ |
|
22 | - private $data; |
|
23 | - |
|
24 | - /** |
|
25 | - * Construct a CanvasObject |
|
26 | - * |
|
27 | - * @param string|string[] $response JSON-encoded response from the Canvas |
|
28 | - * API or the resulting JSON-decoded |
|
29 | - * associative array |
|
30 | - **/ |
|
31 | - public function __construct($response) |
|
32 | - { |
|
33 | - if (is_array($response)) { |
|
34 | - $this->data = $response; |
|
35 | - } else { |
|
36 | - $this->data = json_decode($response, true); |
|
37 | - } |
|
38 | - } |
|
39 | - |
|
40 | - /*************************************************************************** |
|
21 | + /** @var array $data Backing store */ |
|
22 | + private $data; |
|
23 | + |
|
24 | + /** |
|
25 | + * Construct a CanvasObject |
|
26 | + * |
|
27 | + * @param string|string[] $response JSON-encoded response from the Canvas |
|
28 | + * API or the resulting JSON-decoded |
|
29 | + * associative array |
|
30 | + **/ |
|
31 | + public function __construct($response) |
|
32 | + { |
|
33 | + if (is_array($response)) { |
|
34 | + $this->data = $response; |
|
35 | + } else { |
|
36 | + $this->data = json_decode($response, true); |
|
37 | + } |
|
38 | + } |
|
39 | + |
|
40 | + /*************************************************************************** |
|
41 | 41 | * Object methods |
42 | 42 | */ |
43 | 43 | |
44 | - /** |
|
45 | - * Whether a property exists |
|
46 | - * |
|
47 | - * @param string $key |
|
48 | - * |
|
49 | - * @return bool |
|
50 | - * |
|
51 | - * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
52 | - **/ |
|
53 | - public function __isset($key) |
|
54 | - { |
|
55 | - return isset($this->data[$key]); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Property to retrieve |
|
60 | - * |
|
61 | - * @param string $key |
|
62 | - * |
|
63 | - * @return mixed |
|
64 | - * |
|
65 | - * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
66 | - **/ |
|
67 | - public function __get($key) |
|
68 | - { |
|
69 | - return $this->data[$key]; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Whether a property exists |
|
74 | - * |
|
75 | - * @deprecated Canvas objects are immutable |
|
76 | - * |
|
77 | - * @param string $key |
|
78 | - * @param mixed $value |
|
79 | - * |
|
80 | - * @return void |
|
81 | - * |
|
82 | - * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
83 | - * |
|
84 | - * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
85 | - **/ |
|
86 | - public function __set($key, $value) |
|
87 | - { |
|
88 | - throw new CanvasObject_Exception( |
|
89 | - 'Canvas objects are immutable', |
|
90 | - CanvasObject_Exception::IMMUTABLE |
|
91 | - ); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Unset a property |
|
96 | - * |
|
97 | - * @deprecated Canvas objects are immutable |
|
98 | - * |
|
99 | - * @param string $key |
|
100 | - * |
|
101 | - * @return void |
|
102 | - * |
|
103 | - * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
104 | - * |
|
105 | - * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
106 | - **/ |
|
107 | - public function __unset($key) |
|
108 | - { |
|
109 | - throw new CanvasObject_Exception( |
|
110 | - 'Canvas objects are immutable', |
|
111 | - CanvasObject_Exception::IMMUTABLE |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - /*************************************************************************** |
|
44 | + /** |
|
45 | + * Whether a property exists |
|
46 | + * |
|
47 | + * @param string $key |
|
48 | + * |
|
49 | + * @return bool |
|
50 | + * |
|
51 | + * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
52 | + **/ |
|
53 | + public function __isset($key) |
|
54 | + { |
|
55 | + return isset($this->data[$key]); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Property to retrieve |
|
60 | + * |
|
61 | + * @param string $key |
|
62 | + * |
|
63 | + * @return mixed |
|
64 | + * |
|
65 | + * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
66 | + **/ |
|
67 | + public function __get($key) |
|
68 | + { |
|
69 | + return $this->data[$key]; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Whether a property exists |
|
74 | + * |
|
75 | + * @deprecated Canvas objects are immutable |
|
76 | + * |
|
77 | + * @param string $key |
|
78 | + * @param mixed $value |
|
79 | + * |
|
80 | + * @return void |
|
81 | + * |
|
82 | + * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
83 | + * |
|
84 | + * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
85 | + **/ |
|
86 | + public function __set($key, $value) |
|
87 | + { |
|
88 | + throw new CanvasObject_Exception( |
|
89 | + 'Canvas objects are immutable', |
|
90 | + CanvasObject_Exception::IMMUTABLE |
|
91 | + ); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Unset a property |
|
96 | + * |
|
97 | + * @deprecated Canvas objects are immutable |
|
98 | + * |
|
99 | + * @param string $key |
|
100 | + * |
|
101 | + * @return void |
|
102 | + * |
|
103 | + * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
104 | + * |
|
105 | + * @see http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members Property overloading |
|
106 | + **/ |
|
107 | + public function __unset($key) |
|
108 | + { |
|
109 | + throw new CanvasObject_Exception( |
|
110 | + 'Canvas objects are immutable', |
|
111 | + CanvasObject_Exception::IMMUTABLE |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + /*************************************************************************** |
|
116 | 116 | * ArrayAccess methods |
117 | 117 | */ |
118 | 118 | |
119 | - /** |
|
120 | - * Whether an offset exists |
|
121 | - * |
|
122 | - * @param int|string $offset |
|
123 | - * |
|
124 | - * @return bool |
|
125 | - * |
|
126 | - * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists() |
|
127 | - **/ |
|
128 | - public function offsetExists($offset) |
|
129 | - { |
|
130 | - return isset($this->data[$offset]); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Offset to retrieve |
|
135 | - * |
|
136 | - * @param int|string $offset |
|
137 | - * |
|
138 | - * @return mixed|null |
|
139 | - * |
|
140 | - * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetGet() |
|
141 | - **/ |
|
142 | - public function offsetGet($offset) |
|
143 | - { |
|
144 | - return $this->data[$offset]; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Assign a value to the specified offset |
|
149 | - * |
|
150 | - * @deprecated Canvas objects are immutable |
|
151 | - * |
|
152 | - * @param int|string $offset |
|
153 | - * @param mixed $value |
|
154 | - * |
|
155 | - * @return void |
|
156 | - * |
|
157 | - * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
158 | - * |
|
159 | - * @see http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet() |
|
160 | - **/ |
|
161 | - public function offsetSet($offset, $value) |
|
162 | - { |
|
163 | - throw new CanvasObject_Exception( |
|
164 | - 'Canvas objects are immutable', |
|
165 | - CanvasObject_Exception::IMMUTABLE |
|
166 | - ); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Unset an offset |
|
171 | - * |
|
172 | - * @deprecated Canvas objects are immutable |
|
173 | - * |
|
174 | - * @param int|string $offset |
|
175 | - * |
|
176 | - * @return void |
|
177 | - * |
|
178 | - * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
179 | - * |
|
180 | - * @see http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset() |
|
181 | - **/ |
|
182 | - public function offsetUnset($offset) |
|
183 | - { |
|
184 | - throw new CanvasObject_Exception( |
|
185 | - 'Canvas objects are immutable', |
|
186 | - CanvasObject_Exception::IMMUTABLE |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - /*************************************************************************** |
|
119 | + /** |
|
120 | + * Whether an offset exists |
|
121 | + * |
|
122 | + * @param int|string $offset |
|
123 | + * |
|
124 | + * @return bool |
|
125 | + * |
|
126 | + * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists() |
|
127 | + **/ |
|
128 | + public function offsetExists($offset) |
|
129 | + { |
|
130 | + return isset($this->data[$offset]); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Offset to retrieve |
|
135 | + * |
|
136 | + * @param int|string $offset |
|
137 | + * |
|
138 | + * @return mixed|null |
|
139 | + * |
|
140 | + * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetGet() |
|
141 | + **/ |
|
142 | + public function offsetGet($offset) |
|
143 | + { |
|
144 | + return $this->data[$offset]; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Assign a value to the specified offset |
|
149 | + * |
|
150 | + * @deprecated Canvas objects are immutable |
|
151 | + * |
|
152 | + * @param int|string $offset |
|
153 | + * @param mixed $value |
|
154 | + * |
|
155 | + * @return void |
|
156 | + * |
|
157 | + * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
158 | + * |
|
159 | + * @see http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet() |
|
160 | + **/ |
|
161 | + public function offsetSet($offset, $value) |
|
162 | + { |
|
163 | + throw new CanvasObject_Exception( |
|
164 | + 'Canvas objects are immutable', |
|
165 | + CanvasObject_Exception::IMMUTABLE |
|
166 | + ); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Unset an offset |
|
171 | + * |
|
172 | + * @deprecated Canvas objects are immutable |
|
173 | + * |
|
174 | + * @param int|string $offset |
|
175 | + * |
|
176 | + * @return void |
|
177 | + * |
|
178 | + * @throws CanvasObject_Exception IMMUTABLE All calls to this method will cause an exception |
|
179 | + * |
|
180 | + * @see http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset() |
|
181 | + **/ |
|
182 | + public function offsetUnset($offset) |
|
183 | + { |
|
184 | + throw new CanvasObject_Exception( |
|
185 | + 'Canvas objects are immutable', |
|
186 | + CanvasObject_Exception::IMMUTABLE |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + /*************************************************************************** |
|
191 | 191 | * Serializable methods |
192 | 192 | */ |
193 | 193 | |
194 | - /** |
|
195 | - * String representation of CanvasObject |
|
196 | - * |
|
197 | - * @return string |
|
198 | - * |
|
199 | - * @see http://php.net/manual/en/serializable.serialize.php Serializable::serialize() |
|
200 | - **/ |
|
201 | - public function serialize() |
|
202 | - { |
|
203 | - return serialize($this->data); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Construct a CanvasObject from its string representation |
|
208 | - * |
|
209 | - * @param string $data |
|
210 | - * |
|
211 | - * @return void |
|
212 | - * |
|
213 | - * @see http://php.net/manual/en/serializable.unserialize.php Serializable::unsserialize() |
|
214 | - **/ |
|
215 | - public function unserialize($data) |
|
216 | - { |
|
217 | - $this->data = unserialize($data); |
|
218 | - } |
|
219 | - |
|
220 | - /**************************************************************************/ |
|
221 | - |
|
222 | - /** |
|
223 | - * An array representation of the CanvasObject |
|
224 | - * |
|
225 | - * @return array |
|
226 | - **/ |
|
227 | - public function getArrayCopy() |
|
228 | - { |
|
229 | - return $this->data; |
|
230 | - } |
|
194 | + /** |
|
195 | + * String representation of CanvasObject |
|
196 | + * |
|
197 | + * @return string |
|
198 | + * |
|
199 | + * @see http://php.net/manual/en/serializable.serialize.php Serializable::serialize() |
|
200 | + **/ |
|
201 | + public function serialize() |
|
202 | + { |
|
203 | + return serialize($this->data); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Construct a CanvasObject from its string representation |
|
208 | + * |
|
209 | + * @param string $data |
|
210 | + * |
|
211 | + * @return void |
|
212 | + * |
|
213 | + * @see http://php.net/manual/en/serializable.unserialize.php Serializable::unsserialize() |
|
214 | + **/ |
|
215 | + public function unserialize($data) |
|
216 | + { |
|
217 | + $this->data = unserialize($data); |
|
218 | + } |
|
219 | + |
|
220 | + /**************************************************************************/ |
|
221 | + |
|
222 | + /** |
|
223 | + * An array representation of the CanvasObject |
|
224 | + * |
|
225 | + * @return array |
|
226 | + **/ |
|
227 | + public function getArrayCopy() |
|
228 | + { |
|
229 | + return $this->data; |
|
230 | + } |
|
231 | 231 | } |
@@ -11,12 +11,12 @@ |
||
11 | 11 | **/ |
12 | 12 | class CanvasPest_Exception extends \Exception |
13 | 13 | { |
14 | - /** The API access method is not supported by the Canvas API */ |
|
15 | - const UNSUPPORTED_METHOD = 1; |
|
14 | + /** The API access method is not supported by the Canvas API */ |
|
15 | + const UNSUPPORTED_METHOD = 1; |
|
16 | 16 | |
17 | - /** The API access token provided is invalid */ |
|
18 | - const INVALID_TOKEN = 2; |
|
17 | + /** The API access token provided is invalid */ |
|
18 | + const INVALID_TOKEN = 2; |
|
19 | 19 | |
20 | - /** Unanticipated JSON response from API */ |
|
21 | - const INVALID_JSON_RESPONSE = 3; |
|
20 | + /** Unanticipated JSON response from API */ |
|
21 | + const INVALID_JSON_RESPONSE = 3; |
|
22 | 22 | } |
@@ -12,448 +12,448 @@ |
||
12 | 12 | **/ |
13 | 13 | class CanvasArray implements \Iterator, \ArrayAccess, \Serializable |
14 | 14 | { |
15 | - /** The maximum supported number of responses per page */ |
|
16 | - const MAXIMUM_PER_PAGE = 100; |
|
17 | - |
|
18 | - /** @var CanvasPest $api Canvas API (for paging through the array) */ |
|
19 | - protected $api; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var string $endpoint API endpoint whose response is represented by this |
|
23 | - * object |
|
24 | - **/ |
|
25 | - private $endpoint = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var CanvasPageLink[] $pagination The canonical (first, last, next, prev, current) |
|
29 | - * pages relative to the current page of responses |
|
30 | - **/ |
|
31 | - private $pagination = array(); |
|
32 | - |
|
33 | - /** @var CanvasObject[] $data Backing store */ |
|
34 | - private $data = array(); |
|
35 | - |
|
36 | - /** @var int $page Page number corresponding to current $key */ |
|
37 | - private $page = null; |
|
38 | - |
|
39 | - /** @var int $key Current key-value of iterator */ |
|
40 | - private $key = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * Construct a CanvasArray |
|
44 | - * |
|
45 | - * @param string $jsonResponse A JSON-encoded response array from the Canvas API |
|
46 | - * @param CanvasPest $canvasPest An API object for making pagination calls |
|
47 | - **/ |
|
48 | - public function __construct($jsonResponse, $canvasPest) |
|
49 | - { |
|
50 | - $this->api = $canvasPest; |
|
51 | - |
|
52 | - /* parse Canvas page links */ |
|
53 | - if (preg_match_all('%<([^>]*)>\s*;\s*rel="([^"]+)"%', $this->api->lastHeader('link'), $links, PREG_SET_ORDER)) { |
|
54 | - foreach ($links as $link) { |
|
55 | - $this->pagination[$link[2]] = new CanvasPageLink($link[1], $link[2]); |
|
56 | - } |
|
57 | - } else { |
|
58 | - $this->pagination = array(); // might only be one page of results |
|
59 | - } |
|
60 | - |
|
61 | - /* locate ourselves */ |
|
62 | - if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
63 | - $this->page = $this->pagination[CanvasPageLink::CURRENT]->getPageNumber(); |
|
64 | - } else { |
|
65 | - $this->page = 1; // assume only one page (since no pagination) |
|
66 | - } |
|
67 | - $this->key = $this->pageNumberToKey($this->page); |
|
68 | - |
|
69 | - /* parse the JSON response string */ |
|
70 | - $key = $this->key; |
|
71 | - foreach (json_decode($jsonResponse, true) as $item) { |
|
72 | - $this->data[$key++] = new CanvasObject($item, $this->api); |
|
73 | - } |
|
74 | - } |
|
75 | - /** |
|
76 | - * Convert a page number to an array key |
|
77 | - * |
|
78 | - * @param int $pageNumber 1-indexed page number |
|
79 | - * |
|
80 | - * @return int |
|
81 | - * |
|
82 | - * @throws CanvasArray_Exception INVALID_PAGE_NUMBER If $pageNumber < 1 |
|
83 | - **/ |
|
84 | - private function pageNumberToKey($pageNumber) |
|
85 | - { |
|
86 | - if ($pageNumber < 1) { |
|
87 | - throw new CanvasArray_Exception( |
|
88 | - "{$pageNumber} is not a valid page number", |
|
89 | - CanvasArray_Exception::INVALID_PAGE_NUMBER |
|
90 | - ); |
|
91 | - } |
|
92 | - if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
93 | - return ($pageNumber - 1) * $this->pagination[CanvasPageLink::CURRENT]->getPerPage(); |
|
94 | - } else { |
|
95 | - return 0; // assume only one page (since no pagination); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Convert an array key to a page number |
|
101 | - * |
|
102 | - * @param int $key Non-negative array key |
|
103 | - * |
|
104 | - * @return int |
|
105 | - * |
|
106 | - * @throws CanvasArray_Exception INVALID_ARRAY_KEY If $key < 0 |
|
107 | - **/ |
|
108 | - private function keyToPageNumber($key) |
|
109 | - { |
|
110 | - if ($key < 0) { |
|
111 | - throw new CanvasArray_Exception( |
|
112 | - "$key is not a valid array key", |
|
113 | - CanvasArray_Exception::INVALID_ARRAY_KEY |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
118 | - return ((int) ($key / $this->pagination[CanvasPageLink::CURRENT]->getPerPage())) + 1; |
|
119 | - } else { |
|
120 | - return 1; // assume single page if no pagination |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Request a page of responses from the API |
|
126 | - * |
|
127 | - * A page of responses will be requested if it appears that that page has not |
|
128 | - * yet been loaded (tested by checking if the initial element of the page has |
|
129 | - * been initialized in the $data array). |
|
130 | - * |
|
131 | - * @param int $pageNumber Page number to request |
|
132 | - * @param bool $forceRefresh (Optional) Force a refresh of backing data, even |
|
133 | - * if cached (defaults to `FALSE`) |
|
134 | - * |
|
135 | - * @return bool `TRUE` if the page is requested, `FALSE` if it is already cached |
|
136 | - * (and therefore not requested) |
|
137 | - **/ |
|
138 | - private function requestPageNumber($pageNumber, $forceRefresh = false) |
|
139 | - { |
|
140 | - if (!isset($this->data[$this->pageNumberToKey($pageNumber)]) || ($forceRefresh && isset($this->api))) { |
|
141 | - // assume one page if no pagination (and already loaded) |
|
142 | - if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
143 | - $params = $this->pagination[CanvasPageLink::CURRENT]->getParams(); |
|
144 | - $params[CanvasPageLink::PARAM_PAGE_NUMBER] = $pageNumber; |
|
145 | - $page = $this->api->get($this->pagination[CanvasPageLink::CURRENT]->getEndpoint(), $params); |
|
146 | - $this->data = array_replace($this->data, $page->data); |
|
147 | - return true; |
|
148 | - } |
|
149 | - } |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Request all pages from API |
|
155 | - * |
|
156 | - * This stores the entire API response locally, in preparation for, most |
|
157 | - * likely, serializing this object. |
|
158 | - * |
|
159 | - * @param bool $forceRefresh (Optional) Force a refresh of backing data, even |
|
160 | - * if cached (defaults to `FALSE`) |
|
161 | - * |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - private function requestAllPages($forceRefresh = false) |
|
165 | - { |
|
166 | - $_page = $this->page; |
|
167 | - $_key = $this->key; |
|
168 | - |
|
169 | - if (isset($this->pagination[CanvasPageLink::LAST])) { |
|
170 | - for ($page = 1; $page <= $this->pagination[CanvasPageLink::LAST]->getPageNumber(); $page++) { |
|
171 | - $this->requestPageNumber($page, $forceRefresh); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - $this->page = $_page; |
|
176 | - $this->key = $_key; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Rewind the iterator to a specific page of data |
|
181 | - * |
|
182 | - * If the page of data is already cached, it will not (by default) be reloaded |
|
183 | - * from the API, although this can be overridden with the $forceRefresh |
|
184 | - * parameter. |
|
185 | - * |
|
186 | - * @param int $pageNumber Page number to rewind to |
|
187 | - * @param bool $forceRefresh (Optional) Defaults to `FALSE` |
|
188 | - * |
|
189 | - * @return void |
|
190 | - **/ |
|
191 | - private function rewindToPageNumber($pageNumber, $forceRefresh = false) |
|
192 | - { |
|
193 | - $page = null; |
|
194 | - $key = $this->pageNumberToKey($pageNumber); |
|
195 | - if ($forceRefresh || !isset($this->data[$key])) { |
|
196 | - $page = $this->requestPageNumber($pageNumber, $forceRefresh); |
|
197 | - } |
|
198 | - |
|
199 | - $this->key = $key; |
|
200 | - $this->page = $pageNumber; |
|
201 | - $this->pagination[CanvasPageLink::PREV] = new CanvasPageLink( |
|
202 | - $pageNumber, |
|
203 | - $this->pagination[CanvasPageLink::FIRST], |
|
204 | - CanvasPageLink::PREV |
|
205 | - ); |
|
206 | - $this->pagination[CanvasPageLink::NEXT] = new CanvasPageLink( |
|
207 | - $pageNumber, |
|
208 | - $this->pagination[CanvasPageLink::FIRST], |
|
209 | - CanvasPageLink::NEXT |
|
210 | - ); |
|
211 | - } |
|
212 | - |
|
213 | - /*************************************************************************** |
|
15 | + /** The maximum supported number of responses per page */ |
|
16 | + const MAXIMUM_PER_PAGE = 100; |
|
17 | + |
|
18 | + /** @var CanvasPest $api Canvas API (for paging through the array) */ |
|
19 | + protected $api; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var string $endpoint API endpoint whose response is represented by this |
|
23 | + * object |
|
24 | + **/ |
|
25 | + private $endpoint = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var CanvasPageLink[] $pagination The canonical (first, last, next, prev, current) |
|
29 | + * pages relative to the current page of responses |
|
30 | + **/ |
|
31 | + private $pagination = array(); |
|
32 | + |
|
33 | + /** @var CanvasObject[] $data Backing store */ |
|
34 | + private $data = array(); |
|
35 | + |
|
36 | + /** @var int $page Page number corresponding to current $key */ |
|
37 | + private $page = null; |
|
38 | + |
|
39 | + /** @var int $key Current key-value of iterator */ |
|
40 | + private $key = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * Construct a CanvasArray |
|
44 | + * |
|
45 | + * @param string $jsonResponse A JSON-encoded response array from the Canvas API |
|
46 | + * @param CanvasPest $canvasPest An API object for making pagination calls |
|
47 | + **/ |
|
48 | + public function __construct($jsonResponse, $canvasPest) |
|
49 | + { |
|
50 | + $this->api = $canvasPest; |
|
51 | + |
|
52 | + /* parse Canvas page links */ |
|
53 | + if (preg_match_all('%<([^>]*)>\s*;\s*rel="([^"]+)"%', $this->api->lastHeader('link'), $links, PREG_SET_ORDER)) { |
|
54 | + foreach ($links as $link) { |
|
55 | + $this->pagination[$link[2]] = new CanvasPageLink($link[1], $link[2]); |
|
56 | + } |
|
57 | + } else { |
|
58 | + $this->pagination = array(); // might only be one page of results |
|
59 | + } |
|
60 | + |
|
61 | + /* locate ourselves */ |
|
62 | + if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
63 | + $this->page = $this->pagination[CanvasPageLink::CURRENT]->getPageNumber(); |
|
64 | + } else { |
|
65 | + $this->page = 1; // assume only one page (since no pagination) |
|
66 | + } |
|
67 | + $this->key = $this->pageNumberToKey($this->page); |
|
68 | + |
|
69 | + /* parse the JSON response string */ |
|
70 | + $key = $this->key; |
|
71 | + foreach (json_decode($jsonResponse, true) as $item) { |
|
72 | + $this->data[$key++] = new CanvasObject($item, $this->api); |
|
73 | + } |
|
74 | + } |
|
75 | + /** |
|
76 | + * Convert a page number to an array key |
|
77 | + * |
|
78 | + * @param int $pageNumber 1-indexed page number |
|
79 | + * |
|
80 | + * @return int |
|
81 | + * |
|
82 | + * @throws CanvasArray_Exception INVALID_PAGE_NUMBER If $pageNumber < 1 |
|
83 | + **/ |
|
84 | + private function pageNumberToKey($pageNumber) |
|
85 | + { |
|
86 | + if ($pageNumber < 1) { |
|
87 | + throw new CanvasArray_Exception( |
|
88 | + "{$pageNumber} is not a valid page number", |
|
89 | + CanvasArray_Exception::INVALID_PAGE_NUMBER |
|
90 | + ); |
|
91 | + } |
|
92 | + if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
93 | + return ($pageNumber - 1) * $this->pagination[CanvasPageLink::CURRENT]->getPerPage(); |
|
94 | + } else { |
|
95 | + return 0; // assume only one page (since no pagination); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Convert an array key to a page number |
|
101 | + * |
|
102 | + * @param int $key Non-negative array key |
|
103 | + * |
|
104 | + * @return int |
|
105 | + * |
|
106 | + * @throws CanvasArray_Exception INVALID_ARRAY_KEY If $key < 0 |
|
107 | + **/ |
|
108 | + private function keyToPageNumber($key) |
|
109 | + { |
|
110 | + if ($key < 0) { |
|
111 | + throw new CanvasArray_Exception( |
|
112 | + "$key is not a valid array key", |
|
113 | + CanvasArray_Exception::INVALID_ARRAY_KEY |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
118 | + return ((int) ($key / $this->pagination[CanvasPageLink::CURRENT]->getPerPage())) + 1; |
|
119 | + } else { |
|
120 | + return 1; // assume single page if no pagination |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Request a page of responses from the API |
|
126 | + * |
|
127 | + * A page of responses will be requested if it appears that that page has not |
|
128 | + * yet been loaded (tested by checking if the initial element of the page has |
|
129 | + * been initialized in the $data array). |
|
130 | + * |
|
131 | + * @param int $pageNumber Page number to request |
|
132 | + * @param bool $forceRefresh (Optional) Force a refresh of backing data, even |
|
133 | + * if cached (defaults to `FALSE`) |
|
134 | + * |
|
135 | + * @return bool `TRUE` if the page is requested, `FALSE` if it is already cached |
|
136 | + * (and therefore not requested) |
|
137 | + **/ |
|
138 | + private function requestPageNumber($pageNumber, $forceRefresh = false) |
|
139 | + { |
|
140 | + if (!isset($this->data[$this->pageNumberToKey($pageNumber)]) || ($forceRefresh && isset($this->api))) { |
|
141 | + // assume one page if no pagination (and already loaded) |
|
142 | + if (isset($this->pagination[CanvasPageLink::CURRENT])) { |
|
143 | + $params = $this->pagination[CanvasPageLink::CURRENT]->getParams(); |
|
144 | + $params[CanvasPageLink::PARAM_PAGE_NUMBER] = $pageNumber; |
|
145 | + $page = $this->api->get($this->pagination[CanvasPageLink::CURRENT]->getEndpoint(), $params); |
|
146 | + $this->data = array_replace($this->data, $page->data); |
|
147 | + return true; |
|
148 | + } |
|
149 | + } |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Request all pages from API |
|
155 | + * |
|
156 | + * This stores the entire API response locally, in preparation for, most |
|
157 | + * likely, serializing this object. |
|
158 | + * |
|
159 | + * @param bool $forceRefresh (Optional) Force a refresh of backing data, even |
|
160 | + * if cached (defaults to `FALSE`) |
|
161 | + * |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + private function requestAllPages($forceRefresh = false) |
|
165 | + { |
|
166 | + $_page = $this->page; |
|
167 | + $_key = $this->key; |
|
168 | + |
|
169 | + if (isset($this->pagination[CanvasPageLink::LAST])) { |
|
170 | + for ($page = 1; $page <= $this->pagination[CanvasPageLink::LAST]->getPageNumber(); $page++) { |
|
171 | + $this->requestPageNumber($page, $forceRefresh); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + $this->page = $_page; |
|
176 | + $this->key = $_key; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Rewind the iterator to a specific page of data |
|
181 | + * |
|
182 | + * If the page of data is already cached, it will not (by default) be reloaded |
|
183 | + * from the API, although this can be overridden with the $forceRefresh |
|
184 | + * parameter. |
|
185 | + * |
|
186 | + * @param int $pageNumber Page number to rewind to |
|
187 | + * @param bool $forceRefresh (Optional) Defaults to `FALSE` |
|
188 | + * |
|
189 | + * @return void |
|
190 | + **/ |
|
191 | + private function rewindToPageNumber($pageNumber, $forceRefresh = false) |
|
192 | + { |
|
193 | + $page = null; |
|
194 | + $key = $this->pageNumberToKey($pageNumber); |
|
195 | + if ($forceRefresh || !isset($this->data[$key])) { |
|
196 | + $page = $this->requestPageNumber($pageNumber, $forceRefresh); |
|
197 | + } |
|
198 | + |
|
199 | + $this->key = $key; |
|
200 | + $this->page = $pageNumber; |
|
201 | + $this->pagination[CanvasPageLink::PREV] = new CanvasPageLink( |
|
202 | + $pageNumber, |
|
203 | + $this->pagination[CanvasPageLink::FIRST], |
|
204 | + CanvasPageLink::PREV |
|
205 | + ); |
|
206 | + $this->pagination[CanvasPageLink::NEXT] = new CanvasPageLink( |
|
207 | + $pageNumber, |
|
208 | + $this->pagination[CanvasPageLink::FIRST], |
|
209 | + CanvasPageLink::NEXT |
|
210 | + ); |
|
211 | + } |
|
212 | + |
|
213 | + /*************************************************************************** |
|
214 | 214 | * ArrayObject methods |
215 | 215 | */ |
216 | 216 | |
217 | - /** |
|
218 | - * Get the number of CanvasObjects in the Canvas response |
|
219 | - * |
|
220 | - * @return int |
|
221 | - * |
|
222 | - * @see http://php.net/manual/en/arrayobject.count.php ArrayObject::count |
|
223 | - **/ |
|
224 | - public function count() |
|
225 | - { |
|
226 | - if (isset($this->pagination[CanvasPageLink::LAST])) { |
|
227 | - $this->requestPageNumber($this->pagination[CanvasPageLink::LAST]->getPageNumber()); |
|
228 | - if (!end($this->data)) { |
|
229 | - return 0; |
|
230 | - } |
|
231 | - return key($this->data) + 1; |
|
232 | - } else { |
|
233 | - return count($this->data); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Creates a copy of the CanvasArray |
|
239 | - * |
|
240 | - * @return CanvasObject[] |
|
241 | - * |
|
242 | - * @see http://php.net/manual/en/arrayobject.getarraycopy.php ArrayObject::getArrayCopy |
|
243 | - **/ |
|
244 | - public function getArrayCopy() |
|
245 | - { |
|
246 | - $_key = $this->key; |
|
247 | - $this->rewindToPageNumber(1); |
|
248 | - while (isset($this->pagination[CanvasPageLink::NEXT])) { |
|
249 | - $this->rewindToPageNumber($this->pagination[CanvasPageLink::NEXT]); |
|
250 | - } |
|
251 | - $this->key = $_key; |
|
252 | - return $this->data; |
|
253 | - } |
|
254 | - |
|
255 | - /*************************************************************************** |
|
217 | + /** |
|
218 | + * Get the number of CanvasObjects in the Canvas response |
|
219 | + * |
|
220 | + * @return int |
|
221 | + * |
|
222 | + * @see http://php.net/manual/en/arrayobject.count.php ArrayObject::count |
|
223 | + **/ |
|
224 | + public function count() |
|
225 | + { |
|
226 | + if (isset($this->pagination[CanvasPageLink::LAST])) { |
|
227 | + $this->requestPageNumber($this->pagination[CanvasPageLink::LAST]->getPageNumber()); |
|
228 | + if (!end($this->data)) { |
|
229 | + return 0; |
|
230 | + } |
|
231 | + return key($this->data) + 1; |
|
232 | + } else { |
|
233 | + return count($this->data); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Creates a copy of the CanvasArray |
|
239 | + * |
|
240 | + * @return CanvasObject[] |
|
241 | + * |
|
242 | + * @see http://php.net/manual/en/arrayobject.getarraycopy.php ArrayObject::getArrayCopy |
|
243 | + **/ |
|
244 | + public function getArrayCopy() |
|
245 | + { |
|
246 | + $_key = $this->key; |
|
247 | + $this->rewindToPageNumber(1); |
|
248 | + while (isset($this->pagination[CanvasPageLink::NEXT])) { |
|
249 | + $this->rewindToPageNumber($this->pagination[CanvasPageLink::NEXT]); |
|
250 | + } |
|
251 | + $this->key = $_key; |
|
252 | + return $this->data; |
|
253 | + } |
|
254 | + |
|
255 | + /*************************************************************************** |
|
256 | 256 | * ArrayAccess methods |
257 | 257 | */ |
258 | 258 | |
259 | - /** |
|
260 | - * Whether an offset exists |
|
261 | - * |
|
262 | - * @param int|string $offset |
|
263 | - * |
|
264 | - * @return bool |
|
265 | - * |
|
266 | - * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists |
|
267 | - **/ |
|
268 | - public function offsetExists($offset) |
|
269 | - { |
|
270 | - if (isset($this->pagination[CanvasPageLink::LAST])) { |
|
271 | - $lastPageNumber = $this->pagination[CanvasPageLink::LAST]->getPageNumber(); |
|
272 | - if ($this->keyToPageNumber($offset) == $lastPageNumber && |
|
273 | - !isset($this->data[$this->pageNumberToKey($lastPageNumber)])) { |
|
274 | - $this->requestPageNumber($lastPageNumber); |
|
275 | - } |
|
276 | - return isset($this->data[$offset]) || ($offset >= 0 && $offset < $this->pageNumberToKey($lastPageNumber)); |
|
277 | - } else { |
|
278 | - return isset($this->data[$offset]); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Offset to retrieve |
|
284 | - * |
|
285 | - * @param int|string $offset |
|
286 | - * |
|
287 | - * @return CanvasObject|null |
|
288 | - * |
|
289 | - * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetGet |
|
290 | - **/ |
|
291 | - public function offsetGet($offset) |
|
292 | - { |
|
293 | - if ($this->offsetExists($offset) && !isset($this->data[$offset])) { |
|
294 | - $this->requestPageNumber($this->keyToPageNumber($offset)); |
|
295 | - } |
|
296 | - return $this->data[$offset]; |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Assign a value to the specified offset |
|
301 | - * |
|
302 | - * @deprecated Canvas responses are immutable |
|
303 | - * |
|
304 | - * @param int|string $offset |
|
305 | - * @param CanvasObject $value |
|
306 | - * |
|
307 | - * @return void |
|
308 | - * |
|
309 | - * @throws CanvasArray_Exception IMMUTABLE All calls to this method will cause an exception |
|
310 | - * |
|
311 | - * @see http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet |
|
312 | - **/ |
|
313 | - public function offsetSet($offset, $value) |
|
314 | - { |
|
315 | - throw new CanvasArray_Exception( |
|
316 | - 'Canvas responses are immutable', |
|
317 | - CanvasArray_Exception::IMMUTABLE |
|
318 | - ); |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Unset an offset |
|
323 | - * |
|
324 | - * @deprecated Canvas responses are immutable |
|
325 | - * |
|
326 | - * @param int|string $offset |
|
327 | - * |
|
328 | - * @return void |
|
329 | - * |
|
330 | - * @throws CanvasArray_Exception IMMUTABLE All calls to this method will cause an exception |
|
331 | - * |
|
332 | - * @see http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset |
|
333 | - **/ |
|
334 | - public function offsetUnset($offset) |
|
335 | - { |
|
336 | - throw new CanvasArray_Exception( |
|
337 | - 'Canvas responses are immutable', |
|
338 | - CanvasArray_Exception::IMMUTABLE |
|
339 | - ); |
|
340 | - } |
|
341 | - |
|
342 | - /**************************************************************************/ |
|
343 | - |
|
344 | - /************************************************************************** |
|
259 | + /** |
|
260 | + * Whether an offset exists |
|
261 | + * |
|
262 | + * @param int|string $offset |
|
263 | + * |
|
264 | + * @return bool |
|
265 | + * |
|
266 | + * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetExists |
|
267 | + **/ |
|
268 | + public function offsetExists($offset) |
|
269 | + { |
|
270 | + if (isset($this->pagination[CanvasPageLink::LAST])) { |
|
271 | + $lastPageNumber = $this->pagination[CanvasPageLink::LAST]->getPageNumber(); |
|
272 | + if ($this->keyToPageNumber($offset) == $lastPageNumber && |
|
273 | + !isset($this->data[$this->pageNumberToKey($lastPageNumber)])) { |
|
274 | + $this->requestPageNumber($lastPageNumber); |
|
275 | + } |
|
276 | + return isset($this->data[$offset]) || ($offset >= 0 && $offset < $this->pageNumberToKey($lastPageNumber)); |
|
277 | + } else { |
|
278 | + return isset($this->data[$offset]); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Offset to retrieve |
|
284 | + * |
|
285 | + * @param int|string $offset |
|
286 | + * |
|
287 | + * @return CanvasObject|null |
|
288 | + * |
|
289 | + * @see http://php.net/manual/en/arrayaccess.offsetexists.php ArrayAccess::offsetGet |
|
290 | + **/ |
|
291 | + public function offsetGet($offset) |
|
292 | + { |
|
293 | + if ($this->offsetExists($offset) && !isset($this->data[$offset])) { |
|
294 | + $this->requestPageNumber($this->keyToPageNumber($offset)); |
|
295 | + } |
|
296 | + return $this->data[$offset]; |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Assign a value to the specified offset |
|
301 | + * |
|
302 | + * @deprecated Canvas responses are immutable |
|
303 | + * |
|
304 | + * @param int|string $offset |
|
305 | + * @param CanvasObject $value |
|
306 | + * |
|
307 | + * @return void |
|
308 | + * |
|
309 | + * @throws CanvasArray_Exception IMMUTABLE All calls to this method will cause an exception |
|
310 | + * |
|
311 | + * @see http://php.net/manual/en/arrayaccess.offsetset.php ArrayAccess::offsetSet |
|
312 | + **/ |
|
313 | + public function offsetSet($offset, $value) |
|
314 | + { |
|
315 | + throw new CanvasArray_Exception( |
|
316 | + 'Canvas responses are immutable', |
|
317 | + CanvasArray_Exception::IMMUTABLE |
|
318 | + ); |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Unset an offset |
|
323 | + * |
|
324 | + * @deprecated Canvas responses are immutable |
|
325 | + * |
|
326 | + * @param int|string $offset |
|
327 | + * |
|
328 | + * @return void |
|
329 | + * |
|
330 | + * @throws CanvasArray_Exception IMMUTABLE All calls to this method will cause an exception |
|
331 | + * |
|
332 | + * @see http://php.net/manual/en/arrayaccess.offsetunset.php ArrayAccess::offsetUnset |
|
333 | + **/ |
|
334 | + public function offsetUnset($offset) |
|
335 | + { |
|
336 | + throw new CanvasArray_Exception( |
|
337 | + 'Canvas responses are immutable', |
|
338 | + CanvasArray_Exception::IMMUTABLE |
|
339 | + ); |
|
340 | + } |
|
341 | + |
|
342 | + /**************************************************************************/ |
|
343 | + |
|
344 | + /************************************************************************** |
|
345 | 345 | * Iterator methods |
346 | 346 | */ |
347 | 347 | |
348 | - /** |
|
349 | - * Return the current element |
|
350 | - * |
|
351 | - * @return CanvasObject |
|
352 | - * |
|
353 | - * @see http://php.net/manual/en/iterator.current.php Iterator::current |
|
354 | - **/ |
|
355 | - public function current() |
|
356 | - { |
|
357 | - if (!isset($this->data[$this->key])) { |
|
358 | - $this->requestPageNumber($this->keyToPageNumber($this->key)); |
|
359 | - } |
|
360 | - return $this->data[$this->key]; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Return the key of the current element |
|
365 | - * |
|
366 | - * @return int |
|
367 | - * |
|
368 | - * @see http://php.net/manual/en/iterator.key.php Iterator::key |
|
369 | - **/ |
|
370 | - public function key() |
|
371 | - { |
|
372 | - return $this->key; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Move forward to next element |
|
377 | - * |
|
378 | - * @return void |
|
379 | - * |
|
380 | - * @see http://php.net/manual/en/iterator.next.php Iterator::next |
|
381 | - **/ |
|
382 | - public function next() |
|
383 | - { |
|
384 | - $this->key++; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Rewind the iterator to the first element |
|
389 | - * |
|
390 | - * @return void |
|
391 | - * |
|
392 | - * @see http://php.net/manual/en/iterator.rewind.php Iterator::rewind |
|
393 | - **/ |
|
394 | - public function rewind() |
|
395 | - { |
|
396 | - $this->key = 0; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Checks if current position is valid |
|
401 | - * |
|
402 | - * @return bool |
|
403 | - * |
|
404 | - * @see http://php.net/manual/en/iterator.valid.php Iterator::valid |
|
405 | - **/ |
|
406 | - public function valid() |
|
407 | - { |
|
408 | - return ($this->offsetExists($this->key)); |
|
409 | - } |
|
410 | - |
|
411 | - /**************************************************************************/ |
|
412 | - |
|
413 | - /*************************************************************************** |
|
348 | + /** |
|
349 | + * Return the current element |
|
350 | + * |
|
351 | + * @return CanvasObject |
|
352 | + * |
|
353 | + * @see http://php.net/manual/en/iterator.current.php Iterator::current |
|
354 | + **/ |
|
355 | + public function current() |
|
356 | + { |
|
357 | + if (!isset($this->data[$this->key])) { |
|
358 | + $this->requestPageNumber($this->keyToPageNumber($this->key)); |
|
359 | + } |
|
360 | + return $this->data[$this->key]; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Return the key of the current element |
|
365 | + * |
|
366 | + * @return int |
|
367 | + * |
|
368 | + * @see http://php.net/manual/en/iterator.key.php Iterator::key |
|
369 | + **/ |
|
370 | + public function key() |
|
371 | + { |
|
372 | + return $this->key; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Move forward to next element |
|
377 | + * |
|
378 | + * @return void |
|
379 | + * |
|
380 | + * @see http://php.net/manual/en/iterator.next.php Iterator::next |
|
381 | + **/ |
|
382 | + public function next() |
|
383 | + { |
|
384 | + $this->key++; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Rewind the iterator to the first element |
|
389 | + * |
|
390 | + * @return void |
|
391 | + * |
|
392 | + * @see http://php.net/manual/en/iterator.rewind.php Iterator::rewind |
|
393 | + **/ |
|
394 | + public function rewind() |
|
395 | + { |
|
396 | + $this->key = 0; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Checks if current position is valid |
|
401 | + * |
|
402 | + * @return bool |
|
403 | + * |
|
404 | + * @see http://php.net/manual/en/iterator.valid.php Iterator::valid |
|
405 | + **/ |
|
406 | + public function valid() |
|
407 | + { |
|
408 | + return ($this->offsetExists($this->key)); |
|
409 | + } |
|
410 | + |
|
411 | + /**************************************************************************/ |
|
412 | + |
|
413 | + /*************************************************************************** |
|
414 | 414 | * Serializable methods |
415 | 415 | */ |
416 | 416 | |
417 | - /** |
|
418 | - * String representation of CanvasArray |
|
419 | - * |
|
420 | - * @return string |
|
421 | - * |
|
422 | - * @see http://php.net/manual/en/serializable.serialize.php Serializable::serialize() |
|
423 | - **/ |
|
424 | - public function serialize() |
|
425 | - { |
|
426 | - $this->requestAllPages(); |
|
427 | - return serialize( |
|
428 | - array( |
|
429 | - 'page' => $this->page, |
|
430 | - 'key' => $this->key, |
|
431 | - 'data' => $this->data |
|
432 | - ) |
|
433 | - ); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Construct a CanvasArray from its string representation |
|
438 | - * |
|
439 | - * The data in the unserialized CanvasArray is static and cannot be refreshed, |
|
440 | - * as the CanvasPest API connection is _not_ serialized to preserve the |
|
441 | - * security of API access tokens. |
|
442 | - * |
|
443 | - * @param string $data |
|
444 | - * |
|
445 | - * @return string |
|
446 | - * |
|
447 | - * @see http://php.net/manual/en/serializable.unserialize.php Serializable::unserialize() |
|
448 | - **/ |
|
449 | - public function unserialize($data) |
|
450 | - { |
|
451 | - $_data = unserialize($data); |
|
452 | - $this->page = $_data['page']; |
|
453 | - $this->key = $_data['key']; |
|
454 | - $this->data = $_data['data']; |
|
455 | - $this->api = null; |
|
456 | - $this->endpoint = null; |
|
457 | - $this->pagination = array(); |
|
458 | - } |
|
417 | + /** |
|
418 | + * String representation of CanvasArray |
|
419 | + * |
|
420 | + * @return string |
|
421 | + * |
|
422 | + * @see http://php.net/manual/en/serializable.serialize.php Serializable::serialize() |
|
423 | + **/ |
|
424 | + public function serialize() |
|
425 | + { |
|
426 | + $this->requestAllPages(); |
|
427 | + return serialize( |
|
428 | + array( |
|
429 | + 'page' => $this->page, |
|
430 | + 'key' => $this->key, |
|
431 | + 'data' => $this->data |
|
432 | + ) |
|
433 | + ); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Construct a CanvasArray from its string representation |
|
438 | + * |
|
439 | + * The data in the unserialized CanvasArray is static and cannot be refreshed, |
|
440 | + * as the CanvasPest API connection is _not_ serialized to preserve the |
|
441 | + * security of API access tokens. |
|
442 | + * |
|
443 | + * @param string $data |
|
444 | + * |
|
445 | + * @return string |
|
446 | + * |
|
447 | + * @see http://php.net/manual/en/serializable.unserialize.php Serializable::unserialize() |
|
448 | + **/ |
|
449 | + public function unserialize($data) |
|
450 | + { |
|
451 | + $_data = unserialize($data); |
|
452 | + $this->page = $_data['page']; |
|
453 | + $this->key = $_data['key']; |
|
454 | + $this->data = $_data['data']; |
|
455 | + $this->api = null; |
|
456 | + $this->endpoint = null; |
|
457 | + $this->pagination = array(); |
|
458 | + } |
|
459 | 459 | } |
@@ -11,8 +11,8 @@ |
||
11 | 11 | **/ |
12 | 12 | class CanvasPestImmutable_Exception extends CanvasPest_Exception |
13 | 13 | { |
14 | - /** |
|
15 | - * @const IMMUTABLE A request to the API that would change data was attempted |
|
16 | - **/ |
|
17 | - const IMMUTABLE = 1001; |
|
14 | + /** |
|
15 | + * @const IMMUTABLE A request to the API that would change data was attempted |
|
16 | + **/ |
|
17 | + const IMMUTABLE = 1001; |
|
18 | 18 | } |
@@ -18,69 +18,69 @@ |
||
18 | 18 | **/ |
19 | 19 | class CanvasPestImmutable extends CanvasPest |
20 | 20 | { |
21 | - /** |
|
22 | - * {@inheritDoc} |
|
23 | - * |
|
24 | - * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
25 | - * |
|
26 | - * @param string $path Path to the API endpoint of this call |
|
27 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
28 | - * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
29 | - * for this call |
|
30 | - * @return void |
|
31 | - * |
|
32 | - * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
33 | - * will cause an exception |
|
34 | - **/ |
|
35 | - public function put($path, $data = array(), $headers = array()) |
|
36 | - { |
|
37 | - throw new CanvasPestImmutable_Exception( |
|
38 | - 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
39 | - CanvasPestImmutable_Exception::IMMUTABLE |
|
40 | - ); |
|
41 | - } |
|
21 | + /** |
|
22 | + * {@inheritDoc} |
|
23 | + * |
|
24 | + * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
25 | + * |
|
26 | + * @param string $path Path to the API endpoint of this call |
|
27 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
28 | + * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
29 | + * for this call |
|
30 | + * @return void |
|
31 | + * |
|
32 | + * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
33 | + * will cause an exception |
|
34 | + **/ |
|
35 | + public function put($path, $data = array(), $headers = array()) |
|
36 | + { |
|
37 | + throw new CanvasPestImmutable_Exception( |
|
38 | + 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
39 | + CanvasPestImmutable_Exception::IMMUTABLE |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - * |
|
46 | - * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
47 | - * |
|
48 | - * @param string $path Path to the API endpoint of this call |
|
49 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
50 | - * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
51 | - * for this call |
|
52 | - * @return void |
|
53 | - * |
|
54 | - * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
55 | - * will cause an exception |
|
56 | - **/ |
|
57 | - public function post($path, $data = array(), $headers = array()) |
|
58 | - { |
|
59 | - throw new CanvasPestImmutable_Exception( |
|
60 | - 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
61 | - CanvasPestImmutable_Exception::IMMUTABLE |
|
62 | - ); |
|
63 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + * |
|
46 | + * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
47 | + * |
|
48 | + * @param string $path Path to the API endpoint of this call |
|
49 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
50 | + * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
51 | + * for this call |
|
52 | + * @return void |
|
53 | + * |
|
54 | + * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
55 | + * will cause an exception |
|
56 | + **/ |
|
57 | + public function post($path, $data = array(), $headers = array()) |
|
58 | + { |
|
59 | + throw new CanvasPestImmutable_Exception( |
|
60 | + 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
61 | + CanvasPestImmutable_Exception::IMMUTABLE |
|
62 | + ); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * {@inheritDoc} |
|
67 | - * |
|
68 | - * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
69 | - * |
|
70 | - * @param string $path Path to the API endpoint of this call |
|
71 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
72 | - * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
73 | - * for this call |
|
74 | - * @return void |
|
75 | - * |
|
76 | - * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
77 | - * will cause an exception |
|
78 | - **/ |
|
79 | - public function delete($path, $data = array(), $headers = array()) |
|
80 | - { |
|
81 | - throw new CanvasPestImmutable_Exception( |
|
82 | - 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
83 | - CanvasPestImmutable_Exception::IMMUTABLE |
|
84 | - ); |
|
85 | - } |
|
65 | + /** |
|
66 | + * {@inheritDoc} |
|
67 | + * |
|
68 | + * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
69 | + * |
|
70 | + * @param string $path Path to the API endpoint of this call |
|
71 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
72 | + * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
73 | + * for this call |
|
74 | + * @return void |
|
75 | + * |
|
76 | + * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
77 | + * will cause an exception |
|
78 | + **/ |
|
79 | + public function delete($path, $data = array(), $headers = array()) |
|
80 | + { |
|
81 | + throw new CanvasPestImmutable_Exception( |
|
82 | + 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
83 | + CanvasPestImmutable_Exception::IMMUTABLE |
|
84 | + ); |
|
85 | + } |
|
86 | 86 | } |