Exemplo n.º 1
0
 /**
  * Get failure.
  *
  * @return array
  */
 public final function getFail()
 {
     // set default
     $fail = array('code' => Exception::UNKNOWN_ERROR_CODE, 'message' => Exception::UNKNOWN_ERROR_MESSAGE);
     if ($this->type == self::TYPE_REQUEST) {
         if ($this->isFail()) {
             $fail['code'] = $this->getFailCode();
             $fail['message'] = $this->getFailText();
         }
     } elseif ($this->type == self::TYPE_RESPONSE) {
         $bodyData = Util::toObject((array) $this->bodyData, false);
         // check first body for errors (differs by requests)
         if (isset($bodyData->msg)) {
             $fail['code'] = $this->getStatusCode();
             $fail['message'] = $bodyData->msg;
         } elseif (isset($bodyData->status, $bodyData->error)) {
             $fail['code'] = $bodyData->status;
             $fail['message'] = $bodyData->error;
         } elseif ($this->getStatusCode() >= 400) {
             $fail['code'] = $this->getStatusCode();
             $fail['message'] = $this->getStatusText();
         }
     }
     return $fail;
 }
 /**
  * Fill a lib's node object.
  *
  * @param  GraphCommons\Graph\Entity\GraphNode $node
  * @param  array|object $g
  * @return GraphCommons\Graph\Entity\GraphNode
  */
 public final function fillNode(GraphNode $node, $n)
 {
     // force input being an object
     $n = Util::toObject($n);
     if (isset($n->id)) {
         $node->setId($n->id)->setName($n->name)->setDescription($n->description);
         // add suspected (nullable) properties
         if (isset($n->image)) {
             $node->setImage($n->image);
         }
         if (isset($n->created_at)) {
             $node->setCreatedAt($n->created_at);
         }
         if (isset($n->updated_at)) {
             $node->setUpdatedAt($n->updated_at);
         }
         if (isset($n->properties)) {
             $node->setProperties($n->properties);
         }
         if (isset($n->hubs, $n->users, $n->graphs, $n->graphs_count)) {
             $node->setHubs((array) $n->hubs)->setUsers((array) $n->users)->setGraphs((array) $n->graphs)->setGraphsCount($n->graphs_count);
         }
         // add node type as GraphCommons\Graph\Entity\NodeType
         $nodeType = new GraphNodeType();
         if (isset($n->nodetype)) {
             $nodeType->setId($n->nodetype->id)->setName($n->nodetype->name)->setColor($n->nodetype->color);
             $node->setTypeId($n->nodetype->id);
         } elseif (isset($n->type, $n->type_id)) {
             $nodeType->setId($n->type_id)->setName($n->type);
             $node->setTypeId($n->type_id);
         }
         $node->setType($nodeType);
     }
     return $node;
 }