1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php namespace Client\Request;
- abstract class RequestBase implements RequestInterface {
- protected $loaded = false;
- protected $scope;
- use \Lib\Curl {
- get as protected mget;
- }
- public function __construct($api_url, $api_token) {
- $this->url = $api_url;
- $this->token = $api_token;
- $this->set_scope();
- }
- public function load($force = false) {
- if ($this->loaded && !$force)
- return $this;
- $jenc = $this->mget();
- $this->json_set_property($this->json_decode($jenc));
- $this->loaded = true;
- return $this;
- }
- public function get($scope) {
- throw new NotImplementedException("Method not implemented for " . __CLASS__ . ", cant lookup " . $scope);
- }
- public function create() {
- throw new NotImplementedException("Method not implemented for " . __CLASS__ . ", cant create");
- }
- public function patch() {
- throw new NotImplementedException("Method not implemented for " . __CLASS__ . ", cant create");
- }
- public function delete() {
- throw new NotImplementedException("Method not implemented for " . __CLASS__ . ", cant create");
- }
- private function json_decode($jenc) {
- $obj = json_decode($jenc);
- if (($err = json_last_error()) != JSON_ERROR_NONE)
- throw new RequestErrorException(json_last_error_msg(), $err);
- return $obj;
- }
- abstract protected function json_set_property($obj);
- abstract protected function set_scope();
- public function __destruct() {}
- }
- ?>
|