コード例 #1
0
ファイル: Endpoint.php プロジェクト: mentos1386/opencrest
 /**
  * Create Previous Page from data we received
  *
  * @param array $options
  * @return ObjectInterface
  * @throws ApiException
  */
 function previousPage($options = [])
 {
     $uri = $this->object->getAttribute("uri");
     // Check if next page exists
     if (!array_key_exists("previousPage", $this->object->getAttribute("values"))) {
         throw new ApiException("There is no previous page!");
     }
     // Add page query to get next page
     $options["query"] = "page=" . $this->object->getAttribute("values")["previousPage"]["page"];
     // If Async is enabled, we use httpAsyncGet function to make requests
     if (!OpenCrest::$async) {
         $content = $this->http("get", $uri, $options);
         return $this->factory->create($this->object, $content, $this->response);
     }
     // We make Async request and return null as data isn't available yet
     $this->httpAsync("get", $uri, $options);
     return null;
 }
コード例 #2
0
ファイル: Factory.php プロジェクト: mentos1386/opencrest
 /**
  * Custom make function, as ListObject is differently processed
  *
  * @param ObjectInterface $object
  * @param array           $data
  * @return ObjectInterface
  */
 private function createList(ObjectInterface $object, array $data)
 {
     // We check if items are inside in items array, or directly
     if (isset($data['items'])) {
         $items = $data['items'];
     } else {
         $items = $data;
     }
     $values = [];
     $values["totalCount"] = isset($data['totalCount']) ? $data['totalCount'] : count($items);
     $values["pageCount"] = isset($data['pageCount']) ? $data['pageCount'] : 0;
     $values += $this->parsePages($data);
     $values['items'] = [];
     foreach ($items as $item) {
         // TODO: $types->dogma->attributes->items[0] returns values inside "attribute" array, same with dogma->effects->items[0]
         if (isset($item["attribute"])) {
             $item = $item["attribute"];
         } elseif (isset($item['effect'])) {
             $item = $item["effect"];
         }
         // Create new object
         $newItem = $this->create(clone $object, $item);
         // In rare cases, you can get object listing through one endpoint, but get specific object through another
         // This is the case for regions->buy/sellOrders where you get list of orders, but you access those orders
         if ($object->getAttribute("listUri")) {
             $newItem->setAttribute("uri", $object->getAttribute("listUri"));
         }
         // Push item to items
         array_push($values['items'], $newItem);
     }
     // Set all values
     $object->setValues($values);
     return $object;
 }