digikraaft /
abokifx-php
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Digikraaft\Abokifx; |
||
| 4 | |||
| 5 | use Digikraaft\Abokifx\Exceptions\InvalidArgumentException; |
||
| 6 | |||
| 7 | class ApiResource |
||
| 8 | { |
||
| 9 | const OBJECT_NAME = null; |
||
| 10 | |||
| 11 | use ApiOperations\Request; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @return string the base URL for the given class |
||
| 15 | */ |
||
| 16 | public static function baseUrl() |
||
| 17 | { |
||
| 18 | return Abokifx::$apiBaseUrl; |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return string the endpoint URL for the given class |
||
| 23 | */ |
||
| 24 | public static function classUrl() |
||
| 25 | { |
||
| 26 | $base = static::OBJECT_NAME; |
||
| 27 | |||
| 28 | return "{$base}"; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $slug |
||
| 33 | * |
||
| 34 | * @return string the endpoint URL for the given class |
||
| 35 | */ |
||
| 36 | public static function endPointUrl($slug) |
||
| 37 | { |
||
| 38 | $slug = Util\Util::utf8($slug); |
||
| 39 | $base = static::classUrl(); |
||
| 40 | |||
| 41 | return "{$base}/{$slug}"; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param string $slug |
||
| 46 | * @param null $params array of query parameters |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 47 | * |
||
| 48 | * @return string the endpoint URL for the given class |
||
| 49 | */ |
||
| 50 | public static function buildQueryString($slug, $params = null) |
||
| 51 | { |
||
| 52 | $url = self::endPointUrl($slug); |
||
| 53 | if (! empty($params)) { |
||
| 54 | $url .= '?'.http_build_query($params); |
||
| 55 | } |
||
| 56 | |||
| 57 | return $url; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param $id |
||
| 62 | * @return string |
||
| 63 | * @throws InvalidArgumentException |
||
| 64 | */ |
||
| 65 | public static function resourceUrl($id) |
||
| 66 | { |
||
| 67 | if (null === $id) { |
||
| 68 | $message = 'Invalid ID supplied. ID cannot be null'; |
||
| 69 | |||
| 70 | throw new InvalidArgumentException($message); |
||
| 71 | } |
||
| 72 | $id = Util\Util::utf8($id); |
||
| 73 | $base = static::classUrl(); |
||
| 74 | $extn = urlencode($id); |
||
| 75 | |||
| 76 | return "{$base}/{$extn}"; |
||
| 77 | } |
||
| 78 | } |
||
| 79 |