-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move JSON validation to derived class.
- Loading branch information
Showing
5 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Srmklive\PayPal\Services; | ||
|
||
use GuzzleHttp\Utils; | ||
|
||
class Str extends \Illuminate\Support\Str | ||
{ | ||
/** | ||
* Determine if a given value is valid JSON. | ||
* | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public static function isJson($value): bool | ||
{ | ||
if (!is_string($value)) { | ||
return false; | ||
} | ||
|
||
if (function_exists('json_validate')) { | ||
return json_validate($value, 512); | ||
} | ||
|
||
try { | ||
Utils::jsonDecode($value, true, 512, 4194304); | ||
} catch (\JsonException $jsonException) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters