src/SimpleJWT/Util/Helper.php
/**
     * Attempts to detect the format of JWT or JWE encoded data.
     *
     * @param string $data the encoded data
     * @return mixed an array with keys `type` and `format`
     * (see {@link getType()} and {@link getFormat()}), or `null`
     * if the format cannot be detected
     */
Attempts to detect the format of JWT or JWE encoded data.
Attempts to detect the format of JWT or JWE encoded data .
static function detect($data) {
        $results = [];
        $obj = json_decode($data, true);
        if ($obj == null) {
            $dot_count = substr_count($data, '.');
            if ($dot_count == 2) {
                $results['type'] = 'JWT';
                $results['format'] = self::COMPACT_FORMAT;
            } elseif ($dot_count == 4) {
                $results['type'] = 'JWE';
                $results['format'] = self::COMPACT_FORMAT;
            }
        } else {
            if (isset($obj['signature']) || isset($obj['signatures'])) {
                $results['type'] = 'JWT';
                $results['format'] = self::JSON_FORMAT;
            } elseif (isset($obj['ciphertext'])) {
                $results['type'] = 'JWE';
                $results['format'] = self::JSON_FORMAT;
            }
        }
        return (isset($results['type'])) ? $results : null;
    }
static function detect ( $ data ) { $ results = [ ] ; $ obj = json_decode ( $ data , true ) ; if ( $ obj == null ) { $ dot_count = substr_count ( $ data , '.' ) ; if ( $ dot_count == 2 ) { $ results [ 'type' ] = 'JWT' ; $ results [ 'format' ] = self :: COMPACT_FORMAT ; } elseif ( $ dot_count == 4 ) { $ results [ 'type' ] = 'JWE' ; $ results [ 'format' ] = self :: COMPACT_FORMAT ; } } else { if ( isset ( $ obj [ 'signature' ] ) || isset ( $ obj [ 'signatures' ] ) ) { $ results [ 'type' ] = 'JWT' ; $ results [ 'format' ] = self :: JSON_FORMAT ; } elseif ( isset ( $ obj [ 'ciphertext' ] ) ) { $ results [ 'type' ] = 'JWE' ; $ results [ 'format' ] = self :: JSON_FORMAT ; } } return ( isset ( $ results [ 'type' ] ) ) ? $ results : null ; }
Attempts to detect the format of JWT or JWE encoded data.
Attempts to detect the format of JWT or JWE encoded data .