From 4aa8f5b1145b0d67e7169a80efef775319416a50 Mon Sep 17 00:00:00 2001 From: Jan Vansteenlandt Date: Tue, 8 Sep 2015 15:59:09 +0200 Subject: [PATCH] Fix json validator --- app/Tdt/Core/BaseController.php | 2 -- app/Tdt/Core/Definitions/DefinitionController.php | 2 -- .../Core/Repositories/JsonDefinitionRepository.php | 2 +- app/Tdt/Core/Validators/CustomValidator.php | 13 +++++++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Tdt/Core/BaseController.php b/app/Tdt/Core/BaseController.php index 8c1845a2..fc67f8bf 100644 --- a/app/Tdt/Core/BaseController.php +++ b/app/Tdt/Core/BaseController.php @@ -97,11 +97,9 @@ public function handleRequest($uri) // Check the response type if ($response instanceof \Illuminate\Http\RedirectResponse) { - // Redirect and that's it return $response; } else { - // Make sure cross origin requests are allowed for GET $response->header('Access-Control-Allow-Origin', '*'); $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE'); diff --git a/app/Tdt/Core/Definitions/DefinitionController.php b/app/Tdt/Core/Definitions/DefinitionController.php index 741f9440..e12a3bab 100644 --- a/app/Tdt/Core/Definitions/DefinitionController.php +++ b/app/Tdt/Core/Definitions/DefinitionController.php @@ -19,7 +19,6 @@ */ class DefinitionController extends ApiController { - protected $definition; public function __construct(DefinitionRepositoryInterface $definition) @@ -145,7 +144,6 @@ public function get($uri) Auth::requirePermissions('definition.view'); if (!empty($uri)) { - if (!$this->definition->exists($uri)) { \App::abort(404, "No resource was found identified with " . $uri); } diff --git a/app/Tdt/Core/Repositories/JsonDefinitionRepository.php b/app/Tdt/Core/Repositories/JsonDefinitionRepository.php index e29a63db..20d78f8e 100644 --- a/app/Tdt/Core/Repositories/JsonDefinitionRepository.php +++ b/app/Tdt/Core/Repositories/JsonDefinitionRepository.php @@ -9,7 +9,7 @@ class JsonDefinitionRepository extends BaseDefinitionRepository implements JsonD { protected $rules = array( - 'uri' => 'json|uri|required', + 'uri' => 'json|required', 'description' => 'required', ); diff --git a/app/Tdt/Core/Validators/CustomValidator.php b/app/Tdt/Core/Validators/CustomValidator.php index 98ba5f14..abb4a8e9 100644 --- a/app/Tdt/Core/Validators/CustomValidator.php +++ b/app/Tdt/Core/Validators/CustomValidator.php @@ -48,8 +48,17 @@ public function validateJson($attribute, $value, $parameters) { try { - - $data = json_decode(file_get_contents($value)); + $data = []; + + if (!filter_var($value, FILTER_VALIDATE_URL) === false) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $value); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec($ch); + curl_close($ch); + } else { + $data =@ file_get_contents($value); + } if (empty($data)) { return false;