Bolt\Twig\Handler\TextHandler::testJson PHP Метод

testJson() публичный Метод

Test whether a passed string contains valid JSON.
public testJson ( string $string ) : boolean
$string string The string to test.
Результат boolean
    public function testJson($string)
    {
        if (is_scalar($string) || is_callable([$string, '__toString'])) {
            json_decode((string) $string, true);
            return json_last_error() === JSON_ERROR_NONE;
        }
        return false;
    }

Usage Example

Пример #1
0
 public function testTestJsonInvalid()
 {
     $app = $this->getApp();
     $handler = new TextHandler($app);
     $result = $handler->testJson('koala');
     $this->assertFalse($result);
 }