From 08a64722e824b7377b4ea4a1c63dcc5f14e844ed Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 10:37:02 -0200 Subject: [PATCH 01/10] Change header of source. --- splclassloader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/splclassloader.c b/splclassloader.c index 6bbfcfc..2f800f4 100644 --- a/splclassloader.c +++ b/splclassloader.c @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 5.4 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | From a949be97e4c795852de4ea37f6a04313e36b0894 Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 10:50:38 -0200 Subject: [PATCH 02/10] Adding diff from https://gist.github.com/1310352 --- spl_classloader.diff | 576 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 576 insertions(+) create mode 100644 spl_classloader.diff diff --git a/spl_classloader.diff b/spl_classloader.diff new file mode 100644 index 0000000..9d2a05e --- /dev/null +++ b/spl_classloader.diff @@ -0,0 +1,576 @@ +Index: ext/spl/spl_classloader.c +=================================================================== +--- ext/spl/spl_classloader.c (revision 0) ++++ ext/spl/spl_classloader.c (revision 0) +@@ -0,0 +1,464 @@ ++/* ++ +----------------------------------------------------------------------+ ++ | PHP Version 5 | ++ +----------------------------------------------------------------------+ ++ | Copyright (c) 1997-2009 The PHP Group | ++ +----------------------------------------------------------------------+ ++ | This source file is subject to version 3.01 of the PHP license, | ++ | that is bundled with this package in the file LICENSE, and is | ++ | available through the world-wide-web at the following url: | ++ | http://www.php.net/license/3_01.txt | ++ | If you did not receive a copy of the PHP license and are unable to | ++ | obtain it through the world-wide-web, please send a note to | ++ | license@php.net so we can mail you a copy immediately. | ++ +----------------------------------------------------------------------+ ++ | Authors: metagoto | ++ | David Coallier | ++ +----------------------------------------------------------------------+ ++ */ ++ ++#ifdef HAVE_CONFIG_H ++#include "config.h" ++#endif ++ ++#include "php.h" ++#include "php_ini.h" ++#include "ext/standard/info.h" ++#include "zend_interfaces.h" ++ ++#include "spl_classloader.h" ++ ++#include "php_spl.h" ++#include "spl_engine.h" ++#include "spl_functions.h" ++#include "spl_exceptions.h" ++ ++zend_object_handlers spl_handler_SplClassLoader; ++PHPAPI zend_class_entry *spl_ce_SplClassLoader; ++ ++/* zend_API.h: #define ZEND_NS_NAME(ns, name) ns"\\"name */ ++#define SPL_CLASSLD_NS_SEPARATOR '\\' ++ ++ ++static zend_class_entry* spl_classloader_ce; ++zend_object_handlers spl_SplClassLoader_handlers; ++ ++ ++typedef struct _spl_SplClassLoader { ++ zend_object std; ++ char* ns; ++ int ns_len; ++ char* inc_path; ++ int inc_path_len; ++ char* file_ext; ++ int file_ext_len; ++} spl_SplClassLoader; ++ ++ ++static void spl_SplClassLoader_dtor(void* object, zend_object_handle handle TSRMLS_DC) ++{ ++ spl_SplClassLoader* obj = (spl_SplClassLoader*)object; ++ if (obj->ns) { ++ efree(obj->ns); ++ obj->ns = NULL; ++ } ++ if (obj->inc_path) { ++ efree(obj->inc_path); ++ obj->inc_path = NULL; ++ } ++ if (obj->file_ext) { ++ efree(obj->file_ext); ++ obj->file_ext = NULL; ++ } ++ zend_object_std_dtor(&obj->std TSRMLS_CC); ++ efree(obj); ++} ++ ++ ++zend_object_value spl_object_classloader_new_ex(zend_class_entry *class_type, spl_SplClassLoader **obj, zval *orig TSRMLS_DC) /* {{{ */ ++{ ++ zend_object_value retval; ++ spl_SplClassLoader *intern; ++ ++ intern = emalloc(sizeof(spl_SplClassLoader)); ++ memset(intern, 0, sizeof(spl_SplClassLoader)); ++ *obj = intern; ++ ++ zend_object_std_init(&intern->std, class_type TSRMLS_CC); ++ object_properties_init(&intern->std, class_type); ++ ++ //zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void*)NULL, sizeof(zval*)); ++ ++ intern->file_ext = estrndup(".php", sizeof(".php")-1); ++ intern->file_ext_len = sizeof(".php")-1; ++ ++ retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (void*)spl_SplClassLoader_dtor, NULL TSRMLS_CC); ++ retval.handlers = &spl_SplClassLoader_handlers; ++ ++ return retval; ++} /* }}} */ ++ ++/* {{{ spl_SplClassLoader_new */ ++static zend_object_value spl_SplClassLoader_new(zend_class_entry *class_type TSRMLS_DC) ++{ ++ spl_SplClassLoader *tmp; ++ return spl_object_classloader_new_ex(class_type, &tmp, NULL TSRMLS_CC); ++} ++/* }}} */ ++ ++/* {{{ proto void SplClassLoader::__construct([string $namespace [, string $include_path]]) ++ Constructor */ ++SPL_METHOD(SplClassLoader, __construct) ++{ ++ char* ns = NULL; ++ int ns_len = 0; ++ char* inc_path = NULL; ++ int inc_path_len = 0; ++ spl_SplClassLoader* obj; ++ ++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &ns, &ns_len, &inc_path, &inc_path_len) == FAILURE) { ++ return; /* should throw ? */ ++ } ++ ++ obj = (spl_SplClassLoader *) zend_object_store_get_object(getThis() TSRMLS_CC); ++ ++ if (ns_len) { ++ obj->ns = estrndup(ns, ns_len); ++ obj->ns_len = ns_len; ++ } ++ ++ if (inc_path_len) { ++ obj->inc_path = estrndup(inc_path, inc_path_len); ++ obj->inc_path_len = inc_path_len; ++ } ++} /* }}} */ ++ ++/* {{{ proto bool SplClassLoader::register() ++ Installs this class loader on the SPL autoload stack */ ++SPL_METHOD(SplClassLoader, register) ++{ ++ zval* arr; ++ zval* retval = NULL; ++ zval* pthis = getThis(); ++ int res = 0; ++ ++ MAKE_STD_ZVAL(arr); ++ array_init(arr); ++ Z_ADDREF_P(pthis); ++ ++ add_next_index_zval(arr, pthis); ++ add_next_index_string(arr, estrndup("loadClass", sizeof("loadClass")-1), 0); ++ ++ zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload_register", &retval, arr); ++ ++ zval_ptr_dtor(&arr); ++ ++ if (retval) { ++ res = i_zend_is_true(retval); ++ zval_ptr_dtor(&retval); ++ } ++ RETURN_BOOL(res); ++} /* }}} */ ++ ++/* {{{ proto bool SplClassLoader::unregister() ++ Uninstalls this class loader from the SPL autoloader stack */ ++SPL_METHOD(SplClassLoader, unregister) ++{ ++ zval* arr; ++ zval* retval = NULL; ++ zval* pthis = getThis(); ++ int res = 0; ++ ++ MAKE_STD_ZVAL(arr); ++ array_init(arr); ++ Z_ADDREF_P(pthis); ++ ++ add_next_index_zval(arr, pthis); ++ add_next_index_string(arr, estrndup("loadClass", sizeof("loadClass")-1), 0); ++ ++ zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload_unregister", &retval, arr); ++ ++ zval_ptr_dtor(&arr); ++ ++ if (retval) { ++ res = i_zend_is_true(retval); ++ zval_ptr_dtor(&retval); ++ } ++ ++ RETURN_BOOL(res); ++} /* }}} */ ++ ++ ++/* compute filename if (partial) ns and class match. returns filename len including '\0' or 0 */ ++static int get_filename(spl_SplClassLoader* obj, char* cl, int cl_len, char* filename TSRMLS_DC) ++{ ++ char* ccl = cl; ++ char* cns = obj->ns; ++ char* cur = &cl[cl_len-1]; ++ int len = 0; ++ ++ if (cl_len < obj->ns_len) { ++ return 0; ++ } ++ ++ /* we have a ns to compare to the qualified class name */ ++ if (obj->ns) { ++ int i = 0; /* compare and transform ns separator in place */ ++ for ( ; i < obj->ns_len; ++i) { ++ if (*cns != *ccl) { ++ return 0; ++ } ++ if (*ccl == SPL_CLASSLD_NS_SEPARATOR) { ++ *ccl = PHP_DIR_SEPARATOR; ++ } ++ ++ccl; ++ ++cns; ++ } ++ if (*ccl != SPL_CLASSLD_NS_SEPARATOR) { ++ return 0; ++ } ++ *ccl = PHP_DIR_SEPARATOR; ++ } ++ ++ /* transform '_' in the class name from right to left */ ++ for ( ; cur != ccl; --cur) { ++ if (*cur == SPL_CLASSLD_NS_SEPARATOR) { ++ break; ++ } ++ if (*cur == '_') { ++ *cur = PHP_DIR_SEPARATOR; ++ } ++ } ++ ++ /* tranform the remaining ns separator from right to left */ ++ for ( ; cur != ccl; --cur) { ++ if (*cur == SPL_CLASSLD_NS_SEPARATOR) { ++ *cur = PHP_DIR_SEPARATOR; ++ } ++ } ++ ++ if (obj->inc_path) { ++ len = obj->inc_path_len + 1 + cl_len + obj->file_ext_len + 1; ++ if (len > MAXPATHLEN) { ++ return 0; ++ } ++ /* sprintf: we know the len */ ++ sprintf(filename, "%s%c%s%s", obj->inc_path, PHP_DIR_SEPARATOR, cl, obj->file_ext); ++ return len; ++ } ++ len = cl_len + obj->file_ext_len + 1; ++ if (len > MAXPATHLEN) { ++ return 0; ++ } ++ /* sprintf: we know the len */ ++ sprintf(filename, "%s%s", cl, obj->file_ext); ++ return len; ++} ++ ++ ++/* {{{ proto bool SplClassLoader::loadClass(string $class_name) ++ Loads the given class or interface */ ++SPL_METHOD(SplClassLoader, loadClass) ++{ ++ char* cl; ++ int cl_len = 0; ++ char filename[MAXPATHLEN]; ++ int len = 0; ++ spl_SplClassLoader* obj; ++ ++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s/", &cl, &cl_len) == FAILURE /* zval separation is required */ ++ || !cl_len) { ++ return; ++ } ++ ++ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); ++ ++ len = get_filename(obj, cl, cl_len, filename TSRMLS_CC); ++ if (len) { ++ zend_file_handle fh; ++ fh.filename = filename; ++ fh.opened_path = NULL; ++ fh.free_filename = 0; ++ fh.type = ZEND_HANDLE_FILENAME; ++ zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh); ++ RETURN_TRUE; ++ } ++ ++ RETURN_FALSE; ++} /* }}} */ ++ ++/* {{{ proto bool SplClassLoader::setIncludePath(string $include_path) ++ Sets the base include path for all class files in the namespace of this class loader */ ++SPL_METHOD(SplClassLoader, setIncludePath) ++{ ++ char* inc_path; ++ int inc_path_len; ++ spl_SplClassLoader* obj; ++ ++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &inc_path, &inc_path_len)== FAILURE) { ++ return; ++ } ++ ++ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); ++ ++ if (obj->inc_path) { ++ efree(obj->inc_path); ++ obj->inc_path = NULL; ++ } ++ ++ if (inc_path_len) { ++ obj->inc_path = estrndup(inc_path, inc_path_len); ++ } ++ ++ obj->inc_path_len = inc_path_len; ++ ++ RETURN_TRUE; ++} /* }}} */ ++ ++/* {{{ proto string SplClassLoader::getIncludePath() ++ Gets the base include path for all class files in the namespace of this class loader */ ++SPL_METHOD(SplClassLoader, getIncludePath) ++{ ++ spl_SplClassLoader* obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); ++ ++ if (obj->inc_path) { ++ RETURN_STRINGL(obj->inc_path, obj->inc_path_len, 1); ++ } ++ ++ RETURN_EMPTY_STRING(); ++} /* }}} */ ++ ++/* {{{ proto bool SplClassLoader::setFileExtension(string $file_extension) ++ Sets the file extension of class files in the namespace of this class loader */ ++SPL_METHOD(SplClassLoader, setFileExtension) ++{ ++ char* ext; ++ int ext_len; ++ spl_SplClassLoader* obj; ++ ++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ext, &ext_len) == FAILURE) { ++ RETURN_FALSE; ++ } ++ ++ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); ++ ++ if (obj->file_ext) { ++ efree(obj->file_ext); ++ obj->file_ext = NULL; ++ } ++ ++ if (ext_len) { ++ obj->file_ext = estrndup(ext, ext_len); ++ } ++ ++ obj->file_ext_len = ext_len; ++ ++ RETURN_TRUE; ++} /* }}} */ ++ ++/* {{{ proto string SplClassLoader::getFileExtension() ++ Gets the file extension of class files in the namespace of this class loader */ ++SPL_METHOD(SplClassLoader, getFileExtension) ++{ ++ spl_SplClassLoader* obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); ++ ++ if (obj->file_ext) { ++ RETURN_STRINGL(obj->file_ext, obj->file_ext_len, 1); ++ } ++ ++ RETURN_EMPTY_STRING(); ++} /* }}} */ ++ ++/* {{{ proto mixed SplClassLoader::getPath(string $class_name) ++ Gets the path for the given class. Does not load anything. This is just a handy method */ ++SPL_METHOD(SplClassLoader, getPath) ++{ ++ char* cl; ++ int cl_len = 0; ++ char filename[MAXPATHLEN]; ++ int len = 0; ++ spl_SplClassLoader* obj; ++ ++ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cl, &cl_len) == FAILURE ++ || !cl_len) { ++ return; ++ } ++ ++ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); ++ ++ len = get_filename(obj, cl, cl_len, filename TSRMLS_CC); ++ ++ if (len) { ++ RETURN_STRINGL(filename, --len, 1); /* cl_len > 0 and len includes '\0' */ ++ } ++ ++ RETURN_FALSE; ++} /* }}} */ ++ ++/* {{{ arginfo and function tables */ ++ZEND_BEGIN_ARG_INFO(arginfo_spl_classloader___construct, 0) ++ ZEND_ARG_INFO(0, namespace) ++ ZEND_ARG_INFO(0, include_path) ++ZEND_END_ARG_INFO() ++ ++ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_classloader_loadclass, 0, 0, 1) ++ ZEND_ARG_INFO(0, class_name) ++ZEND_END_ARG_INFO() ++ ++ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_classloader_setincludepath, 0, 0, 1) ++ ZEND_ARG_INFO(0, path) ++ZEND_END_ARG_INFO() ++ ++ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_classloader_setfileextension, 0, 0, 1) ++ ZEND_ARG_INFO(0, file_ext) ++ZEND_END_ARG_INFO() ++ ++ZEND_BEGIN_ARG_INFO(arginfo_spl_cl_void, 0) ++ZEND_END_ARG_INFO() ++ ++static const zend_function_entry spl_funcs_SplClassLoader[] = { ++ SPL_ME(SplClassLoader, __construct, arginfo_spl_classloader___construct, ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, register, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, unregister, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, loadClass, arginfo_spl_classloader_loadclass, ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, setIncludePath, arginfo_spl_classloader_setincludepath, ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, getIncludePath, arginfo_spl_cl_void , ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, setFileExtension, arginfo_spl_classloader_setfileextension, ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, getFileExtension, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) ++ SPL_ME(SplClassLoader, getPath, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) ++ PHP_FE_END ++}; ++ ++/*const zend_function_entry spl_classloader_functions[] = { ++ {NULL, NULL, NULL} ++};*/ ++/* }}} */ ++ ++/* {{{ PHP_M* */ ++PHP_MINIT_FUNCTION(spl_classloader) ++{ ++ REGISTER_SPL_STD_CLASS_EX(SplClassLoader, spl_SplClassLoader_new, spl_funcs_SplClassLoader) ++ ++ memcpy(&spl_SplClassLoader_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); ++ spl_SplClassLoader_handlers.clone_obj = NULL; /* no cloning! */ ++ ++ return SUCCESS; ++} ++ ++PHP_MINFO_FUNCTION(spl_classloader) ++{ ++ php_info_print_table_start (); ++ php_info_print_table_header(2, "SplClassLoader support", "enabled"); ++ php_info_print_table_row (2, "Conformance", "PSR-0"); ++ php_info_print_table_end (); ++} ++/* }}} */ ++ ++/* ++ * Local variables: ++ * tab-width: 4 ++ * c-basic-offset: 4 ++ * End: ++ * vim600: fdm=marker ++ * vim: noet sw=4 ts=4 ++ */ +Index: ext/spl/spl_classloader.h +=================================================================== +--- ext/spl/spl_classloader.h (revision 0) ++++ ext/spl/spl_classloader.h (revision 0) +@@ -0,0 +1,40 @@ ++/* ++ +----------------------------------------------------------------------+ ++ | PHP Version 5 | ++ +----------------------------------------------------------------------+ ++ | Copyright (c) 1997-2009 The PHP Group | ++ +----------------------------------------------------------------------+ ++ | This source file is subject to version 3.01 of the PHP license, | ++ | that is bundled with this package in the file LICENSE, and is | ++ | available through the world-wide-web at the following url: | ++ | http://www.php.net/license/3_01.txt | ++ | If you did not receive a copy of the PHP license and are unable to | ++ | obtain it through the world-wide-web, please send a note to | ++ | license@php.net so we can mail you a copy immediately. | ++ +----------------------------------------------------------------------+ ++ | Authors: metagoto | ++ +----------------------------------------------------------------------+ ++ */ ++ ++#ifndef SPL_CLASSLOADER_H ++#define SPL_CLASSLOADER_H ++ ++#include "php.h" ++#include "php_spl.h" ++ ++extern PHPAPI zend_class_entry *spl_ce_SplClassLoader; ++ ++#ifdef ZTS ++#include "TSRM.h" ++#endif ++ ++#ifdef ZTS ++#define SPL_CLASSLD_G(v) TSRMG(spl_classloader_globals_id, zend_spl_classloader_globals *, v) ++#else ++#define SPL_CLASSLD_G(v) (spl_classloader_globals.v) ++#endif ++ ++PHP_MINIT_FUNCTION(spl_classloader); ++PHP_MINFO_FUNCTION(spl_classloader); ++ ++#endif /* SPL_CLASSLOADER_H */ +Index: ext/spl/config.w32 +=================================================================== +--- ext/spl/config.w32 (revision 318369) ++++ ext/spl/config.w32 (working copy) +@@ -1,7 +1,7 @@ + // $Id$ + // vim:ft=javascript + +-EXTENSION("spl", "php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c", false /*never shared */); ++EXTENSION("spl", "php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c spl_classloader.c", false /*never shared */); + AC_DEFINE('HAVE_SPL', 1); + PHP_SPL="yes"; +-PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h"); ++PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h spl_classloader.h"); +Index: ext/spl/config.m4 +=================================================================== +--- ext/spl/config.m4 (revision 318369) ++++ ext/spl/config.m4 (working copy) +@@ -1,6 +1,5 @@ + dnl $Id$ + dnl config.m4 for extension SPL +- + AC_MSG_CHECKING(whether zend_object_value is packed) + old_CPPFLAGS=$CPPFLAGS + CPPFLAGS="$INCLUDES -I$abs_srcdir $CPPFLAGS" +@@ -22,6 +21,6 @@ + CPPFLAGS=$old_CPPFLAGS + AC_DEFINE_UNQUOTED(HAVE_PACKED_OBJECT_VALUE, $ac_result, [Whether struct _zend_object_value is packed]) + AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support]) +- PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c, no) +- PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h]) ++ PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c spl_classloader.c, no) ++ PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h spl_classloader.h]) + PHP_ADD_EXTENSION_DEP(spl, pcre, true) +Index: ext/spl/php_spl.c +=================================================================== +--- ext/spl/php_spl.c (revision 318369) ++++ ext/spl/php_spl.c (working copy) +@@ -37,6 +37,7 @@ + #include "spl_dllist.h" + #include "spl_fixedarray.h" + #include "spl_heap.h" ++#include "spl_classloader.h" + #include "zend_exceptions.h" + #include "zend_interfaces.h" + #include "ext/standard/php_rand.h" +@@ -255,6 +256,7 @@ + SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \ + SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \ + SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \ ++ SPL_ADD_CLASS(SplClassLoader, z_list, sub, allow, ce_flags); \ + + /* {{{ proto array spl_classes() + Return an array containing the names of all clsses and interfaces defined in SPL */ +@@ -1038,6 +1040,7 @@ + PHP_MINIT(spl_heap)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU); ++ PHP_MINIT(spl_classloader)(INIT_FUNC_ARGS_PASSTHRU); + + return SUCCESS; + } From 4aabd487c4671527cf7d910175932b3fb2b8956b Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 10:57:00 -0200 Subject: [PATCH 03/10] Testing... --- CREDITS => ext/spl/CREDITS | 0 EXPERIMENTAL => ext/spl/EXPERIMENTAL | 0 README => ext/spl/README | 0 config.m4 => ext/spl/config.m4 | 0 config.w32 => ext/spl/config.w32 | 0 php_splclassloader.h => ext/spl/php_splclassloader.h | 0 splclassloader.c => ext/spl/splclassloader.c | 0 {tests => ext/spl/tests}/001.phpt | 0 {tests => ext/spl/tests}/002.phpt | 0 {tests => ext/spl/tests}/003.phpt | 0 {tests => ext/spl/tests}/004.phpt | 0 {tests => ext/spl/tests}/005.phpt | 0 {tests => ext/spl/tests}/006.phpt | 0 {tests => ext/spl/tests}/007.phpt | 0 {tests => ext/spl/tests}/008.phpt | 0 {tests => ext/spl/tests}/009.phpt | 0 {tests => ext/spl/tests}/010.phpt | 0 {tests => ext/spl/tests}/Dummy.php | 0 {tests => ext/spl/tests}/Dummyb.php | 0 {tests => ext/spl/tests}/Dummyc.class.php | 0 {tests => ext/spl/tests}/for_bench/SplClassLoaderUser.php | 0 {tests => ext/spl/tests}/for_bench/fs_gen.py | 0 {tests => ext/spl/tests}/for_bench/index_ext.php | 0 {tests => ext/spl/tests}/for_bench/index_ext_with_ns.php | 0 {tests => ext/spl/tests}/for_bench/index_ext_with_path.php | 0 {tests => ext/spl/tests}/for_bench/index_user.php | 0 {tests => ext/spl/tests}/for_bench/index_user_with_ns.php | 0 {tests => ext/spl/tests}/for_bench/index_user_with_path.php | 0 {tests => ext/spl/tests}/ns1/Dummy1.php | 0 {tests => ext/spl/tests}/ns1/ns2/Dummy2.php | 0 {tests => ext/spl/tests}/ns_1b/Dummy1b.php | 0 {tests => ext/spl/tests}/ns_1b/NS2C/NS3B.php | 0 {tests => ext/spl/tests}/ns_1b/NS2C/NS3B/Name.php | 0 {tests => ext/spl/tests}/ns_1b/ns2b_/Dummy2b.php | 0 34 files changed, 0 insertions(+), 0 deletions(-) rename CREDITS => ext/spl/CREDITS (100%) rename EXPERIMENTAL => ext/spl/EXPERIMENTAL (100%) rename README => ext/spl/README (100%) rename config.m4 => ext/spl/config.m4 (100%) rename config.w32 => ext/spl/config.w32 (100%) rename php_splclassloader.h => ext/spl/php_splclassloader.h (100%) rename splclassloader.c => ext/spl/splclassloader.c (100%) rename {tests => ext/spl/tests}/001.phpt (100%) rename {tests => ext/spl/tests}/002.phpt (100%) rename {tests => ext/spl/tests}/003.phpt (100%) rename {tests => ext/spl/tests}/004.phpt (100%) rename {tests => ext/spl/tests}/005.phpt (100%) rename {tests => ext/spl/tests}/006.phpt (100%) rename {tests => ext/spl/tests}/007.phpt (100%) rename {tests => ext/spl/tests}/008.phpt (100%) rename {tests => ext/spl/tests}/009.phpt (100%) rename {tests => ext/spl/tests}/010.phpt (100%) rename {tests => ext/spl/tests}/Dummy.php (100%) rename {tests => ext/spl/tests}/Dummyb.php (100%) rename {tests => ext/spl/tests}/Dummyc.class.php (100%) rename {tests => ext/spl/tests}/for_bench/SplClassLoaderUser.php (100%) rename {tests => ext/spl/tests}/for_bench/fs_gen.py (100%) rename {tests => ext/spl/tests}/for_bench/index_ext.php (100%) rename {tests => ext/spl/tests}/for_bench/index_ext_with_ns.php (100%) rename {tests => ext/spl/tests}/for_bench/index_ext_with_path.php (100%) rename {tests => ext/spl/tests}/for_bench/index_user.php (100%) rename {tests => ext/spl/tests}/for_bench/index_user_with_ns.php (100%) rename {tests => ext/spl/tests}/for_bench/index_user_with_path.php (100%) rename {tests => ext/spl/tests}/ns1/Dummy1.php (100%) rename {tests => ext/spl/tests}/ns1/ns2/Dummy2.php (100%) rename {tests => ext/spl/tests}/ns_1b/Dummy1b.php (100%) rename {tests => ext/spl/tests}/ns_1b/NS2C/NS3B.php (100%) rename {tests => ext/spl/tests}/ns_1b/NS2C/NS3B/Name.php (100%) rename {tests => ext/spl/tests}/ns_1b/ns2b_/Dummy2b.php (100%) diff --git a/CREDITS b/ext/spl/CREDITS similarity index 100% rename from CREDITS rename to ext/spl/CREDITS diff --git a/EXPERIMENTAL b/ext/spl/EXPERIMENTAL similarity index 100% rename from EXPERIMENTAL rename to ext/spl/EXPERIMENTAL diff --git a/README b/ext/spl/README similarity index 100% rename from README rename to ext/spl/README diff --git a/config.m4 b/ext/spl/config.m4 similarity index 100% rename from config.m4 rename to ext/spl/config.m4 diff --git a/config.w32 b/ext/spl/config.w32 similarity index 100% rename from config.w32 rename to ext/spl/config.w32 diff --git a/php_splclassloader.h b/ext/spl/php_splclassloader.h similarity index 100% rename from php_splclassloader.h rename to ext/spl/php_splclassloader.h diff --git a/splclassloader.c b/ext/spl/splclassloader.c similarity index 100% rename from splclassloader.c rename to ext/spl/splclassloader.c diff --git a/tests/001.phpt b/ext/spl/tests/001.phpt similarity index 100% rename from tests/001.phpt rename to ext/spl/tests/001.phpt diff --git a/tests/002.phpt b/ext/spl/tests/002.phpt similarity index 100% rename from tests/002.phpt rename to ext/spl/tests/002.phpt diff --git a/tests/003.phpt b/ext/spl/tests/003.phpt similarity index 100% rename from tests/003.phpt rename to ext/spl/tests/003.phpt diff --git a/tests/004.phpt b/ext/spl/tests/004.phpt similarity index 100% rename from tests/004.phpt rename to ext/spl/tests/004.phpt diff --git a/tests/005.phpt b/ext/spl/tests/005.phpt similarity index 100% rename from tests/005.phpt rename to ext/spl/tests/005.phpt diff --git a/tests/006.phpt b/ext/spl/tests/006.phpt similarity index 100% rename from tests/006.phpt rename to ext/spl/tests/006.phpt diff --git a/tests/007.phpt b/ext/spl/tests/007.phpt similarity index 100% rename from tests/007.phpt rename to ext/spl/tests/007.phpt diff --git a/tests/008.phpt b/ext/spl/tests/008.phpt similarity index 100% rename from tests/008.phpt rename to ext/spl/tests/008.phpt diff --git a/tests/009.phpt b/ext/spl/tests/009.phpt similarity index 100% rename from tests/009.phpt rename to ext/spl/tests/009.phpt diff --git a/tests/010.phpt b/ext/spl/tests/010.phpt similarity index 100% rename from tests/010.phpt rename to ext/spl/tests/010.phpt diff --git a/tests/Dummy.php b/ext/spl/tests/Dummy.php similarity index 100% rename from tests/Dummy.php rename to ext/spl/tests/Dummy.php diff --git a/tests/Dummyb.php b/ext/spl/tests/Dummyb.php similarity index 100% rename from tests/Dummyb.php rename to ext/spl/tests/Dummyb.php diff --git a/tests/Dummyc.class.php b/ext/spl/tests/Dummyc.class.php similarity index 100% rename from tests/Dummyc.class.php rename to ext/spl/tests/Dummyc.class.php diff --git a/tests/for_bench/SplClassLoaderUser.php b/ext/spl/tests/for_bench/SplClassLoaderUser.php similarity index 100% rename from tests/for_bench/SplClassLoaderUser.php rename to ext/spl/tests/for_bench/SplClassLoaderUser.php diff --git a/tests/for_bench/fs_gen.py b/ext/spl/tests/for_bench/fs_gen.py similarity index 100% rename from tests/for_bench/fs_gen.py rename to ext/spl/tests/for_bench/fs_gen.py diff --git a/tests/for_bench/index_ext.php b/ext/spl/tests/for_bench/index_ext.php similarity index 100% rename from tests/for_bench/index_ext.php rename to ext/spl/tests/for_bench/index_ext.php diff --git a/tests/for_bench/index_ext_with_ns.php b/ext/spl/tests/for_bench/index_ext_with_ns.php similarity index 100% rename from tests/for_bench/index_ext_with_ns.php rename to ext/spl/tests/for_bench/index_ext_with_ns.php diff --git a/tests/for_bench/index_ext_with_path.php b/ext/spl/tests/for_bench/index_ext_with_path.php similarity index 100% rename from tests/for_bench/index_ext_with_path.php rename to ext/spl/tests/for_bench/index_ext_with_path.php diff --git a/tests/for_bench/index_user.php b/ext/spl/tests/for_bench/index_user.php similarity index 100% rename from tests/for_bench/index_user.php rename to ext/spl/tests/for_bench/index_user.php diff --git a/tests/for_bench/index_user_with_ns.php b/ext/spl/tests/for_bench/index_user_with_ns.php similarity index 100% rename from tests/for_bench/index_user_with_ns.php rename to ext/spl/tests/for_bench/index_user_with_ns.php diff --git a/tests/for_bench/index_user_with_path.php b/ext/spl/tests/for_bench/index_user_with_path.php similarity index 100% rename from tests/for_bench/index_user_with_path.php rename to ext/spl/tests/for_bench/index_user_with_path.php diff --git a/tests/ns1/Dummy1.php b/ext/spl/tests/ns1/Dummy1.php similarity index 100% rename from tests/ns1/Dummy1.php rename to ext/spl/tests/ns1/Dummy1.php diff --git a/tests/ns1/ns2/Dummy2.php b/ext/spl/tests/ns1/ns2/Dummy2.php similarity index 100% rename from tests/ns1/ns2/Dummy2.php rename to ext/spl/tests/ns1/ns2/Dummy2.php diff --git a/tests/ns_1b/Dummy1b.php b/ext/spl/tests/ns_1b/Dummy1b.php similarity index 100% rename from tests/ns_1b/Dummy1b.php rename to ext/spl/tests/ns_1b/Dummy1b.php diff --git a/tests/ns_1b/NS2C/NS3B.php b/ext/spl/tests/ns_1b/NS2C/NS3B.php similarity index 100% rename from tests/ns_1b/NS2C/NS3B.php rename to ext/spl/tests/ns_1b/NS2C/NS3B.php diff --git a/tests/ns_1b/NS2C/NS3B/Name.php b/ext/spl/tests/ns_1b/NS2C/NS3B/Name.php similarity index 100% rename from tests/ns_1b/NS2C/NS3B/Name.php rename to ext/spl/tests/ns_1b/NS2C/NS3B/Name.php diff --git a/tests/ns_1b/ns2b_/Dummy2b.php b/ext/spl/tests/ns_1b/ns2b_/Dummy2b.php similarity index 100% rename from tests/ns_1b/ns2b_/Dummy2b.php rename to ext/spl/tests/ns_1b/ns2b_/Dummy2b.php From 3a3b349b1d484a5d92e93f16442e2fb7b0caec18 Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 11:01:43 -0200 Subject: [PATCH 04/10] Chaging file names. --- ext/spl/config.m4 | 2 +- ext/spl/config.w32 | 2 +- ext/spl/{splclassloader.c => spl_classloader.c} | 2 +- ext/spl/{php_splclassloader.h => spl_classloader.h} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename ext/spl/{splclassloader.c => spl_classloader.c} (99%) rename ext/spl/{php_splclassloader.h => spl_classloader.h} (100%) diff --git a/ext/spl/config.m4 b/ext/spl/config.m4 index fd96ebd..e75478a 100644 --- a/ext/spl/config.m4 +++ b/ext/spl/config.m4 @@ -3,6 +3,6 @@ PHP_ARG_ENABLE(splclassloader, whether to enable splclassloader, if test "$PHP_SPLCLASSLOADER" != "no"; then - PHP_NEW_EXTENSION(splclassloader, splclassloader.c, $ext_shared) + PHP_NEW_EXTENSION(splclassloader, spl_classloader.c, $ext_shared) fi diff --git a/ext/spl/config.w32 b/ext/spl/config.w32 index 834f855..ae8feb0 100644 --- a/ext/spl/config.w32 +++ b/ext/spl/config.w32 @@ -2,5 +2,5 @@ ARG_ENABLE("splclassloader", "enable splclassloader support", "no"); if (PHP_SPLCLASSLOADER != "no") { - EXTENSION("splclassloader", "splclassloader.c"); + EXTENSION("splclassloader", "spl_classloader.c"); } diff --git a/ext/spl/splclassloader.c b/ext/spl/spl_classloader.c similarity index 99% rename from ext/spl/splclassloader.c rename to ext/spl/spl_classloader.c index 2f800f4..f40adf2 100644 --- a/ext/spl/splclassloader.c +++ b/ext/spl/spl_classloader.c @@ -24,7 +24,7 @@ #include "php_ini.h" #include "ext/standard/info.h" #include "zend_interfaces.h" -#include "php_splclassloader.h" +#include "spl_classloader.h" #ifdef COMPILE_DL_SPLCLASSLOADER diff --git a/ext/spl/php_splclassloader.h b/ext/spl/spl_classloader.h similarity index 100% rename from ext/spl/php_splclassloader.h rename to ext/spl/spl_classloader.h From e4836b10d34ed5b6455575f1e574050cc1e4c3ec Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 11:02:50 -0200 Subject: [PATCH 05/10] Adding headers. --- ext/spl/spl_classloader.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ext/spl/spl_classloader.c b/ext/spl/spl_classloader.c index f40adf2..547f1b6 100644 --- a/ext/spl/spl_classloader.c +++ b/ext/spl/spl_classloader.c @@ -24,7 +24,12 @@ #include "php_ini.h" #include "ext/standard/info.h" #include "zend_interfaces.h" + #include "spl_classloader.h" +#include "php_spl.h" +#include "spl_engine.h" +#include "spl_functions.h" +#include "spl_exceptions.h" #ifdef COMPILE_DL_SPLCLASSLOADER From a6daa54d0f9b5e38a977be3d68e8759e6109da1e Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 11:28:56 -0200 Subject: [PATCH 06/10] Roll back changes. --- ext/spl/CREDITS => CREDITS | 0 ext/spl/EXPERIMENTAL => EXPERIMENTAL | 0 ext/spl/README => README | 0 ext/spl/config.m4 => config.m4 | 0 ext/spl/config.w32 => config.w32 | 0 ext/spl/spl_classloader.c => spl_classloader.c | 0 ext/spl/spl_classloader.h => spl_classloader.h | 0 {ext/spl/tests => tests}/001.phpt | 0 {ext/spl/tests => tests}/002.phpt | 0 {ext/spl/tests => tests}/003.phpt | 0 {ext/spl/tests => tests}/004.phpt | 0 {ext/spl/tests => tests}/005.phpt | 0 {ext/spl/tests => tests}/006.phpt | 0 {ext/spl/tests => tests}/007.phpt | 0 {ext/spl/tests => tests}/008.phpt | 0 {ext/spl/tests => tests}/009.phpt | 0 {ext/spl/tests => tests}/010.phpt | 0 {ext/spl/tests => tests}/Dummy.php | 0 {ext/spl/tests => tests}/Dummyb.php | 0 {ext/spl/tests => tests}/Dummyc.class.php | 0 {ext/spl/tests => tests}/for_bench/SplClassLoaderUser.php | 0 {ext/spl/tests => tests}/for_bench/fs_gen.py | 0 {ext/spl/tests => tests}/for_bench/index_ext.php | 0 {ext/spl/tests => tests}/for_bench/index_ext_with_ns.php | 0 {ext/spl/tests => tests}/for_bench/index_ext_with_path.php | 0 {ext/spl/tests => tests}/for_bench/index_user.php | 0 {ext/spl/tests => tests}/for_bench/index_user_with_ns.php | 0 {ext/spl/tests => tests}/for_bench/index_user_with_path.php | 0 {ext/spl/tests => tests}/ns1/Dummy1.php | 0 {ext/spl/tests => tests}/ns1/ns2/Dummy2.php | 0 {ext/spl/tests => tests}/ns_1b/Dummy1b.php | 0 {ext/spl/tests => tests}/ns_1b/NS2C/NS3B.php | 0 {ext/spl/tests => tests}/ns_1b/NS2C/NS3B/Name.php | 0 {ext/spl/tests => tests}/ns_1b/ns2b_/Dummy2b.php | 0 34 files changed, 0 insertions(+), 0 deletions(-) rename ext/spl/CREDITS => CREDITS (100%) rename ext/spl/EXPERIMENTAL => EXPERIMENTAL (100%) rename ext/spl/README => README (100%) rename ext/spl/config.m4 => config.m4 (100%) rename ext/spl/config.w32 => config.w32 (100%) rename ext/spl/spl_classloader.c => spl_classloader.c (100%) rename ext/spl/spl_classloader.h => spl_classloader.h (100%) rename {ext/spl/tests => tests}/001.phpt (100%) rename {ext/spl/tests => tests}/002.phpt (100%) rename {ext/spl/tests => tests}/003.phpt (100%) rename {ext/spl/tests => tests}/004.phpt (100%) rename {ext/spl/tests => tests}/005.phpt (100%) rename {ext/spl/tests => tests}/006.phpt (100%) rename {ext/spl/tests => tests}/007.phpt (100%) rename {ext/spl/tests => tests}/008.phpt (100%) rename {ext/spl/tests => tests}/009.phpt (100%) rename {ext/spl/tests => tests}/010.phpt (100%) rename {ext/spl/tests => tests}/Dummy.php (100%) rename {ext/spl/tests => tests}/Dummyb.php (100%) rename {ext/spl/tests => tests}/Dummyc.class.php (100%) rename {ext/spl/tests => tests}/for_bench/SplClassLoaderUser.php (100%) rename {ext/spl/tests => tests}/for_bench/fs_gen.py (100%) rename {ext/spl/tests => tests}/for_bench/index_ext.php (100%) rename {ext/spl/tests => tests}/for_bench/index_ext_with_ns.php (100%) rename {ext/spl/tests => tests}/for_bench/index_ext_with_path.php (100%) rename {ext/spl/tests => tests}/for_bench/index_user.php (100%) rename {ext/spl/tests => tests}/for_bench/index_user_with_ns.php (100%) rename {ext/spl/tests => tests}/for_bench/index_user_with_path.php (100%) rename {ext/spl/tests => tests}/ns1/Dummy1.php (100%) rename {ext/spl/tests => tests}/ns1/ns2/Dummy2.php (100%) rename {ext/spl/tests => tests}/ns_1b/Dummy1b.php (100%) rename {ext/spl/tests => tests}/ns_1b/NS2C/NS3B.php (100%) rename {ext/spl/tests => tests}/ns_1b/NS2C/NS3B/Name.php (100%) rename {ext/spl/tests => tests}/ns_1b/ns2b_/Dummy2b.php (100%) diff --git a/ext/spl/CREDITS b/CREDITS similarity index 100% rename from ext/spl/CREDITS rename to CREDITS diff --git a/ext/spl/EXPERIMENTAL b/EXPERIMENTAL similarity index 100% rename from ext/spl/EXPERIMENTAL rename to EXPERIMENTAL diff --git a/ext/spl/README b/README similarity index 100% rename from ext/spl/README rename to README diff --git a/ext/spl/config.m4 b/config.m4 similarity index 100% rename from ext/spl/config.m4 rename to config.m4 diff --git a/ext/spl/config.w32 b/config.w32 similarity index 100% rename from ext/spl/config.w32 rename to config.w32 diff --git a/ext/spl/spl_classloader.c b/spl_classloader.c similarity index 100% rename from ext/spl/spl_classloader.c rename to spl_classloader.c diff --git a/ext/spl/spl_classloader.h b/spl_classloader.h similarity index 100% rename from ext/spl/spl_classloader.h rename to spl_classloader.h diff --git a/ext/spl/tests/001.phpt b/tests/001.phpt similarity index 100% rename from ext/spl/tests/001.phpt rename to tests/001.phpt diff --git a/ext/spl/tests/002.phpt b/tests/002.phpt similarity index 100% rename from ext/spl/tests/002.phpt rename to tests/002.phpt diff --git a/ext/spl/tests/003.phpt b/tests/003.phpt similarity index 100% rename from ext/spl/tests/003.phpt rename to tests/003.phpt diff --git a/ext/spl/tests/004.phpt b/tests/004.phpt similarity index 100% rename from ext/spl/tests/004.phpt rename to tests/004.phpt diff --git a/ext/spl/tests/005.phpt b/tests/005.phpt similarity index 100% rename from ext/spl/tests/005.phpt rename to tests/005.phpt diff --git a/ext/spl/tests/006.phpt b/tests/006.phpt similarity index 100% rename from ext/spl/tests/006.phpt rename to tests/006.phpt diff --git a/ext/spl/tests/007.phpt b/tests/007.phpt similarity index 100% rename from ext/spl/tests/007.phpt rename to tests/007.phpt diff --git a/ext/spl/tests/008.phpt b/tests/008.phpt similarity index 100% rename from ext/spl/tests/008.phpt rename to tests/008.phpt diff --git a/ext/spl/tests/009.phpt b/tests/009.phpt similarity index 100% rename from ext/spl/tests/009.phpt rename to tests/009.phpt diff --git a/ext/spl/tests/010.phpt b/tests/010.phpt similarity index 100% rename from ext/spl/tests/010.phpt rename to tests/010.phpt diff --git a/ext/spl/tests/Dummy.php b/tests/Dummy.php similarity index 100% rename from ext/spl/tests/Dummy.php rename to tests/Dummy.php diff --git a/ext/spl/tests/Dummyb.php b/tests/Dummyb.php similarity index 100% rename from ext/spl/tests/Dummyb.php rename to tests/Dummyb.php diff --git a/ext/spl/tests/Dummyc.class.php b/tests/Dummyc.class.php similarity index 100% rename from ext/spl/tests/Dummyc.class.php rename to tests/Dummyc.class.php diff --git a/ext/spl/tests/for_bench/SplClassLoaderUser.php b/tests/for_bench/SplClassLoaderUser.php similarity index 100% rename from ext/spl/tests/for_bench/SplClassLoaderUser.php rename to tests/for_bench/SplClassLoaderUser.php diff --git a/ext/spl/tests/for_bench/fs_gen.py b/tests/for_bench/fs_gen.py similarity index 100% rename from ext/spl/tests/for_bench/fs_gen.py rename to tests/for_bench/fs_gen.py diff --git a/ext/spl/tests/for_bench/index_ext.php b/tests/for_bench/index_ext.php similarity index 100% rename from ext/spl/tests/for_bench/index_ext.php rename to tests/for_bench/index_ext.php diff --git a/ext/spl/tests/for_bench/index_ext_with_ns.php b/tests/for_bench/index_ext_with_ns.php similarity index 100% rename from ext/spl/tests/for_bench/index_ext_with_ns.php rename to tests/for_bench/index_ext_with_ns.php diff --git a/ext/spl/tests/for_bench/index_ext_with_path.php b/tests/for_bench/index_ext_with_path.php similarity index 100% rename from ext/spl/tests/for_bench/index_ext_with_path.php rename to tests/for_bench/index_ext_with_path.php diff --git a/ext/spl/tests/for_bench/index_user.php b/tests/for_bench/index_user.php similarity index 100% rename from ext/spl/tests/for_bench/index_user.php rename to tests/for_bench/index_user.php diff --git a/ext/spl/tests/for_bench/index_user_with_ns.php b/tests/for_bench/index_user_with_ns.php similarity index 100% rename from ext/spl/tests/for_bench/index_user_with_ns.php rename to tests/for_bench/index_user_with_ns.php diff --git a/ext/spl/tests/for_bench/index_user_with_path.php b/tests/for_bench/index_user_with_path.php similarity index 100% rename from ext/spl/tests/for_bench/index_user_with_path.php rename to tests/for_bench/index_user_with_path.php diff --git a/ext/spl/tests/ns1/Dummy1.php b/tests/ns1/Dummy1.php similarity index 100% rename from ext/spl/tests/ns1/Dummy1.php rename to tests/ns1/Dummy1.php diff --git a/ext/spl/tests/ns1/ns2/Dummy2.php b/tests/ns1/ns2/Dummy2.php similarity index 100% rename from ext/spl/tests/ns1/ns2/Dummy2.php rename to tests/ns1/ns2/Dummy2.php diff --git a/ext/spl/tests/ns_1b/Dummy1b.php b/tests/ns_1b/Dummy1b.php similarity index 100% rename from ext/spl/tests/ns_1b/Dummy1b.php rename to tests/ns_1b/Dummy1b.php diff --git a/ext/spl/tests/ns_1b/NS2C/NS3B.php b/tests/ns_1b/NS2C/NS3B.php similarity index 100% rename from ext/spl/tests/ns_1b/NS2C/NS3B.php rename to tests/ns_1b/NS2C/NS3B.php diff --git a/ext/spl/tests/ns_1b/NS2C/NS3B/Name.php b/tests/ns_1b/NS2C/NS3B/Name.php similarity index 100% rename from ext/spl/tests/ns_1b/NS2C/NS3B/Name.php rename to tests/ns_1b/NS2C/NS3B/Name.php diff --git a/ext/spl/tests/ns_1b/ns2b_/Dummy2b.php b/tests/ns_1b/ns2b_/Dummy2b.php similarity index 100% rename from ext/spl/tests/ns_1b/ns2b_/Dummy2b.php rename to tests/ns_1b/ns2b_/Dummy2b.php From 452ebdd962e6d72ad0e9807af78c1da615ae79f0 Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 11:43:07 -0200 Subject: [PATCH 07/10] Bug fix when build in PHP 5.4.x sources. --- spl_classloader.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/spl_classloader.c b/spl_classloader.c index 547f1b6..95a1a44 100644 --- a/spl_classloader.c +++ b/spl_classloader.c @@ -26,11 +26,6 @@ #include "zend_interfaces.h" #include "spl_classloader.h" -#include "php_spl.h" -#include "spl_engine.h" -#include "spl_functions.h" -#include "spl_exceptions.h" - #ifdef COMPILE_DL_SPLCLASSLOADER ZEND_GET_MODULE(splclassloader) @@ -39,11 +34,9 @@ ZEND_GET_MODULE(splclassloader) /* zend_API.h: #define ZEND_NS_NAME(ns, name) ns"\\"name */ #define SPLCLASSLD_NS_SEPARATOR '\\' - static zend_class_entry* splclassloader_ce; zend_object_handlers splclassloader_object_handlers; - typedef struct _splclassloader_object { zend_object std; char* ns; @@ -74,26 +67,36 @@ static void splclassloader_object_dtor(void* object, zend_object_handle handle T efree(obj); } - -zend_object_value splclassloader_create_object(zend_class_entry* class_type TSRMLS_DC) +zend_object_value spl_object_classloader_new_ex(zend_class_entry *class_type, splclassloader_object **obj, zval *orig TSRMLS_DC) /* {{{ */ { zend_object_value retval; + splclassloader_object *intern; - splclassloader_object* obj = (splclassloader_object*)emalloc(sizeof(splclassloader_object)); - memset(obj, 0, sizeof(splclassloader_object)); + intern = emalloc(sizeof(splclassloader_object)); + memset(intern, 0, sizeof(splclassloader_object)); + *obj = intern; - zend_object_std_init(&obj->std, class_type TSRMLS_CC); - zend_hash_copy(obj->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void*)0, sizeof(zval*)); + zend_object_std_init(&intern->std, class_type TSRMLS_CC); + object_properties_init(&intern->std, class_type); - obj->file_ext = estrndup(".php", sizeof(".php")-1); - obj->file_ext_len = sizeof(".php")-1; - - retval.handle = zend_objects_store_put(obj, (zend_objects_store_dtor_t)zend_objects_destroy_object, (void*)splclassloader_object_dtor, NULL TSRMLS_CC); + //zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void*)NULL, sizeof(zval*)); + + intern->file_ext = estrndup(".php", sizeof(".php")-1); + intern->file_ext_len = sizeof(".php")-1; + + retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (void*)splclassloader_object_dtor, NULL TSRMLS_CC); retval.handlers = &splclassloader_object_handlers; return retval; -} +} /* }}} */ +/* {{{ splclassloader_create_object */ +static zend_object_value splclassloader_create_object(zend_class_entry *class_type TSRMLS_DC) +{ + splclassloader_object *tmp; + return spl_object_classloader_new_ex(class_type, &tmp, NULL TSRMLS_CC); +} +/* }}} */ /* {{{ proto void SplClassLoader::__construct([string $namespace [, string $include_path]]) Constructor */ From 6f5db1f0f7bc3780ead906cdae3403e79f2adb68 Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Tue, 29 Jan 2013 13:51:36 -0200 Subject: [PATCH 08/10] Changing authors format. --- spl_classloader.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spl_classloader.c b/spl_classloader.c index 95a1a44..0b6b1c5 100644 --- a/spl_classloader.c +++ b/spl_classloader.c @@ -419,6 +419,9 @@ PHP_MINFO_FUNCTION(splclassloader) php_info_print_table_start (); php_info_print_table_header(2, "SplClassLoader support", "enabled"); php_info_print_table_row (2, "Conformance", "PSR-0"); + php_info_print_table_row (2, "Version", "0.2"); + php_info_print_table_row (2, "Author", "David Coallier "); + php_info_print_table_row (2, "Author", "Marcel Araujo "); php_info_print_table_end (); } @@ -432,6 +435,6 @@ zend_module_entry splclassloader_module_entry = { NULL, NULL, PHP_MINFO(splclassloader), - "0.1", + "0.2", STANDARD_MODULE_PROPERTIES }; From 3b9390087911c85279edd9e892e2ad9fd1489d97 Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Thu, 31 Jan 2013 09:24:26 -0200 Subject: [PATCH 09/10] Update SplClassLoader php and remove diff file. --- spl_classloader.diff | 576 ------------------------- tests/for_bench/SplClassLoaderUser.php | 136 +++--- 2 files changed, 68 insertions(+), 644 deletions(-) delete mode 100644 spl_classloader.diff diff --git a/spl_classloader.diff b/spl_classloader.diff deleted file mode 100644 index 9d2a05e..0000000 --- a/spl_classloader.diff +++ /dev/null @@ -1,576 +0,0 @@ -Index: ext/spl/spl_classloader.c -=================================================================== ---- ext/spl/spl_classloader.c (revision 0) -+++ ext/spl/spl_classloader.c (revision 0) -@@ -0,0 +1,464 @@ -+/* -+ +----------------------------------------------------------------------+ -+ | PHP Version 5 | -+ +----------------------------------------------------------------------+ -+ | Copyright (c) 1997-2009 The PHP Group | -+ +----------------------------------------------------------------------+ -+ | This source file is subject to version 3.01 of the PHP license, | -+ | that is bundled with this package in the file LICENSE, and is | -+ | available through the world-wide-web at the following url: | -+ | http://www.php.net/license/3_01.txt | -+ | If you did not receive a copy of the PHP license and are unable to | -+ | obtain it through the world-wide-web, please send a note to | -+ | license@php.net so we can mail you a copy immediately. | -+ +----------------------------------------------------------------------+ -+ | Authors: metagoto | -+ | David Coallier | -+ +----------------------------------------------------------------------+ -+ */ -+ -+#ifdef HAVE_CONFIG_H -+#include "config.h" -+#endif -+ -+#include "php.h" -+#include "php_ini.h" -+#include "ext/standard/info.h" -+#include "zend_interfaces.h" -+ -+#include "spl_classloader.h" -+ -+#include "php_spl.h" -+#include "spl_engine.h" -+#include "spl_functions.h" -+#include "spl_exceptions.h" -+ -+zend_object_handlers spl_handler_SplClassLoader; -+PHPAPI zend_class_entry *spl_ce_SplClassLoader; -+ -+/* zend_API.h: #define ZEND_NS_NAME(ns, name) ns"\\"name */ -+#define SPL_CLASSLD_NS_SEPARATOR '\\' -+ -+ -+static zend_class_entry* spl_classloader_ce; -+zend_object_handlers spl_SplClassLoader_handlers; -+ -+ -+typedef struct _spl_SplClassLoader { -+ zend_object std; -+ char* ns; -+ int ns_len; -+ char* inc_path; -+ int inc_path_len; -+ char* file_ext; -+ int file_ext_len; -+} spl_SplClassLoader; -+ -+ -+static void spl_SplClassLoader_dtor(void* object, zend_object_handle handle TSRMLS_DC) -+{ -+ spl_SplClassLoader* obj = (spl_SplClassLoader*)object; -+ if (obj->ns) { -+ efree(obj->ns); -+ obj->ns = NULL; -+ } -+ if (obj->inc_path) { -+ efree(obj->inc_path); -+ obj->inc_path = NULL; -+ } -+ if (obj->file_ext) { -+ efree(obj->file_ext); -+ obj->file_ext = NULL; -+ } -+ zend_object_std_dtor(&obj->std TSRMLS_CC); -+ efree(obj); -+} -+ -+ -+zend_object_value spl_object_classloader_new_ex(zend_class_entry *class_type, spl_SplClassLoader **obj, zval *orig TSRMLS_DC) /* {{{ */ -+{ -+ zend_object_value retval; -+ spl_SplClassLoader *intern; -+ -+ intern = emalloc(sizeof(spl_SplClassLoader)); -+ memset(intern, 0, sizeof(spl_SplClassLoader)); -+ *obj = intern; -+ -+ zend_object_std_init(&intern->std, class_type TSRMLS_CC); -+ object_properties_init(&intern->std, class_type); -+ -+ //zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void*)NULL, sizeof(zval*)); -+ -+ intern->file_ext = estrndup(".php", sizeof(".php")-1); -+ intern->file_ext_len = sizeof(".php")-1; -+ -+ retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (void*)spl_SplClassLoader_dtor, NULL TSRMLS_CC); -+ retval.handlers = &spl_SplClassLoader_handlers; -+ -+ return retval; -+} /* }}} */ -+ -+/* {{{ spl_SplClassLoader_new */ -+static zend_object_value spl_SplClassLoader_new(zend_class_entry *class_type TSRMLS_DC) -+{ -+ spl_SplClassLoader *tmp; -+ return spl_object_classloader_new_ex(class_type, &tmp, NULL TSRMLS_CC); -+} -+/* }}} */ -+ -+/* {{{ proto void SplClassLoader::__construct([string $namespace [, string $include_path]]) -+ Constructor */ -+SPL_METHOD(SplClassLoader, __construct) -+{ -+ char* ns = NULL; -+ int ns_len = 0; -+ char* inc_path = NULL; -+ int inc_path_len = 0; -+ spl_SplClassLoader* obj; -+ -+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &ns, &ns_len, &inc_path, &inc_path_len) == FAILURE) { -+ return; /* should throw ? */ -+ } -+ -+ obj = (spl_SplClassLoader *) zend_object_store_get_object(getThis() TSRMLS_CC); -+ -+ if (ns_len) { -+ obj->ns = estrndup(ns, ns_len); -+ obj->ns_len = ns_len; -+ } -+ -+ if (inc_path_len) { -+ obj->inc_path = estrndup(inc_path, inc_path_len); -+ obj->inc_path_len = inc_path_len; -+ } -+} /* }}} */ -+ -+/* {{{ proto bool SplClassLoader::register() -+ Installs this class loader on the SPL autoload stack */ -+SPL_METHOD(SplClassLoader, register) -+{ -+ zval* arr; -+ zval* retval = NULL; -+ zval* pthis = getThis(); -+ int res = 0; -+ -+ MAKE_STD_ZVAL(arr); -+ array_init(arr); -+ Z_ADDREF_P(pthis); -+ -+ add_next_index_zval(arr, pthis); -+ add_next_index_string(arr, estrndup("loadClass", sizeof("loadClass")-1), 0); -+ -+ zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload_register", &retval, arr); -+ -+ zval_ptr_dtor(&arr); -+ -+ if (retval) { -+ res = i_zend_is_true(retval); -+ zval_ptr_dtor(&retval); -+ } -+ RETURN_BOOL(res); -+} /* }}} */ -+ -+/* {{{ proto bool SplClassLoader::unregister() -+ Uninstalls this class loader from the SPL autoloader stack */ -+SPL_METHOD(SplClassLoader, unregister) -+{ -+ zval* arr; -+ zval* retval = NULL; -+ zval* pthis = getThis(); -+ int res = 0; -+ -+ MAKE_STD_ZVAL(arr); -+ array_init(arr); -+ Z_ADDREF_P(pthis); -+ -+ add_next_index_zval(arr, pthis); -+ add_next_index_string(arr, estrndup("loadClass", sizeof("loadClass")-1), 0); -+ -+ zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload_unregister", &retval, arr); -+ -+ zval_ptr_dtor(&arr); -+ -+ if (retval) { -+ res = i_zend_is_true(retval); -+ zval_ptr_dtor(&retval); -+ } -+ -+ RETURN_BOOL(res); -+} /* }}} */ -+ -+ -+/* compute filename if (partial) ns and class match. returns filename len including '\0' or 0 */ -+static int get_filename(spl_SplClassLoader* obj, char* cl, int cl_len, char* filename TSRMLS_DC) -+{ -+ char* ccl = cl; -+ char* cns = obj->ns; -+ char* cur = &cl[cl_len-1]; -+ int len = 0; -+ -+ if (cl_len < obj->ns_len) { -+ return 0; -+ } -+ -+ /* we have a ns to compare to the qualified class name */ -+ if (obj->ns) { -+ int i = 0; /* compare and transform ns separator in place */ -+ for ( ; i < obj->ns_len; ++i) { -+ if (*cns != *ccl) { -+ return 0; -+ } -+ if (*ccl == SPL_CLASSLD_NS_SEPARATOR) { -+ *ccl = PHP_DIR_SEPARATOR; -+ } -+ ++ccl; -+ ++cns; -+ } -+ if (*ccl != SPL_CLASSLD_NS_SEPARATOR) { -+ return 0; -+ } -+ *ccl = PHP_DIR_SEPARATOR; -+ } -+ -+ /* transform '_' in the class name from right to left */ -+ for ( ; cur != ccl; --cur) { -+ if (*cur == SPL_CLASSLD_NS_SEPARATOR) { -+ break; -+ } -+ if (*cur == '_') { -+ *cur = PHP_DIR_SEPARATOR; -+ } -+ } -+ -+ /* tranform the remaining ns separator from right to left */ -+ for ( ; cur != ccl; --cur) { -+ if (*cur == SPL_CLASSLD_NS_SEPARATOR) { -+ *cur = PHP_DIR_SEPARATOR; -+ } -+ } -+ -+ if (obj->inc_path) { -+ len = obj->inc_path_len + 1 + cl_len + obj->file_ext_len + 1; -+ if (len > MAXPATHLEN) { -+ return 0; -+ } -+ /* sprintf: we know the len */ -+ sprintf(filename, "%s%c%s%s", obj->inc_path, PHP_DIR_SEPARATOR, cl, obj->file_ext); -+ return len; -+ } -+ len = cl_len + obj->file_ext_len + 1; -+ if (len > MAXPATHLEN) { -+ return 0; -+ } -+ /* sprintf: we know the len */ -+ sprintf(filename, "%s%s", cl, obj->file_ext); -+ return len; -+} -+ -+ -+/* {{{ proto bool SplClassLoader::loadClass(string $class_name) -+ Loads the given class or interface */ -+SPL_METHOD(SplClassLoader, loadClass) -+{ -+ char* cl; -+ int cl_len = 0; -+ char filename[MAXPATHLEN]; -+ int len = 0; -+ spl_SplClassLoader* obj; -+ -+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s/", &cl, &cl_len) == FAILURE /* zval separation is required */ -+ || !cl_len) { -+ return; -+ } -+ -+ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); -+ -+ len = get_filename(obj, cl, cl_len, filename TSRMLS_CC); -+ if (len) { -+ zend_file_handle fh; -+ fh.filename = filename; -+ fh.opened_path = NULL; -+ fh.free_filename = 0; -+ fh.type = ZEND_HANDLE_FILENAME; -+ zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh); -+ RETURN_TRUE; -+ } -+ -+ RETURN_FALSE; -+} /* }}} */ -+ -+/* {{{ proto bool SplClassLoader::setIncludePath(string $include_path) -+ Sets the base include path for all class files in the namespace of this class loader */ -+SPL_METHOD(SplClassLoader, setIncludePath) -+{ -+ char* inc_path; -+ int inc_path_len; -+ spl_SplClassLoader* obj; -+ -+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &inc_path, &inc_path_len)== FAILURE) { -+ return; -+ } -+ -+ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); -+ -+ if (obj->inc_path) { -+ efree(obj->inc_path); -+ obj->inc_path = NULL; -+ } -+ -+ if (inc_path_len) { -+ obj->inc_path = estrndup(inc_path, inc_path_len); -+ } -+ -+ obj->inc_path_len = inc_path_len; -+ -+ RETURN_TRUE; -+} /* }}} */ -+ -+/* {{{ proto string SplClassLoader::getIncludePath() -+ Gets the base include path for all class files in the namespace of this class loader */ -+SPL_METHOD(SplClassLoader, getIncludePath) -+{ -+ spl_SplClassLoader* obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); -+ -+ if (obj->inc_path) { -+ RETURN_STRINGL(obj->inc_path, obj->inc_path_len, 1); -+ } -+ -+ RETURN_EMPTY_STRING(); -+} /* }}} */ -+ -+/* {{{ proto bool SplClassLoader::setFileExtension(string $file_extension) -+ Sets the file extension of class files in the namespace of this class loader */ -+SPL_METHOD(SplClassLoader, setFileExtension) -+{ -+ char* ext; -+ int ext_len; -+ spl_SplClassLoader* obj; -+ -+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ext, &ext_len) == FAILURE) { -+ RETURN_FALSE; -+ } -+ -+ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); -+ -+ if (obj->file_ext) { -+ efree(obj->file_ext); -+ obj->file_ext = NULL; -+ } -+ -+ if (ext_len) { -+ obj->file_ext = estrndup(ext, ext_len); -+ } -+ -+ obj->file_ext_len = ext_len; -+ -+ RETURN_TRUE; -+} /* }}} */ -+ -+/* {{{ proto string SplClassLoader::getFileExtension() -+ Gets the file extension of class files in the namespace of this class loader */ -+SPL_METHOD(SplClassLoader, getFileExtension) -+{ -+ spl_SplClassLoader* obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); -+ -+ if (obj->file_ext) { -+ RETURN_STRINGL(obj->file_ext, obj->file_ext_len, 1); -+ } -+ -+ RETURN_EMPTY_STRING(); -+} /* }}} */ -+ -+/* {{{ proto mixed SplClassLoader::getPath(string $class_name) -+ Gets the path for the given class. Does not load anything. This is just a handy method */ -+SPL_METHOD(SplClassLoader, getPath) -+{ -+ char* cl; -+ int cl_len = 0; -+ char filename[MAXPATHLEN]; -+ int len = 0; -+ spl_SplClassLoader* obj; -+ -+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cl, &cl_len) == FAILURE -+ || !cl_len) { -+ return; -+ } -+ -+ obj = (spl_SplClassLoader*) zend_object_store_get_object(getThis() TSRMLS_CC); -+ -+ len = get_filename(obj, cl, cl_len, filename TSRMLS_CC); -+ -+ if (len) { -+ RETURN_STRINGL(filename, --len, 1); /* cl_len > 0 and len includes '\0' */ -+ } -+ -+ RETURN_FALSE; -+} /* }}} */ -+ -+/* {{{ arginfo and function tables */ -+ZEND_BEGIN_ARG_INFO(arginfo_spl_classloader___construct, 0) -+ ZEND_ARG_INFO(0, namespace) -+ ZEND_ARG_INFO(0, include_path) -+ZEND_END_ARG_INFO() -+ -+ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_classloader_loadclass, 0, 0, 1) -+ ZEND_ARG_INFO(0, class_name) -+ZEND_END_ARG_INFO() -+ -+ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_classloader_setincludepath, 0, 0, 1) -+ ZEND_ARG_INFO(0, path) -+ZEND_END_ARG_INFO() -+ -+ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_classloader_setfileextension, 0, 0, 1) -+ ZEND_ARG_INFO(0, file_ext) -+ZEND_END_ARG_INFO() -+ -+ZEND_BEGIN_ARG_INFO(arginfo_spl_cl_void, 0) -+ZEND_END_ARG_INFO() -+ -+static const zend_function_entry spl_funcs_SplClassLoader[] = { -+ SPL_ME(SplClassLoader, __construct, arginfo_spl_classloader___construct, ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, register, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, unregister, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, loadClass, arginfo_spl_classloader_loadclass, ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, setIncludePath, arginfo_spl_classloader_setincludepath, ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, getIncludePath, arginfo_spl_cl_void , ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, setFileExtension, arginfo_spl_classloader_setfileextension, ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, getFileExtension, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) -+ SPL_ME(SplClassLoader, getPath, arginfo_spl_cl_void, ZEND_ACC_PUBLIC) -+ PHP_FE_END -+}; -+ -+/*const zend_function_entry spl_classloader_functions[] = { -+ {NULL, NULL, NULL} -+};*/ -+/* }}} */ -+ -+/* {{{ PHP_M* */ -+PHP_MINIT_FUNCTION(spl_classloader) -+{ -+ REGISTER_SPL_STD_CLASS_EX(SplClassLoader, spl_SplClassLoader_new, spl_funcs_SplClassLoader) -+ -+ memcpy(&spl_SplClassLoader_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); -+ spl_SplClassLoader_handlers.clone_obj = NULL; /* no cloning! */ -+ -+ return SUCCESS; -+} -+ -+PHP_MINFO_FUNCTION(spl_classloader) -+{ -+ php_info_print_table_start (); -+ php_info_print_table_header(2, "SplClassLoader support", "enabled"); -+ php_info_print_table_row (2, "Conformance", "PSR-0"); -+ php_info_print_table_end (); -+} -+/* }}} */ -+ -+/* -+ * Local variables: -+ * tab-width: 4 -+ * c-basic-offset: 4 -+ * End: -+ * vim600: fdm=marker -+ * vim: noet sw=4 ts=4 -+ */ -Index: ext/spl/spl_classloader.h -=================================================================== ---- ext/spl/spl_classloader.h (revision 0) -+++ ext/spl/spl_classloader.h (revision 0) -@@ -0,0 +1,40 @@ -+/* -+ +----------------------------------------------------------------------+ -+ | PHP Version 5 | -+ +----------------------------------------------------------------------+ -+ | Copyright (c) 1997-2009 The PHP Group | -+ +----------------------------------------------------------------------+ -+ | This source file is subject to version 3.01 of the PHP license, | -+ | that is bundled with this package in the file LICENSE, and is | -+ | available through the world-wide-web at the following url: | -+ | http://www.php.net/license/3_01.txt | -+ | If you did not receive a copy of the PHP license and are unable to | -+ | obtain it through the world-wide-web, please send a note to | -+ | license@php.net so we can mail you a copy immediately. | -+ +----------------------------------------------------------------------+ -+ | Authors: metagoto | -+ +----------------------------------------------------------------------+ -+ */ -+ -+#ifndef SPL_CLASSLOADER_H -+#define SPL_CLASSLOADER_H -+ -+#include "php.h" -+#include "php_spl.h" -+ -+extern PHPAPI zend_class_entry *spl_ce_SplClassLoader; -+ -+#ifdef ZTS -+#include "TSRM.h" -+#endif -+ -+#ifdef ZTS -+#define SPL_CLASSLD_G(v) TSRMG(spl_classloader_globals_id, zend_spl_classloader_globals *, v) -+#else -+#define SPL_CLASSLD_G(v) (spl_classloader_globals.v) -+#endif -+ -+PHP_MINIT_FUNCTION(spl_classloader); -+PHP_MINFO_FUNCTION(spl_classloader); -+ -+#endif /* SPL_CLASSLOADER_H */ -Index: ext/spl/config.w32 -=================================================================== ---- ext/spl/config.w32 (revision 318369) -+++ ext/spl/config.w32 (working copy) -@@ -1,7 +1,7 @@ - // $Id$ - // vim:ft=javascript - --EXTENSION("spl", "php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c", false /*never shared */); -+EXTENSION("spl", "php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c spl_classloader.c", false /*never shared */); - AC_DEFINE('HAVE_SPL', 1); - PHP_SPL="yes"; --PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h"); -+PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h spl_classloader.h"); -Index: ext/spl/config.m4 -=================================================================== ---- ext/spl/config.m4 (revision 318369) -+++ ext/spl/config.m4 (working copy) -@@ -1,6 +1,5 @@ - dnl $Id$ - dnl config.m4 for extension SPL -- - AC_MSG_CHECKING(whether zend_object_value is packed) - old_CPPFLAGS=$CPPFLAGS - CPPFLAGS="$INCLUDES -I$abs_srcdir $CPPFLAGS" -@@ -22,6 +21,6 @@ - CPPFLAGS=$old_CPPFLAGS - AC_DEFINE_UNQUOTED(HAVE_PACKED_OBJECT_VALUE, $ac_result, [Whether struct _zend_object_value is packed]) - AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support]) -- PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c, no) -- PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h]) -+ PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c spl_classloader.c, no) -+ PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h spl_classloader.h]) - PHP_ADD_EXTENSION_DEP(spl, pcre, true) -Index: ext/spl/php_spl.c -=================================================================== ---- ext/spl/php_spl.c (revision 318369) -+++ ext/spl/php_spl.c (working copy) -@@ -37,6 +37,7 @@ - #include "spl_dllist.h" - #include "spl_fixedarray.h" - #include "spl_heap.h" -+#include "spl_classloader.h" - #include "zend_exceptions.h" - #include "zend_interfaces.h" - #include "ext/standard/php_rand.h" -@@ -255,6 +256,7 @@ - SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \ -+ SPL_ADD_CLASS(SplClassLoader, z_list, sub, allow, ce_flags); \ - - /* {{{ proto array spl_classes() - Return an array containing the names of all clsses and interfaces defined in SPL */ -@@ -1038,6 +1040,7 @@ - PHP_MINIT(spl_heap)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU); -+ PHP_MINIT(spl_classloader)(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; - } diff --git a/tests/for_bench/SplClassLoaderUser.php b/tests/for_bench/SplClassLoaderUser.php index 564ad31..2778340 100644 --- a/tests/for_bench/SplClassLoaderUser.php +++ b/tests/for_bench/SplClassLoaderUser.php @@ -1,123 +1,123 @@ register(); -* -* @author Jonathan H. Wage -* @author Roman S. Borschel -* @author Matthew Weier O'Phinney -* @author Kris Wallsmith -* @author Fabien Potencier -*/ -class SplClassLoaderUser + * SplClassLoader implementation that implements the technical interoperability + * standards for PHP 5.3 namespaces and class names. + * + * http://groups.google.com/group/php-standards/web/final-proposal + * + * // Example which loads classes for the Doctrine Common package in the + * // Doctrine\Common namespace. + * $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); + * $classLoader->register(); + * + * @author Jonathan H. Wage + * @author Roman S. Borschel + * @author Matthew Weier O'Phinney + * @author Kris Wallsmith + * @author Fabien Potencier + */ +class SplClassLoader { private $_fileExtension = '.php'; private $_namespace; private $_includePath; private $_namespaceSeparator = '\\'; - + /** -* Creates a new SplClassLoader that loads classes of the -* specified namespace. -* -* @param string $ns The namespace to use. -*/ + * Creates a new SplClassLoader that loads classes of the + * specified namespace. + * + * @param string $ns The namespace to use. + */ public function __construct($ns = null, $includePath = null) { $this->_namespace = $ns; $this->_includePath = $includePath; } - + /** -* Sets the namespace separator used by classes in the namespace of this class loader. -* -* @param string $sep The separator to use. -*/ + * Sets the namespace separator used by classes in the namespace of this class loader. + * + * @param string $sep The separator to use. + */ public function setNamespaceSeparator($sep) { $this->_namespaceSeparator = $sep; } - + /** -* Gets the namespace seperator used by classes in the namespace of this class loader. -* -* @return void -*/ + * Gets the namespace seperator used by classes in the namespace of this class loader. + * + * @return void + */ public function getNamespaceSeparator() { return $this->_namespaceSeparator; } - + /** -* Sets the base include path for all class files in the namespace of this class loader. -* -* @param string $includePath -*/ + * Sets the base include path for all class files in the namespace of this class loader. + * + * @param string $includePath + */ public function setIncludePath($includePath) { $this->_includePath = $includePath; } - + /** -* Gets the base include path for all class files in the namespace of this class loader. -* -* @return string $includePath -*/ + * Gets the base include path for all class files in the namespace of this class loader. + * + * @return string $includePath + */ public function getIncludePath() { return $this->_includePath; } - + /** -* Sets the file extension of class files in the namespace of this class loader. -* -* @param string $fileExtension -*/ + * Sets the file extension of class files in the namespace of this class loader. + * + * @param string $fileExtension + */ public function setFileExtension($fileExtension) { $this->_fileExtension = $fileExtension; } - + /** -* Gets the file extension of class files in the namespace of this class loader. -* -* @return string $fileExtension -*/ + * Gets the file extension of class files in the namespace of this class loader. + * + * @return string $fileExtension + */ public function getFileExtension() { return $this->_fileExtension; } - + /** -* Installs this class loader on the SPL autoload stack. -*/ + * Installs this class loader on the SPL autoload stack. + */ public function register() { spl_autoload_register(array($this, 'loadClass')); } - + /** -* Uninstalls this class loader from the SPL autoloader stack. -*/ + * Uninstalls this class loader from the SPL autoloader stack. + */ public function unregister() { spl_autoload_unregister(array($this, 'loadClass')); } - + /** -* Loads the given class or interface. -* -* @param string $className The name of the class to load. -* @return void -*/ + * Loads the given class or interface. + * + * @param string $className The name of the class to load. + * @return void + */ public function loadClass($className) { if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) { @@ -129,8 +129,8 @@ public function loadClass($className) $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; - + require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; } } -} \ No newline at end of file +} From a5c0518873b78f013313c7b267656c2338d410af Mon Sep 17 00:00:00 2001 From: Marcel Araujo Date: Thu, 31 Jan 2013 10:48:59 -0200 Subject: [PATCH 10/10] Adding performance tests. --- tests/bench/SplClassLoader.php | 136 +++++++++++++++++++++++ tests/bench/functions.php | 25 +++++ tests/bench/index.php | 12 ++ tests/bench/results.txt | 7 ++ tests/bench/test-class.php | 24 ++++ tests/bench/test-native.php | 25 +++++ tests/bench/vendor/Yeap/Animal.php | 9 ++ tests/bench/vendor/Yeap/BigHornSheep.php | 7 ++ tests/bench/vendor/Yeap/Cow.php | 9 ++ tests/bench/vendor/Yeap/MilkCow.php | 7 ++ tests/bench/vendor/Yeap/Pig.php | 9 ++ tests/bench/vendor/Yeap/Piggy.php | 7 ++ tests/bench/vendor/Yeap/Sheep.php | 9 ++ 13 files changed, 286 insertions(+) create mode 100644 tests/bench/SplClassLoader.php create mode 100644 tests/bench/functions.php create mode 100644 tests/bench/index.php create mode 100644 tests/bench/results.txt create mode 100644 tests/bench/test-class.php create mode 100644 tests/bench/test-native.php create mode 100644 tests/bench/vendor/Yeap/Animal.php create mode 100644 tests/bench/vendor/Yeap/BigHornSheep.php create mode 100644 tests/bench/vendor/Yeap/Cow.php create mode 100644 tests/bench/vendor/Yeap/MilkCow.php create mode 100644 tests/bench/vendor/Yeap/Pig.php create mode 100644 tests/bench/vendor/Yeap/Piggy.php create mode 100644 tests/bench/vendor/Yeap/Sheep.php diff --git a/tests/bench/SplClassLoader.php b/tests/bench/SplClassLoader.php new file mode 100644 index 0000000..2778340 --- /dev/null +++ b/tests/bench/SplClassLoader.php @@ -0,0 +1,136 @@ +register(); + * + * @author Jonathan H. Wage + * @author Roman S. Borschel + * @author Matthew Weier O'Phinney + * @author Kris Wallsmith + * @author Fabien Potencier + */ +class SplClassLoader +{ + private $_fileExtension = '.php'; + private $_namespace; + private $_includePath; + private $_namespaceSeparator = '\\'; + + /** + * Creates a new SplClassLoader that loads classes of the + * specified namespace. + * + * @param string $ns The namespace to use. + */ + public function __construct($ns = null, $includePath = null) + { + $this->_namespace = $ns; + $this->_includePath = $includePath; + } + + /** + * Sets the namespace separator used by classes in the namespace of this class loader. + * + * @param string $sep The separator to use. + */ + public function setNamespaceSeparator($sep) + { + $this->_namespaceSeparator = $sep; + } + + /** + * Gets the namespace seperator used by classes in the namespace of this class loader. + * + * @return void + */ + public function getNamespaceSeparator() + { + return $this->_namespaceSeparator; + } + + /** + * Sets the base include path for all class files in the namespace of this class loader. + * + * @param string $includePath + */ + public function setIncludePath($includePath) + { + $this->_includePath = $includePath; + } + + /** + * Gets the base include path for all class files in the namespace of this class loader. + * + * @return string $includePath + */ + public function getIncludePath() + { + return $this->_includePath; + } + + /** + * Sets the file extension of class files in the namespace of this class loader. + * + * @param string $fileExtension + */ + public function setFileExtension($fileExtension) + { + $this->_fileExtension = $fileExtension; + } + + /** + * Gets the file extension of class files in the namespace of this class loader. + * + * @return string $fileExtension + */ + public function getFileExtension() + { + return $this->_fileExtension; + } + + /** + * Installs this class loader on the SPL autoload stack. + */ + public function register() + { + spl_autoload_register(array($this, 'loadClass')); + } + + /** + * Uninstalls this class loader from the SPL autoloader stack. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $className The name of the class to load. + * @return void + */ + public function loadClass($className) + { + if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) { + $fileName = ''; + $namespace = ''; + if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; + + require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; + } + } +} diff --git a/tests/bench/functions.php b/tests/bench/functions.php new file mode 100644 index 0000000..15d696a --- /dev/null +++ b/tests/bench/functions.php @@ -0,0 +1,25 @@ +register(); + +$piggy = new \Yeap\Piggy(); +$piggy->speak(); + +$cow = new \Yeap\MilkCow; +$cow->speak(); + +$sheep = new \Yeap\BigHornSheep; +$sheep->speak(); + +end_test($t0, "SplClassLoader PHP Class"); +echo "Memory Usage: " . (memory_get_usage() - $startMemory) . " bytes\n"; \ No newline at end of file diff --git a/tests/bench/test-native.php b/tests/bench/test-native.php new file mode 100644 index 0000000..d71d157 --- /dev/null +++ b/tests/bench/test-native.php @@ -0,0 +1,25 @@ +register(); + +$piggy = new \Yeap\Piggy(); +$piggy->speak(); + +$cow = new \Yeap\MilkCow; +$cow->speak(); + +$sheep = new \Yeap\BigHornSheep; +$sheep->speak(); + +end_test($t0, "SplClassLoader PHP Native"); +echo "Memory Usage: " . (memory_get_usage() - $startMemory) . " bytes\n"; \ No newline at end of file diff --git a/tests/bench/vendor/Yeap/Animal.php b/tests/bench/vendor/Yeap/Animal.php new file mode 100644 index 0000000..68e0d97 --- /dev/null +++ b/tests/bench/vendor/Yeap/Animal.php @@ -0,0 +1,9 @@ +