All.php
6 years ago
Create.php
6 years ago
Delete.php
6 years ago
NestedResource.php
6 years ago
Request.php
6 years ago
Retrieve.php
6 years ago
Update.php
6 years ago
All.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Stripe\ApiOperations; |
| 4 | |
| 5 | /** |
| 6 | * Trait for listable resources. Adds a `all()` static method to the class. |
| 7 | * |
| 8 | * This trait should only be applied to classes that derive from StripeObject. |
| 9 | */ |
| 10 | trait All |
| 11 | { |
| 12 | /** |
| 13 | * @param array|null $params |
| 14 | * @param array|string|null $opts |
| 15 | * |
| 16 | * @return \Stripe\Collection of ApiResources |
| 17 | */ |
| 18 | public static function all($params = null, $opts = null) |
| 19 | { |
| 20 | self::_validateParams($params); |
| 21 | $url = static::classUrl(); |
| 22 | |
| 23 | list($response, $opts) = static::_staticRequest('get', $url, $params, $opts); |
| 24 | $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts); |
| 25 | if (!is_a($obj, 'Stripe\\Collection')) { |
| 26 | $class = get_class($obj); |
| 27 | $message = "Expected type \"Stripe\\Collection\", got \"$class\" instead"; |
| 28 | throw new \Stripe\Error\Api($message); |
| 29 | } |
| 30 | $obj->setLastResponse($response); |
| 31 | $obj->setRequestParams($params); |
| 32 | return $obj; |
| 33 | } |
| 34 | } |
| 35 |