]> granicus.if.org Git - php/commitdiff
Implement Bug #54649 Create session_serializer_name()
authorYasuo Ohgaki <yohgaki@php.net>
Sat, 10 Aug 2013 00:26:10 +0000 (09:26 +0900)
committerYasuo Ohgaki <yohgaki@php.net>
Sat, 10 Aug 2013 00:26:10 +0000 (09:26 +0900)
NEWS
ext/session/session.c
ext/session/tests/session_serializer_name_basic.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 02fa05ede8d81fb5624a093dd95a435d79fe1e26..f9cb504aa24a295bbf416e652479113f6755d231 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ PHP                                                                        NEWS
 - Session:
   . Fixed Bug #65315 (session.hash_function silently fallback to default md5)
     (Yasuo)
+  . Implemented Request #54649 (Create session_serializer_name()). (Yasuo)
 
 - mysqlnd:
   . Disabled flag for SP OUT variables for 5.5+ servers as they are not natively
index aee3308568b38b3027302698647023fd5b2d7052..278f954bdfee5649d508e7af175016de9edb2fa1 100644 (file)
@@ -1647,6 +1647,31 @@ static PHP_FUNCTION(session_module_name)
 }
 /* }}} */
 
+/* {{{ proto mixed session_serializer_name([string newname])
+   Return the current serializer name used for encode/decode session data. If newname is given, the serialzer name is replaced with newname and return bool */
+static PHP_FUNCTION(session_serializer_name)
+{
+       char *name = NULL;
+       int name_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) {
+               return;
+       }
+
+       /* Return serializer name */
+       if (!name) {
+               RETURN_STRING(zend_ini_string("session.serialize_handler", sizeof("session.serialize_handler"), 0), 1);
+       }
+
+       /* Set serializer name */
+       if (zend_alter_ini_entry("session.serialize_handler", sizeof("session.serialize_handler"), name, name_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == SUCCESS) {
+               RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
+
 /* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid)
    Sets user-level functions */
 static PHP_FUNCTION(session_set_save_handler)
@@ -2068,6 +2093,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_session_module_name, 0, 0, 0)
        ZEND_ARG_INFO(0, module)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_session_serializer_name, 0, 0, 0)
+       ZEND_ARG_INFO(0, module)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_session_save_path, 0, 0, 0)
        ZEND_ARG_INFO(0, path)
 ZEND_END_ARG_INFO()
@@ -2147,6 +2176,7 @@ ZEND_END_ARG_INFO()
 static const zend_function_entry session_functions[] = {
        PHP_FE(session_name,              arginfo_session_name)
        PHP_FE(session_module_name,       arginfo_session_module_name)
+       PHP_FE(session_serializer_name,   arginfo_session_serializer_name)
        PHP_FE(session_save_path,         arginfo_session_save_path)
        PHP_FE(session_id,                arginfo_session_id)
        PHP_FE(session_regenerate_id,     arginfo_session_regenerate_id)
diff --git a/ext/session/tests/session_serializer_name_basic.phpt b/ext/session/tests/session_serializer_name_basic.phpt
new file mode 100644 (file)
index 0000000..ca292dd
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+Test session_serializer_name() function : basic functionality
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+/*
+ * Prototype : mixed session_serializer_name([string name])
+ * Description : Change/get serialize handler name
+ * Source code : ext/session/session.c
+ */
+
+echo "*** Testing session_serializer_name() : basic functionality ***\n";
+
+var_dump(session_serializer_name());
+var_dump(session_serializer_name('php'));
+var_dump(session_serializer_name('php_binary'));
+var_dump(session_serializer_name('none'));
+var_dump(session_serializer_name());
+
+echo "Done";
+ob_end_flush();
+?>
+--EXPECTF--
+*** Testing session_serializer_name() : basic functionality ***
+string(3) "php"
+bool(true)
+bool(true)
+
+Warning: session_serializer_name(): Cannot find serialization handler 'none' in %s/session_serializer_name_basic.php on line 16
+bool(false)
+string(10) "php_binary"
+Done
+