Skip to content

Commit

Permalink
Fix json validator
Browse files Browse the repository at this point in the history
  • Loading branch information
coreation committed Sep 8, 2015
1 parent f7e6d79 commit 4aa8f5b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 0 additions & 2 deletions app/Tdt/Core/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 0 additions & 2 deletions app/Tdt/Core/Definitions/DefinitionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
class DefinitionController extends ApiController
{

protected $definition;

public function __construct(DefinitionRepositoryInterface $definition)
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Tdt/Core/Repositories/JsonDefinitionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class JsonDefinitionRepository extends BaseDefinitionRepository implements JsonD
{

protected $rules = array(
'uri' => 'json|uri|required',
'uri' => 'json|required',
'description' => 'required',
);

Expand Down
13 changes: 11 additions & 2 deletions app/Tdt/Core/Validators/CustomValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4aa8f5b

Please sign in to comment.