Ejemplo n.º 1
0
 /**
  * Process input information to verify it is valid
  * and classify request for further processing.
  * 
  * @return boolean : true if rquest is valid
  */
 function isValid()
 {
     // Primary record must not be empty
     if ($this->record == null) {
         return false;
     }
     // Primary record should exist in restful api configuration file
     if (!array_key_exists($this->record, \restfulConfig::getObjects())) {
         return false;
     }
     // If no more parameters, request type should be GET or POST
     if ($this->recordId === null) {
         switch ($this->getRequestType()) {
             case "GET":
                 $this->requestType = RestfulRequest::TYPE_GET_RECORD_LIST;
                 return true;
             case "POST":
                 $this->requestType = RestfulRequest::TYPE_POST_RECORD;
                 return true;
             default:
                 return false;
         }
     }
     // If recordId exists, it must be a valid id (number)
     if (!is_numeric($this->recordId)) {
         return false;
     }
     // If no subrecord, type should be GET, PUT or DELETE
     if ($this->subRecord === null) {
         switch ($this->getRequestType()) {
             case "GET":
                 $this->requestType = RestfulRequest::TYPE_GET_RECORD;
                 return true;
             case "PUT":
                 $this->requestType = RestfulRequest::TYPE_PUT_RECORD;
                 return true;
             case "DELETE":
                 $this->requestType = RestfulRequest::TYPE_DELETE_RECORD;
                 return true;
             default:
                 return false;
         }
     }
     // Subrecord should exist in restful api configuration file
     if (!array_key_exists($this->subRecord, \restfulConfig::getObjects()[$this->record])) {
         return false;
     }
     // If no subrecordID, type should be GET or POST
     if ($this->subRecordId === null) {
         switch ($this->getRequestType()) {
             case "GET":
                 $this->requestType = RestfulRequest::TYPE_GET_SUBRECORD_LIST;
                 return true;
             case "POST":
                 $this->requestType = RestfulRequest::TYPE_POST_SUBRECORD;
                 return true;
             default:
                 return false;
         }
     }
     // If subrecordId exists, it must be a valid id (number)
     if (!is_numeric($this->subRecordId)) {
         return false;
     }
     // If subrecord ID is present, type could be GET, PUT or DELETE.
     switch ($this->getRequestType()) {
         case "GET":
             $this->requestType = RestfulRequest::TYPE_GET_SUBRECORD;
             return true;
         case "PUT":
             $this->requestType = RestfulRequest::TYPE_PUT_SUBRECORD;
             return true;
         case "DELETE":
             $this->requestType = RestfulRequest::TYPE_DELETE_SUBRECORD;
             return true;
         default:
             return false;
     }
 }
Ejemplo n.º 2
0
                vertical-align: top;
                border-bottom: 1px solid #ddd;
            }


        </style>

    </head>

    <body>

        <h1>Todo List API Documentation</h1>
        <h2>Data Structure</h2>

        <?php 
$objectTree = restfulConfig::getObjects();
$objects = array();
foreach ($objectTree as $key => $value) {
    echo $key . ' <span class="light">(record)</span><br>';
    $objects[$key] = '';
    foreach ($value as $key2 => $value2) {
        echo "&nbsp;&nbsp; - " . $key2 . ' <span class="light">(subrecord)</span><br>';
        $objects[$key2] = '';
    }
}
echo "<h2>Data Objects Definition</h2>";
foreach ($objects as $key => $value) {
    echo "<h3>" . $key . "</h3>";
    $object = new $key();
    echo "<b>Fields:</b>";
    echo "<ul>";