@@ -48,6 +48,8 @@ PHP_JWT_API zend_class_entry *jwt_invalid_jti_cex;
4848PHP_JWT_API zend_class_entry * jwt_invalid_iat_cex ;
4949PHP_JWT_API zend_class_entry * jwt_invalid_sub_cex ;
5050
51+ static zend_class_entry * jwt_ce ;
52+
5153ZEND_DECLARE_MODULE_GLOBALS (jwt )
5254
5355ZEND_BEGIN_ARG_INFO_EX (arginfo_jwt_encode , 0 , 0 , 2 )
@@ -454,9 +456,8 @@ int jwt_parse_options(zval *options)
454456 return 0 ;
455457}
456458
457- /* function jwt_encode() */
458- PHP_FUNCTION (jwt_encode )
459- {
459+ /* Jwt encode */
460+ static void php_jwt_encode (INTERNAL_FUNCTION_PARAMETERS ) {
460461 zval * payload = NULL , header ;
461462 zend_string * key = NULL ;
462463 smart_str json_header = {0 }, json_payload = {0 }, segments = {0 };
@@ -545,9 +546,8 @@ PHP_FUNCTION(jwt_encode)
545546 }
546547}
547548
548- /* function jwt_decode() */
549- PHP_FUNCTION (jwt_decode )
550- {
549+ /* Jwt decode */
550+ static void php_jwt_decode (INTERNAL_FUNCTION_PARAMETERS ) {
551551 zend_string * token = NULL , * key = NULL ;
552552 zval * options = NULL ;
553553 smart_str segments = {0 };
@@ -652,12 +652,42 @@ PHP_FUNCTION(jwt_decode)
652652 jwt_free (jwt );
653653}
654654
655- const zend_function_entry jwt_functions [] = {
655+ /* function jwt_encode() */
656+ PHP_FUNCTION (jwt_encode )
657+ {
658+ php_jwt_encode (INTERNAL_FUNCTION_PARAM_PASSTHRU );
659+ }
660+
661+ /* function jwt_decode() */
662+ PHP_FUNCTION (jwt_decode )
663+ {
664+ php_jwt_decode (INTERNAL_FUNCTION_PARAM_PASSTHRU );
665+ }
666+
667+ /* JWT::encode() */
668+ PHP_METHOD (jwt , encode )
669+ {
670+ php_jwt_encode (INTERNAL_FUNCTION_PARAM_PASSTHRU );
671+ }
672+
673+ /* JWT::decode() */
674+ PHP_METHOD (jwt , decode )
675+ {
676+ php_jwt_decode (INTERNAL_FUNCTION_PARAM_PASSTHRU );
677+ }
678+
679+ static const zend_function_entry jwt_functions [] = {
656680 PHP_FE (jwt_encode , arginfo_jwt_encode )
657681 PHP_FE (jwt_decode , arginfo_jwt_decode )
658682 PHP_FE_END
659683};
660684
685+ static const zend_function_entry jwt_methods [] = {
686+ PHP_ME (jwt , encode , arginfo_jwt_encode , ZEND_ACC_STATIC | ZEND_ACC_PUBLIC )
687+ PHP_ME (jwt , decode , arginfo_jwt_decode , ZEND_ACC_STATIC | ZEND_ACC_PUBLIC )
688+ {NULL , NULL , NULL }
689+ };
690+
661691/* GINIT */
662692PHP_GINIT_FUNCTION (jwt ) {
663693 jwt_globals -> expiration = 0 ;
@@ -673,6 +703,11 @@ PHP_GINIT_FUNCTION(jwt) {
673703
674704PHP_MINIT_FUNCTION (jwt )
675705{
706+ zend_class_entry ce ;
707+
708+ INIT_CLASS_ENTRY (ce , "Cdoco\\JWT" , jwt_methods );
709+ jwt_ce = zend_register_internal_class (& ce );
710+
676711 /* register exception class */
677712 jwt_signature_invalid_cex = jwt_register_class ("SignatureInvalidException" );
678713 jwt_before_valid_cex = jwt_register_class ("BeforeValidException" );
0 commit comments