php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53065
Patch spl_autoload_case_sensitive revision 2010-12-27 14:34 UTC by marc at easen dot co dot uk

Patch spl_autoload_case_sensitive for SPL related Bug #53065

Patch version 2010-12-27 14:34 UTC

Return to Bug #53065 | Download this patch
Patch Revisions:

Developer: marc@easen.co.uk

Index: ext/spl/spl.php
===================================================================
--- ext/spl/spl.php	(revision 306670)
+++ ext/spl/spl.php	(working copy)
@@ -199,6 +199,16 @@
 function spl_autoload_extensions($file_extensions) {/**/};
 
 /** @ingroup SPL
+ * @brief Register and returns the use case sensitive file naming flag
+ * @since PHP 5.x
+ *
+ * @param use_case_sensitive_file_naming optional comma separated list of extensions to use in
+ *        default autoload function. If not given just return the current list.
+ * @return bool the value of the case sensitive flag
+ */
+function spl_autoload_case_sensitive($use_case_sensitive_file_naming = null) {/**/};
+
+/** @ingroup SPL
  * @brief Return all registered autoload functionns
  * @since PHP 5.1
  *
Index: ext/spl/tests/TestClassCS.php.inc
===================================================================
--- ext/spl/tests/TestClassCS.php.inc	(revision 0)
+++ ext/spl/tests/TestClassCS.php.inc	(revision 0)
@@ -0,0 +1,12 @@
+<?php
+
+if (1 === preg_match('/TestClassCS.php.inc$/', __FILE__))
+{
+	echo __FILE__ . "\n";
+
+	class TestClassCS
+	{
+	}
+}
+
+?>
\ No newline at end of file

Property changes on: ext/spl/tests/TestClassCS.php.inc
___________________________________________________________________
Added: svn:executable
   + *

Index: ext/spl/tests/spl_autoload_015.phpt
===================================================================
--- ext/spl/tests/spl_autoload_015.phpt	(revision 0)
+++ ext/spl/tests/spl_autoload_015.phpt	(revision 0)
@@ -0,0 +1,70 @@
+--TEST--
+SPL: spl_autoload_case_sensitive()
+--INI--
+include_path=.
+--FILE--
+<?php
+
+if (spl_autoload_case_sensitive() == false) {
+	echo "return spl_autoload_case_sensitive() == FALSE\n";
+} else { 
+	echo "return spl_autoload_case_sensitive() == TRUE\n";
+}
+$retVal = spl_autoload_case_sensitive(true);
+if ($retVal == true) {
+	echo "Successfully set\n";
+} else {
+	echo "Failed to set\n";
+}
+
+$retVal = spl_autoload_case_sensitive(false);
+if ($retVal == false) {
+	echo "Successfully set\n";
+} else {
+	echo "Failed to set\n";
+}
+
+echo "===AUTOLOAD testclass_lc (cs = false)===\n";
+try
+{
+	spl_autoload_extensions(".php.inc");
+	spl_autoload("testclass_lc");
+} 
+catch(Exception $e) {}
+var_dump(class_exists("testclass_lc", true));
+
+echo "===AUTOLOAD testclasscs (cs = true)===\n";
+spl_autoload_case_sensitive(true);
+try
+{
+	spl_autoload_extensions(".php.inc");
+	spl_autoload("testclasscs");
+}
+catch(Exception $e) {}
+var_dump(class_exists("testclasscs", true));
+
+
+echo "===AUTOLOAD TestClassCS (cs = true)===\n";
+try
+{
+	spl_autoload_extensions(".php.inc");
+	spl_autoload("TestClassCS");
+}
+catch(Exception $e) {}
+var_dump(class_exists("TestClassCS", true));
+
+?>
+===DONE===
+--EXPECTF--
+return spl_autoload_case_sensitive() == FALSE
+Successfully set
+Successfully set
+===AUTOLOAD testclass_lc (cs = false)===
+%stestclass_lc.php.inc
+bool(true)
+===AUTOLOAD testclasscs (cs = true)===
+bool(false)
+===AUTOLOAD TestClassCS (cs = true)===
+%sTestClassCS.php.inc
+bool(true)
+===DONE===
Index: ext/spl/tests/testclass_lc.php.inc
===================================================================
--- ext/spl/tests/testclass_lc.php.inc	(revision 0)
+++ ext/spl/tests/testclass_lc.php.inc	(revision 0)
@@ -0,0 +1,9 @@
+<?php
+
+echo __FILE__ . "\n";
+
+class testclass_lc
+{
+}
+
+?>
\ No newline at end of file

Property changes on: ext/spl/tests/testclass_lc.php.inc
___________________________________________________________________
Added: svn:executable
   + *

Index: ext/spl/php_spl.c
===================================================================
--- ext/spl/php_spl.c	(revision 306670)
+++ ext/spl/php_spl.c	(working copy)
@@ -59,6 +59,7 @@
 	spl_globals->autoload_extensions_len = 0;
 	spl_globals->autoload_functions      = NULL;
 	spl_globals->autoload_running        = 0;
+    spl_globals->autoload_case_sensitive = 0;
 }
 /* }}} */
 
@@ -219,17 +220,25 @@
 }
 /* }}} */
 
-static int spl_autoload(const char *class_name, const char * lc_name, int class_name_len, const char * file_extension TSRMLS_DC) /* {{{ */
+static int spl_autoload(const char *class_name, int class_name_len, const char * file_extension TSRMLS_DC) /* {{{ */
 {
 	char *class_file;
+	char *ps_name;
 	int class_file_len;
 	int dummy = 1;
 	zend_file_handle file_handle;
 	zend_op_array *new_op_array;
 	zval *result = NULL;
 	int ret;
+	
+	if (SPL_G(autoload_case_sensitive) == 0) {
+		ps_name = zend_str_tolower_dup(class_name, class_name_len);
+	} else {
+		ps_name = safe_emalloc(class_name_len, 1, sizeof(long) + 1);
+		strcpy(ps_name, class_name);
+	}
 
-	class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, file_extension);
+	class_file_len = spprintf(&class_file, 0, "%s%s", ps_name, file_extension);
 
 #if DEFAULT_SLASH != '\\'
 	{
@@ -273,10 +282,12 @@
 			}
 
 			efree(class_file);
-			return zend_hash_exists(EG(class_table), (char*)lc_name, class_name_len+1);
+			efree(ps_name);
+			return zend_hash_exists(EG(class_table), (char*)ps_name, class_name_len+1);
 		}
 	}
 	efree(class_file);
+	efree(ps_name);
 	return 0;
 } /* }}} */
 
@@ -284,7 +295,7 @@
  Default implementation for __autoload() */
 PHP_FUNCTION(spl_autoload)
 {
-	char *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions);
+	char *class_name, *file_exts = SPL_G(autoload_extensions);
 	int class_name_len, file_exts_len = SPL_G(autoload_extensions_len), found = 0;
 	char *copy, *pos1, *pos2;
 	zval **original_return_value = EG(return_value_ptr_ptr);
@@ -300,20 +311,18 @@
 	} else {
 		copy = pos1 = estrndup(file_exts, file_exts_len);
 	}
-	lc_name = zend_str_tolower_dup(class_name, class_name_len);
 	while(pos1 && *pos1 && !EG(exception)) {
 		EG(return_value_ptr_ptr) = original_return_value;
 		EG(opline_ptr) = original_opline_ptr;
 		EG(active_op_array) = original_active_op_array;
 		pos2 = strchr(pos1, ',');
 		if (pos2) *pos2 = '\0';
-		if (spl_autoload(class_name, lc_name, class_name_len, pos1 TSRMLS_CC)) {
+		if (spl_autoload(class_name, class_name_len, pos1 TSRMLS_CC)) {
 			found = 1;
 			break; /* loaded */
 		}
 		pos1 = pos2 ? pos2 + 1 : NULL;
 	}
-	efree(lc_name);
 	if (copy) {
 		efree(copy);
 	}
@@ -360,6 +369,21 @@
 	}
 } /* }}} */
 
+
+/* {{{ proto bool spl_autoload_case_sensitive([bool use_case_sensitive_file_naming])
+ Register and returns the use case sensitive file naming flag for spl_autoload */
+PHP_FUNCTION(spl_autoload_case_sensitive)
+{
+    zend_bool use_case_sensitive = SPL_G(autoload_case_sensitive);
+    
+    zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &use_case_sensitive);
+
+    SPL_G(autoload_case_sensitive) = use_case_sensitive;
+    
+    RETURN_BOOL(SPL_G(autoload_case_sensitive));    
+} /* }}} */
+
+
 typedef struct {
 	zend_function *func_ptr;
 	zval *obj;
@@ -849,6 +873,10 @@
 	ZEND_ARG_INFO(0, file_extensions)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_case_sensitive, 0, 0, 0)
+	ZEND_ARG_INFO(0, use_case_sensitive_file_naming)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_call, 0, 0, 1)
 	ZEND_ARG_INFO(0, class_name)
 ZEND_END_ARG_INFO()
@@ -869,20 +897,21 @@
 /* {{{ spl_functions
  */
 const zend_function_entry spl_functions[] = {
-	PHP_FE(spl_classes,             arginfo_spl_classes)
-	PHP_FE(spl_autoload,            arginfo_spl_autoload)
-	PHP_FE(spl_autoload_extensions, arginfo_spl_autoload_extensions)
-	PHP_FE(spl_autoload_register,   arginfo_spl_autoload_register)
-	PHP_FE(spl_autoload_unregister, arginfo_spl_autoload_unregister)
-	PHP_FE(spl_autoload_functions,  arginfo_spl_autoload_functions)
-	PHP_FE(spl_autoload_call,       arginfo_spl_autoload_call)
-	PHP_FE(class_parents,           arginfo_class_parents)
-	PHP_FE(class_implements,        arginfo_class_implements)
-	PHP_FE(spl_object_hash,         arginfo_spl_object_hash)
+	PHP_FE(spl_classes,                 arginfo_spl_classes)
+	PHP_FE(spl_autoload,                arginfo_spl_autoload)
+	PHP_FE(spl_autoload_extensions,     arginfo_spl_autoload_extensions)
+	PHP_FE(spl_autoload_case_sensitive, arginfo_spl_autoload_case_sensitive)
+	PHP_FE(spl_autoload_register,       arginfo_spl_autoload_register)
+	PHP_FE(spl_autoload_unregister,     arginfo_spl_autoload_unregister)
+	PHP_FE(spl_autoload_functions,      arginfo_spl_autoload_functions)
+	PHP_FE(spl_autoload_call,           arginfo_spl_autoload_call)
+	PHP_FE(class_parents,               arginfo_class_parents)
+	PHP_FE(class_implements,            arginfo_class_implements)
+	PHP_FE(spl_object_hash,             arginfo_spl_object_hash)
 #ifdef SPL_ITERATORS_H
-	PHP_FE(iterator_to_array,       arginfo_iterator_to_array)
-	PHP_FE(iterator_count,          arginfo_iterator)
-	PHP_FE(iterator_apply,          arginfo_iterator_apply)
+	PHP_FE(iterator_to_array,           arginfo_iterator_to_array)
+	PHP_FE(iterator_count,              arginfo_iterator)
+	PHP_FE(iterator_apply,              arginfo_iterator_apply)
 #endif /* SPL_ITERATORS_H */
 	{NULL, NULL, NULL}
 };
Index: ext/spl/php_spl.h
===================================================================
--- ext/spl/php_spl.h	(revision 306670)
+++ ext/spl/php_spl.h	(working copy)
@@ -67,6 +67,7 @@
 	HashTable *  autoload_functions;
 	int          autoload_running;
 	int          autoload_extensions_len;
+	int          autoload_case_sensitive;
 	intptr_t     hash_mask_handle;
 	intptr_t     hash_mask_handlers;
 	int          hash_mask_init;

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 03:01:27 2024 UTC