public function requestApiResource()
 {
     if (!is_null(request()->route())) {
         if (request()->route()->getName() == "api.endpoint.root") {
             return ApiResponse::CreateResponse(ApiResponse::API_OK, ["info" => "This URL is an API Endpoint URI, used to query specific data based on provided configuration. In order to make use of this API Endpoint, please provide the correct Endpoint Resource, or contact the administrator of this web site for more information"]);
         }
     }
     $resourceDataProvider = $this->apiEndpointHost->resourceDataProvider;
     if (empty(trim($resourceDataProvider))) {
         return ApiResponse::CreateResponse(ApiResponse::API_INVALID_CONFIGURATION);
     }
     $resourceDataProviderMethod = $this->apiEndpointHost->resourceDataProviderMethod;
     if (empty(trim($resourceDataProviderMethod))) {
         return ApiResponse::CreateResponse(ApiResponse::API_INVALID_CONFIGURATION);
     }
     $theDataProvider = new $resourceDataProvider();
     $params = [];
     foreach ($this->apiEndpointHost->resourceRequestParams as $param) {
         if (!isset($this->apiEndpointHost->routeParams[$param])) {
             return ApiResponse::CreateResponse(ApiResponse::API_INSUFFICIENT_INPUT_PARAMS);
         }
         $params[$param] = $this->apiEndpointHost->routeParams[$param];
     }
     // Call Application Method
     $data = $theDataProvider::$resourceDataProviderMethod($params);
     // Return Result
     return $data ? ApiResponse::CreateResponse(ApiResponse::API_OK, $data) : ApiResponse::CreateResponse(ApiResponse::API_NOT_FOUND);
 }
Пример #2
0
 public function validateApiResourcePath()
 {
     // Clear the Response object
     $this->clearResponse();
     // Get the current API Resource Path
     $routePath = $this->getResourcePath();
     // Validate
     if (array_key_exists($routePath, $this->validApiResourcePaths) || config("apiendpointhost.showRootResourceInfo") === true && request()->route()->getName() == "api.endpoint.root") {
         return true;
     }
     // Host Validation failed. Set the response object
     $this->setResponse(ApiResponse::CreateResponse(ApiResponse::API_INVALID_RESOURCE));
     // Return ubhappiness
     return false;
 }