2003-05-01 23:28:28 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2004-01-08 18:17:39 +00:00
| PHP Version 5 |
2003-05-01 23:28:28 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2007-01-01 09:29:37 +00:00
| Copyright ( c ) 1997 - 2007 The PHP Group |
2003-05-01 23:28:28 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 13:10:10 +00:00
| This source file is subject to version 3.01 of the PHP license , |
2003-05-01 23:28:28 +00:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-12 19:30:54 +00:00
| available through the world - wide - web at the following url : |
2006-01-01 13:10:10 +00:00
| http : //www.php.net/license/3_01.txt |
2003-05-01 23:28:28 +00:00
| 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 : Marcus Boerger < helly @ php . net > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
2004-01-20 20:59:45 +00:00
/* $Id$ */
2003-05-01 23:28:28 +00:00
# ifdef HAVE_CONFIG_H
2007-11-01 22:31:39 +00:00
# include "config.h"
2003-05-01 23:28:28 +00:00
# endif
# include "php.h"
# include "php_ini.h"
2007-01-09 18:38:38 +00:00
# include "php_main.h"
2003-05-01 23:28:28 +00:00
# include "ext/standard/info.h"
# include "php_spl.h"
# include "spl_functions.h"
# include "spl_engine.h"
# include "spl_array.h"
2003-11-09 14:05:36 +00:00
# include "spl_directory.h"
# include "spl_iterators.h"
2004-01-18 15:33:38 +00:00
# include "spl_sxe.h"
2004-11-01 15:50:25 +00:00
# include "spl_exceptions.h"
2005-02-08 20:42:48 +00:00
# include "spl_observer.h"
2005-03-02 01:14:41 +00:00
# include "zend_exceptions.h"
# include "zend_interfaces.h"
2006-07-09 10:22:03 +00:00
# include "ext/standard/md5.h"
2003-05-01 23:28:28 +00:00
# ifdef COMPILE_DL_SPL
ZEND_GET_MODULE ( spl )
# endif
ZEND_DECLARE_MODULE_GLOBALS ( spl )
/* {{{ spl_functions_none
*/
2007-09-27 18:28:44 +00:00
const zend_function_entry spl_functions_none [ ] = {
2003-05-01 23:28:28 +00:00
{ NULL , NULL , NULL }
} ;
/* }}} */
2006-06-13 13:12:20 +00:00
/* {{{ PHP_GINIT_FUNCTION
2003-05-01 23:28:28 +00:00
*/
2006-06-13 13:12:20 +00:00
static PHP_GINIT_FUNCTION ( spl )
2003-05-01 23:28:28 +00:00
{
2006-12-20 22:11:14 +00:00
ZVAL_NULL ( & spl_globals - > autoload_extensions ) ;
2006-11-04 20:22:29 +00:00
spl_globals - > autoload_functions = NULL ;
spl_globals - > autoload_running = 0 ;
2003-05-01 23:28:28 +00:00
}
/* }}} */
2006-02-21 20:12:43 +00:00
static zend_class_entry * spl_find_ce_by_name ( zend_uchar ztype , zstr name , int len , zend_bool autoload TSRMLS_DC )
2005-04-06 15:16:45 +00:00
{
zend_class_entry * * ce ;
int found ;
2005-08-15 17:29:07 +00:00
2005-04-06 15:16:45 +00:00
if ( ! autoload ) {
2006-02-21 20:12:43 +00:00
zstr lc_name ;
2005-04-06 15:16:45 +00:00
2005-08-15 17:29:07 +00:00
lc_name = zend_u_str_tolower_dup ( ztype , name , len ) ;
found = zend_u_hash_find ( EG ( class_table ) , ztype , lc_name , len + 1 , ( void * * ) & ce ) ;
2006-02-21 20:12:43 +00:00
efree ( lc_name . v ) ;
2005-04-06 15:16:45 +00:00
} else {
2005-08-15 17:29:07 +00:00
found = zend_u_lookup_class ( ztype , name , len , & ce TSRMLS_CC ) ;
2005-04-06 15:16:45 +00:00
}
if ( found ! = SUCCESS ) {
2005-08-15 17:29:07 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " Class %v does not exist%s " , name , autoload ? " and could not be loaded " : " " ) ;
2005-04-06 15:16:45 +00:00
return NULL ;
}
return * ce ;
}
2006-11-04 20:12:26 +00:00
/* {{{ proto array class_parents(object instance) U
2005-02-13 18:14:34 +00:00
Return an array containing the names of all parent classes */
2003-05-01 23:28:28 +00:00
PHP_FUNCTION ( class_parents )
{
zval * obj ;
2005-04-06 15:16:45 +00:00
zend_class_entry * parent_class , * ce ;
zend_bool autoload = 1 ;
2003-05-01 23:28:28 +00:00
2005-04-06 15:16:45 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z|b " , & obj , & autoload ) = = FAILURE ) {
2003-05-01 23:28:28 +00:00
RETURN_FALSE ;
}
2005-04-06 15:16:45 +00:00
2005-08-15 17:29:07 +00:00
if ( Z_TYPE_P ( obj ) ! = IS_OBJECT & & Z_TYPE_P ( obj ) ! = IS_STRING & & Z_TYPE_P ( obj ) ! = IS_UNICODE ) {
2005-04-06 15:16:45 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " object or string expected " ) ;
RETURN_FALSE ;
}
2005-08-15 17:29:07 +00:00
if ( Z_TYPE_P ( obj ) = = IS_STRING | | Z_TYPE_P ( obj ) = = IS_UNICODE ) {
if ( NULL = = ( ce = spl_find_ce_by_name ( Z_TYPE_P ( obj ) , Z_UNIVAL_P ( obj ) , Z_UNILEN_P ( obj ) , autoload TSRMLS_CC ) ) ) {
2005-04-06 15:16:45 +00:00
RETURN_FALSE ;
}
} else {
ce = Z_OBJCE_P ( obj ) ;
}
2003-05-01 23:28:28 +00:00
array_init ( return_value ) ;
2005-04-06 15:16:45 +00:00
parent_class = ce - > parent ;
2003-05-01 23:28:28 +00:00
while ( parent_class ) {
2004-01-25 17:30:19 +00:00
spl_add_class_name ( return_value , parent_class , 0 , 0 TSRMLS_CC ) ;
2003-05-01 23:28:28 +00:00
parent_class = parent_class - > parent ;
}
}
/* }}} */
2006-11-04 20:12:26 +00:00
/* {{{ proto array class_implements(mixed what [, bool autoload ]) U
2005-02-13 18:14:34 +00:00
Return all classes and interfaces implemented by SPL */
2003-05-01 23:28:28 +00:00
PHP_FUNCTION ( class_implements )
{
zval * obj ;
2005-04-06 15:16:45 +00:00
zend_bool autoload = 1 ;
zend_class_entry * ce ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z|b " , & obj , & autoload ) = = FAILURE ) {
2003-05-01 23:28:28 +00:00
RETURN_FALSE ;
}
2005-08-15 17:29:07 +00:00
if ( Z_TYPE_P ( obj ) ! = IS_OBJECT & & Z_TYPE_P ( obj ) ! = IS_STRING & & Z_TYPE_P ( obj ) ! = IS_UNICODE ) {
2005-04-06 15:16:45 +00:00
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " object or string expected " ) ;
RETURN_FALSE ;
}
2005-08-15 17:29:07 +00:00
if ( Z_TYPE_P ( obj ) = = IS_STRING | | Z_TYPE_P ( obj ) = = IS_UNICODE ) {
if ( NULL = = ( ce = spl_find_ce_by_name ( Z_TYPE_P ( obj ) , Z_UNIVAL_P ( obj ) , Z_UNILEN_P ( obj ) , autoload TSRMLS_CC ) ) ) {
2005-04-06 15:16:45 +00:00
RETURN_FALSE ;
}
} else {
ce = Z_OBJCE_P ( obj ) ;
}
2003-05-01 23:28:28 +00:00
array_init ( return_value ) ;
2005-04-06 15:16:45 +00:00
spl_add_interfaces ( return_value , ce , 1 , ZEND_ACC_INTERFACE TSRMLS_CC ) ;
2003-05-01 23:28:28 +00:00
}
/* }}} */
2004-01-25 17:30:19 +00:00
# define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
2006-02-13 10:23:59 +00:00
spl_add_classes ( spl_ce_ # # class_name , z_list , sub , allow , ce_flags TSRMLS_CC )
2004-01-25 17:30:19 +00:00
# define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \
2004-11-01 00:26:59 +00:00
SPL_ADD_CLASS ( AppendIterator , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( ArrayIterator , z_list , sub , allow , ce_flags ) ; \
2005-08-24 10:16:45 +00:00
SPL_ADD_CLASS ( ArrayObject , z_list , sub , allow , ce_flags ) ; \
2004-11-01 17:39:59 +00:00
SPL_ADD_CLASS ( BadFunctionCallException , z_list , sub , allow , ce_flags ) ; \
2005-08-02 02:20:01 +00:00
SPL_ADD_CLASS ( BadMethodCallException , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( CachingIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 10:45:54 +00:00
SPL_ADD_CLASS ( Countable , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( DirectoryIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( DomainException , z_list , sub , allow , ce_flags ) ; \
2004-10-31 20:59:39 +00:00
SPL_ADD_CLASS ( EmptyIterator , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( FilterIterator , z_list , sub , allow , ce_flags ) ; \
2004-10-31 19:49:18 +00:00
SPL_ADD_CLASS ( InfiniteIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( InvalidArgumentException , z_list , sub , allow , ce_flags ) ; \
2004-10-31 18:43:00 +00:00
SPL_ADD_CLASS ( IteratorIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( LengthException , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( LimitIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( LogicException , z_list , sub , allow , ce_flags ) ; \
2004-10-31 18:43:00 +00:00
SPL_ADD_CLASS ( NoRewindIterator , z_list , sub , allow , ce_flags ) ; \
2004-10-29 20:12:57 +00:00
SPL_ADD_CLASS ( OuterIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( OutOfBoundsException , z_list , sub , allow , ce_flags ) ; \
2005-08-24 10:16:45 +00:00
SPL_ADD_CLASS ( OutOfRangeException , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( OverflowException , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( ParentIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( RangeException , z_list , sub , allow , ce_flags ) ; \
2005-09-18 16:51:24 +00:00
SPL_ADD_CLASS ( RecursiveArrayIterator , z_list , sub , allow , ce_flags ) ; \
SPL_ADD_CLASS ( RecursiveCachingIterator , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( RecursiveDirectoryIterator , z_list , sub , allow , ce_flags ) ; \
2005-08-10 22:01:15 +00:00
SPL_ADD_CLASS ( RecursiveFilterIterator , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( RecursiveIterator , z_list , sub , allow , ce_flags ) ; \
SPL_ADD_CLASS ( RecursiveIteratorIterator , z_list , sub , allow , ce_flags ) ; \
2006-05-10 21:09:31 +00:00
SPL_ADD_CLASS ( RecursiveRegexIterator , z_list , sub , allow , ce_flags ) ; \
SPL_ADD_CLASS ( RegexIterator , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( RuntimeException , z_list , sub , allow , ce_flags ) ; \
2004-01-25 17:30:19 +00:00
SPL_ADD_CLASS ( SeekableIterator , z_list , sub , allow , ce_flags ) ; \
SPL_ADD_CLASS ( SimpleXMLIterator , z_list , sub , allow , ce_flags ) ; \
2005-10-10 21:45:09 +00:00
SPL_ADD_CLASS ( SplFileInfo , z_list , sub , allow , ce_flags ) ; \
2005-09-15 14:07:39 +00:00
SPL_ADD_CLASS ( SplFileObject , z_list , sub , allow , ce_flags ) ; \
2005-08-10 22:01:15 +00:00
SPL_ADD_CLASS ( SplObjectStorage , z_list , sub , allow , ce_flags ) ; \
2005-09-15 03:31:37 +00:00
SPL_ADD_CLASS ( SplObserver , z_list , sub , allow , ce_flags ) ; \
SPL_ADD_CLASS ( SplSubject , z_list , sub , allow , ce_flags ) ; \
2005-10-29 15:15:22 +00:00
SPL_ADD_CLASS ( SplTempFileObject , z_list , sub , allow , ce_flags ) ; \
2004-11-01 15:50:25 +00:00
SPL_ADD_CLASS ( UnderflowException , z_list , sub , allow , ce_flags ) ; \
2005-08-24 10:16:45 +00:00
SPL_ADD_CLASS ( UnexpectedValueException , z_list , sub , allow , ce_flags ) ; \
2003-06-04 20:54:48 +00:00
2006-11-04 20:12:26 +00:00
/* {{{ proto array spl_classes() U
2005-02-13 18:14:34 +00:00
Return an array containing the names of all clsses and interfaces defined in SPL */
2003-05-01 23:28:28 +00:00
PHP_FUNCTION ( spl_classes )
{
array_init ( return_value ) ;
2004-01-25 17:30:19 +00:00
SPL_LIST_CLASSES ( return_value , 0 , 0 , 0 )
}
/* }}} */
2003-06-04 20:54:48 +00:00
2006-12-20 22:11:14 +00:00
int spl_autoload ( const zstr class_name , const zstr lc_name , int class_name_len , const zstr file_extension TSRMLS_DC ) /* { { { */
2005-03-02 01:14:41 +00:00
{
char * class_file ;
int class_file_len ;
int dummy = 1 ;
zend_file_handle file_handle ;
zend_op_array * new_op_array ;
zval * result = NULL ;
2006-08-03 14:53:51 +00:00
int ret ;
2005-04-05 09:24:53 +00:00
2007-01-12 22:28:05 +00:00
/* UTODO: We want the stream to acept a zstr for opening */
2006-12-20 22:11:14 +00:00
class_file_len = spprintf ( & class_file , 0 , " %v%v " , lc_name , file_extension ) ;
2005-03-02 01:14:41 +00:00
2007-01-09 18:38:38 +00:00
ret = php_stream_open_for_zend_ex ( class_file , & file_handle , ENFORCE_SAFE_MODE | USE_PATH | STREAM_OPEN_FOR_INCLUDE TSRMLS_CC ) ;
2006-08-03 14:53:51 +00:00
if ( ret = = SUCCESS ) {
2005-03-02 01:14:41 +00:00
if ( ! file_handle . opened_path ) {
file_handle . opened_path = estrndup ( class_file , class_file_len ) ;
}
if ( zend_hash_add ( & EG ( included_files ) , file_handle . opened_path , strlen ( file_handle . opened_path ) + 1 , ( void * ) & dummy , sizeof ( int ) , NULL ) = = SUCCESS ) {
new_op_array = zend_compile_file ( & file_handle , ZEND_REQUIRE TSRMLS_CC ) ;
zend_destroy_file_handle ( & file_handle TSRMLS_CC ) ;
} else {
new_op_array = NULL ;
zend_file_handle_dtor ( & file_handle ) ;
}
if ( new_op_array ) {
EG ( return_value_ptr_ptr ) = & result ;
EG ( active_op_array ) = new_op_array ;
2006-08-03 14:53:51 +00:00
2005-03-02 01:14:41 +00:00
zend_execute ( new_op_array TSRMLS_CC ) ;
destroy_op_array ( new_op_array TSRMLS_CC ) ;
efree ( new_op_array ) ;
if ( ! EG ( exception ) ) {
if ( EG ( return_value_ptr_ptr ) ) {
zval_ptr_dtor ( EG ( return_value_ptr_ptr ) ) ;
}
}
efree ( class_file ) ;
2006-12-20 22:11:14 +00:00
return zend_u_hash_exists ( EG ( class_table ) , ZEND_STR_TYPE , lc_name , class_name_len + 1 ) ;
2005-03-02 01:14:41 +00:00
}
}
efree ( class_file ) ;
return 0 ;
} /* }}} */
2006-12-20 22:11:14 +00:00
/* {{{ proto void spl_autoload(string class_name [, string file_extensions]) U
2005-03-02 01:14:41 +00:00
Default implementation for __autoload ( ) */
PHP_FUNCTION ( spl_autoload )
{
2006-12-20 22:11:14 +00:00
zstr class_name , lc_name ;
zstr file_exts = Z_UNIVAL ( SPL_G ( autoload_extensions ) ) ;
int class_name_len , file_exts_len = Z_UNILEN ( SPL_G ( autoload_extensions ) ) , found = 0 ;
int unicode = UG ( unicode ) ;
zstr copy , pos1 , pos2 ;
2005-03-02 01:14:41 +00:00
zval * * original_return_value = EG ( return_value_ptr_ptr ) ;
zend_op * * original_opline_ptr = EG ( opline_ptr ) ;
zend_op_array * original_active_op_array = EG ( active_op_array ) ;
2006-12-20 22:11:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " x|x " , & class_name , & class_name_len , & file_exts , & file_exts_len ) = = FAILURE ) {
2005-03-02 01:14:41 +00:00
RETURN_FALSE ;
}
2006-12-22 00:57:51 +00:00
copy = pos1 = ezstrndup ( ZEND_STR_TYPE , file_exts , file_exts_len ) ;
2006-12-20 22:11:14 +00:00
lc_name = zend_u_str_tolower_dup ( ZEND_STR_TYPE , class_name , class_name_len ) ;
while ( pos1 . v & & ( unicode ? * pos1 . u : * pos1 . s ) & & ! EG ( exception ) ) {
2005-03-02 01:14:41 +00:00
EG ( return_value_ptr_ptr ) = original_return_value ;
EG ( opline_ptr ) = original_opline_ptr ;
EG ( active_op_array ) = original_active_op_array ;
2006-12-20 22:11:14 +00:00
if ( unicode ) {
pos2 . u = u_strchr ( pos1 . u , ' , ' ) ;
if ( pos2 . u ) * pos2 . u = ' \0 ' ;
} else {
pos2 . s = strchr ( pos1 . s , ' , ' ) ;
if ( pos2 . s ) * pos2 . s = ' \0 ' ;
}
2005-03-02 01:14:41 +00:00
if ( spl_autoload ( class_name , lc_name , class_name_len , pos1 TSRMLS_CC ) ) {
found = 1 ;
break ; /* loaded */
}
2006-12-20 22:11:14 +00:00
if ( ! pos2 . v ) {
pos1 . v = NULL ;
} else if ( unicode ) {
pos1 . u = pos2 . u + 1 ;
} else {
pos1 . s = pos2 . s + 1 ;
}
2005-03-02 01:14:41 +00:00
}
2006-12-20 22:11:14 +00:00
efree ( lc_name . v ) ;
if ( copy . v ) {
efree ( copy . v ) ;
2005-03-02 01:14:41 +00:00
}
EG ( return_value_ptr_ptr ) = original_return_value ;
EG ( opline_ptr ) = original_opline_ptr ;
EG ( active_op_array ) = original_active_op_array ;
2006-10-31 23:18:00 +00:00
if ( ! found & & ! SPL_G ( autoload_running ) ) {
2006-12-20 22:11:14 +00:00
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Class %v could not be loaded " , class_name ) ;
2005-03-02 01:14:41 +00:00
}
} /* }}} */
2006-12-20 22:11:14 +00:00
/* {{{ proto string spl_autoload_extensions([string file_extensions]) U
2005-03-02 20:59:06 +00:00
Register and return default file extensions for spl_autoload */
2005-03-02 01:14:41 +00:00
PHP_FUNCTION ( spl_autoload_extensions )
{
2006-12-20 22:11:14 +00:00
zstr file_exts ;
2005-03-02 01:14:41 +00:00
int file_exts_len ;
2006-12-20 22:11:14 +00:00
zval * global = & SPL_G ( autoload_extensions ) ;
2005-03-02 01:14:41 +00:00
2005-03-02 20:59:06 +00:00
if ( ZEND_NUM_ARGS ( ) > 0 ) {
2006-12-20 22:11:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " x " , & file_exts , & file_exts_len ) = = FAILURE ) {
2005-03-02 20:59:06 +00:00
return ;
}
2006-12-20 22:11:14 +00:00
zval_dtor ( global ) ;
ZVAL_ZSTRL ( global , ZEND_STR_TYPE , file_exts , file_exts_len , 1 ) ;
2005-03-02 01:14:41 +00:00
}
2006-12-20 22:11:14 +00:00
RETURN_ZVAL ( global , 1 , 0 ) ;
2005-03-02 01:14:41 +00:00
} /* }}} */
2005-08-11 01:19:11 +00:00
typedef struct {
zend_function * func_ptr ;
zval * obj ;
zend_class_entry * ce ;
} autoload_func_info ;
static void autoload_func_info_dtor ( autoload_func_info * alfi )
{
if ( alfi - > obj ) {
zval_ptr_dtor ( & alfi - > obj ) ;
}
}
2006-12-19 22:30:59 +00:00
/* {{{ proto void spl_autoload_call(string class_name) U
2005-03-02 01:14:41 +00:00
Try all registerd autoload function to load the requested class */
PHP_FUNCTION ( spl_autoload_call )
{
2006-12-19 22:30:59 +00:00
zval * zclass_name , * retval = NULL ;
int class_name_len , func_name_type ;
zstr class_name , func_name , lc_name ;
2005-10-26 22:46:51 +00:00
uint func_name_len ;
ulong dummy ;
2005-03-02 01:14:41 +00:00
HashPosition function_pos ;
2005-08-11 01:19:11 +00:00
autoload_func_info * alfi ;
2005-03-02 01:14:41 +00:00
2006-12-19 22:31:26 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " x " , & class_name , & class_name_len ) = = FAILURE ) {
2005-03-02 01:14:41 +00:00
return ;
}
2006-12-19 22:30:59 +00:00
MAKE_STD_ZVAL ( zclass_name ) ;
ZVAL_ZSTRL ( zclass_name , ZEND_STR_TYPE , class_name , class_name_len , 1 ) ;
2005-03-02 01:14:41 +00:00
if ( SPL_G ( autoload_functions ) ) {
2006-10-31 23:18:00 +00:00
int l_autoload_running = SPL_G ( autoload_running ) ;
SPL_G ( autoload_running ) = 1 ;
2006-12-19 22:30:59 +00:00
lc_name = zend_u_str_tolower_dup ( ZEND_STR_TYPE , class_name , class_name_len ) ;
2005-03-02 01:14:41 +00:00
zend_hash_internal_pointer_reset_ex ( SPL_G ( autoload_functions ) , & function_pos ) ;
2005-04-05 09:24:53 +00:00
while ( zend_hash_has_more_elements_ex ( SPL_G ( autoload_functions ) , & function_pos ) = = SUCCESS & & ! EG ( exception ) ) {
2006-12-19 22:30:59 +00:00
func_name_type = zend_hash_get_current_key_ex ( SPL_G ( autoload_functions ) , & func_name , & func_name_len , & dummy , 0 , & function_pos ) ;
2005-08-11 01:19:11 +00:00
zend_hash_get_current_data_ex ( SPL_G ( autoload_functions ) , ( void * * ) & alfi , & function_pos ) ;
2006-12-19 22:30:59 +00:00
zend_u_call_method ( alfi - > obj ? & alfi - > obj : NULL , alfi - > ce , & alfi - > func_ptr , func_name_type , func_name , func_name_len , & retval , 1 , zclass_name , NULL TSRMLS_CC ) ;
2005-03-02 01:14:41 +00:00
if ( retval ) {
zval_ptr_dtor ( & retval ) ;
}
2006-12-19 22:30:59 +00:00
if ( zend_u_hash_exists ( EG ( class_table ) , ZEND_STR_TYPE , lc_name , class_name_len + 1 ) ) {
2005-03-02 01:14:41 +00:00
break ;
}
zend_hash_move_forward_ex ( SPL_G ( autoload_functions ) , & function_pos ) ;
}
2006-02-21 20:12:43 +00:00
efree ( lc_name . v ) ;
2006-10-31 23:18:00 +00:00
SPL_G ( autoload_running ) = l_autoload_running ;
2005-03-02 01:14:41 +00:00
} else {
/* do not use or overwrite &EG(autoload_func) here */
2006-12-19 22:30:59 +00:00
zend_call_method_with_1_params ( NULL , NULL , NULL , " spl_autoload " , NULL , zclass_name ) ;
2005-03-02 01:14:41 +00:00
}
2006-12-19 22:30:59 +00:00
zval_ptr_dtor ( & zclass_name ) ;
2005-03-02 01:14:41 +00:00
} /* }}} */
2006-11-04 20:12:26 +00:00
/* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true]]) U
2005-03-03 00:20:57 +00:00
Register given function as __autoload ( ) implementation */
2005-03-02 01:14:41 +00:00
PHP_FUNCTION ( spl_autoload_register )
{
2005-12-17 00:09:06 +00:00
zval zfunc_name , ztmp ;
2005-07-28 20:59:44 +00:00
zval * zcallable = NULL ;
2005-05-12 21:23:56 +00:00
zend_bool do_throw = 1 ;
2005-08-11 01:19:11 +00:00
zend_function * spl_func_ptr ;
autoload_func_info alfi ;
zval * * obj_ptr ;
2005-08-22 12:22:16 +00:00
2005-12-17 00:09:06 +00:00
if ( zend_parse_parameters_ex ( ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS ( ) TSRMLS_CC , " |zb " , & zcallable , & do_throw ) = = FAILURE ) {
return ;
}
if ( ZEND_NUM_ARGS ( ) ) {
if ( Z_TYPE_P ( zcallable ) = = IS_STRING ) {
if ( Z_STRLEN_P ( zcallable ) = = sizeof ( " spl_autoload_call " ) - 1 ) {
if ( ! zend_binary_strcasecmp ( Z_STRVAL_P ( zcallable ) , sizeof ( " spl_autoload_call " ) , " spl_autoload_call " , sizeof ( " spl_autoload_call " ) ) ) {
if ( do_throw ) {
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Function spl_autoload_call() cannot be registered " ) ;
}
2006-03-23 19:34:20 +00:00
RETURN_FALSE ;
2005-12-17 00:09:06 +00:00
}
2005-08-11 01:19:11 +00:00
}
2005-12-17 00:09:06 +00:00
} else if ( Z_TYPE_P ( zcallable ) = = IS_UNICODE ) {
2006-01-17 12:18:53 +00:00
ZVAL_ASCII_STRINGL ( & ztmp , " spl_autoload_call " , sizeof ( " spl_autoload_call " ) - 1 , 1 ) ;
2005-12-17 00:09:06 +00:00
if ( zend_u_binary_zval_strcmp ( & ztmp , zcallable ) ) {
if ( ! zend_binary_strcasecmp ( Z_STRVAL_P ( zcallable ) , sizeof ( " spl_autoload_call " ) , " spl_autoload_call " , sizeof ( " spl_autoload_call " ) ) ) {
if ( do_throw ) {
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Function spl_autoload_call() cannot be registered " ) ;
}
zval_dtor ( & ztmp ) ;
2006-03-23 19:34:20 +00:00
RETURN_FALSE ;
2005-12-17 00:09:06 +00:00
}
2005-08-11 01:19:11 +00:00
}
2005-12-17 00:09:06 +00:00
zval_dtor ( & ztmp ) ;
2005-07-28 20:59:44 +00:00
}
2005-12-17 00:09:06 +00:00
if ( ! zend_is_callable_ex ( zcallable , IS_CALLABLE_STRICT , & zfunc_name , & alfi . ce , & alfi . func_ptr , & obj_ptr TSRMLS_CC ) ) {
if ( Z_TYPE_P ( zcallable ) = = IS_ARRAY ) {
if ( ! obj_ptr & & alfi . func_ptr & & ! ( alfi . func_ptr - > common . fn_flags & ZEND_ACC_STATIC ) ) {
if ( do_throw ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Passed array specifies a non static method but no object " ) ;
2005-12-17 00:09:06 +00:00
}
zval_dtor ( & zfunc_name ) ;
2006-03-23 19:34:20 +00:00
RETURN_FALSE ;
2005-12-17 00:09:06 +00:00
}
else if ( do_throw ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Passed array does not specify %s %smethod " , alfi . func_ptr ? " a callable " : " an existing " , ! obj_ptr ? " static " : " " ) ;
2005-12-17 00:09:06 +00:00
}
zval_dtor ( & zfunc_name ) ;
2006-03-23 19:34:20 +00:00
RETURN_FALSE ;
2005-12-17 00:09:06 +00:00
} else if ( Z_TYPE_P ( zcallable ) = = IS_STRING | | Z_TYPE_P ( zcallable ) = = IS_UNICODE ) {
if ( do_throw ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Function '%R' not %s " , Z_TYPE_P ( zcallable ) , Z_UNIVAL_P ( zcallable ) , alfi . func_ptr ? " callable " : " found " ) ;
2005-12-17 00:09:06 +00:00
}
zval_dtor ( & zfunc_name ) ;
2006-03-23 19:34:20 +00:00
RETURN_FALSE ;
2005-12-17 00:09:06 +00:00
} else {
if ( do_throw ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Illegal value passed " ) ;
2005-12-17 00:09:06 +00:00
}
zval_dtor ( & zfunc_name ) ;
2006-03-23 19:34:20 +00:00
RETURN_FALSE ;
2005-12-17 00:09:06 +00:00
}
}
zend_u_str_tolower ( Z_TYPE ( zfunc_name ) , Z_UNIVAL ( zfunc_name ) , Z_UNILEN ( zfunc_name ) ) ;
2007-04-06 18:50:07 +00:00
if ( SPL_G ( autoload_functions ) & & zend_u_hash_exists ( SPL_G ( autoload_functions ) , Z_TYPE ( zfunc_name ) , Z_UNIVAL ( zfunc_name ) , Z_UNILEN ( zfunc_name ) + 1 ) ) {
goto skip ;
}
2005-08-11 01:19:11 +00:00
if ( obj_ptr & & ! ( alfi . func_ptr - > common . fn_flags & ZEND_ACC_STATIC ) ) {
2007-04-06 18:50:07 +00:00
/* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */
zstr lc_name ;
size_t func_name_len = Z_UNISIZE ( zfunc_name ) ;
2007-04-06 21:02:20 +00:00
lc_name . v = Z_UNIVAL ( zfunc_name ) . v = erealloc ( Z_UNIVAL ( zfunc_name ) . v , func_name_len + 2 + sizeof ( zend_object_handle ) ) ;
2007-04-06 18:50:07 +00:00
memcpy ( lc_name . s + func_name_len , & Z_OBJ_HANDLE_PP ( obj_ptr ) , sizeof ( zend_object_handle ) ) ;
func_name_len + = sizeof ( zend_object_handle ) ;
2005-08-11 01:19:11 +00:00
alfi . obj = * obj_ptr ;
2007-10-07 05:15:07 +00:00
Z_ADDREF_P ( alfi . obj ) ;
2007-04-06 18:50:07 +00:00
if ( Z_TYPE ( zfunc_name ) = = IS_UNICODE ) {
2007-04-06 21:02:20 +00:00
func_name_len / = sizeof ( UChar ) ;
Z_STRLEN ( zfunc_name ) = func_name_len ;
2007-04-06 21:07:48 +00:00
lc_name . u [ func_name_len ] = 0 ;
2007-04-06 18:50:07 +00:00
} else {
2007-04-06 21:02:20 +00:00
Z_STRLEN ( zfunc_name ) = func_name_len ;
lc_name . s [ func_name_len ] = ' \0 ' ;
2007-04-06 18:50:07 +00:00
}
2005-08-11 01:19:11 +00:00
} else {
alfi . obj = NULL ;
}
2005-03-02 01:14:41 +00:00
if ( ! SPL_G ( autoload_functions ) ) {
ALLOC_HASHTABLE ( SPL_G ( autoload_functions ) ) ;
2005-08-22 12:22:16 +00:00
zend_u_hash_init ( SPL_G ( autoload_functions ) , 1 , NULL , ( dtor_func_t ) autoload_func_info_dtor , 0 , UG ( unicode ) ) ;
2005-03-02 01:14:41 +00:00
}
2005-03-03 00:20:57 +00:00
zend_hash_find ( EG ( function_table ) , " spl_autoload " , sizeof ( " spl_autoload " ) , ( void * * ) & spl_func_ptr ) ;
if ( EG ( autoload_func ) = = spl_func_ptr ) { /* registered already, so we insert that first */
2005-11-03 21:58:42 +00:00
autoload_func_info spl_alfi ;
spl_alfi . func_ptr = spl_func_ptr ;
spl_alfi . obj = NULL ;
spl_alfi . ce = NULL ;
2005-08-11 01:19:11 +00:00
zend_hash_add ( SPL_G ( autoload_functions ) , " spl_autoload " , sizeof ( " spl_autoload " ) , & spl_alfi , sizeof ( autoload_func_info ) , NULL ) ;
2005-03-03 00:20:57 +00:00
}
2005-12-17 00:09:06 +00:00
zend_u_hash_add ( SPL_G ( autoload_functions ) , Z_TYPE ( zfunc_name ) , Z_UNIVAL ( zfunc_name ) , Z_UNILEN ( zfunc_name ) + 1 , & alfi , sizeof ( autoload_func_info ) , NULL ) ;
2007-04-06 18:50:07 +00:00
skip :
2005-12-17 00:09:06 +00:00
zval_dtor ( & zfunc_name ) ;
2005-03-02 01:14:41 +00:00
}
if ( SPL_G ( autoload_functions ) ) {
zend_hash_find ( EG ( function_table ) , " spl_autoload_call " , sizeof ( " spl_autoload_call " ) , ( void * * ) & EG ( autoload_func ) ) ;
} else {
zend_hash_find ( EG ( function_table ) , " spl_autoload " , sizeof ( " spl_autoload " ) , ( void * * ) & EG ( autoload_func ) ) ;
}
2006-03-23 19:34:20 +00:00
RETURN_TRUE ;
2005-03-02 01:14:41 +00:00
} /* }}} */
2006-11-04 20:12:26 +00:00
/* {{{ proto bool spl_autoload_unregister(mixed autoload_function) U
2005-03-03 00:20:57 +00:00
Unregister given function as __autoload ( ) implementation */
PHP_FUNCTION ( spl_autoload_unregister )
{
2006-03-23 12:55:58 +00:00
zval zfunc_name ;
zval * zcallable ;
zstr lc_name ;
int success = FAILURE ;
2005-03-03 00:20:57 +00:00
zend_function * spl_func_ptr ;
2007-04-06 18:50:07 +00:00
zval * * obj_ptr ;
2005-03-03 00:20:57 +00:00
2006-03-23 12:55:58 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " z " , & zcallable ) = = FAILURE ) {
return ;
}
2007-04-06 18:50:07 +00:00
if ( ! zend_is_callable_ex ( zcallable , IS_CALLABLE_CHECK_SYNTAX_ONLY , & zfunc_name , NULL , NULL , & obj_ptr TSRMLS_CC ) ) {
2006-03-23 12:55:58 +00:00
zval_dtor ( & zfunc_name ) ;
2006-03-23 19:34:20 +00:00
RETURN_FALSE ;
2005-03-03 00:20:57 +00:00
}
2006-03-23 12:55:58 +00:00
lc_name = zend_u_str_tolower_dup ( Z_TYPE ( zfunc_name ) , Z_UNIVAL ( zfunc_name ) , Z_UNILEN ( zfunc_name ) ) ;
2005-03-03 00:20:57 +00:00
if ( SPL_G ( autoload_functions ) ) {
2006-03-23 12:55:58 +00:00
if ( ( Z_UNILEN ( zfunc_name ) = = sizeof ( " spl_autoload_call " ) - 1 ) & &
( ZEND_U_EQUAL ( Z_TYPE ( zfunc_name ) , lc_name , Z_UNILEN ( zfunc_name ) , " spl_autoload_call " , sizeof ( " spl_autoload_call " ) - 1 ) ) ) {
2005-03-03 00:20:57 +00:00
/* remove all */
zend_hash_destroy ( SPL_G ( autoload_functions ) ) ;
FREE_HASHTABLE ( SPL_G ( autoload_functions ) ) ;
SPL_G ( autoload_functions ) = NULL ;
EG ( autoload_func ) = NULL ;
success = SUCCESS ;
} else {
/* remove specific */
2006-03-23 12:55:58 +00:00
success = zend_u_hash_del ( SPL_G ( autoload_functions ) , Z_TYPE ( zfunc_name ) , lc_name , Z_UNILEN ( zfunc_name ) + 1 ) ;
2007-04-06 18:50:07 +00:00
if ( success ! = SUCCESS & & obj_ptr ) {
size_t func_name_len = Z_UNISIZE ( zfunc_name ) ;
2007-04-06 21:07:48 +00:00
lc_name . v = erealloc ( lc_name . v , func_name_len + 2 + sizeof ( zend_object_handle ) ) ;
2007-04-09 15:33:59 +00:00
memcpy ( lc_name . s + func_name_len , & Z_OBJ_HANDLE_PP ( obj_ptr ) , sizeof ( zend_object_handle ) ) ;
2007-04-06 19:04:53 +00:00
func_name_len + = sizeof ( zend_object_handle ) ;
2007-04-06 18:50:07 +00:00
if ( Z_TYPE ( zfunc_name ) = = IS_UNICODE ) {
func_name_len / = sizeof ( UChar ) ;
2007-04-06 21:07:48 +00:00
lc_name . u [ func_name_len ] = 0 ;
} else {
lc_name . s [ func_name_len ] = ' \0 ' ;
2007-04-06 18:50:07 +00:00
}
success = zend_u_hash_del ( SPL_G ( autoload_functions ) , Z_TYPE ( zfunc_name ) , lc_name , func_name_len + 1 ) ;
}
2005-03-03 00:20:57 +00:00
}
2006-03-23 12:55:58 +00:00
} else if ( ( Z_UNILEN ( zfunc_name ) = = sizeof ( " spl_autoload " ) - 1 ) & &
( ZEND_U_EQUAL ( Z_TYPE ( zfunc_name ) , lc_name , Z_UNILEN ( zfunc_name ) , " spl_autoload " , sizeof ( " spl_autoload " ) - 1 ) ) ) {
2005-03-03 00:20:57 +00:00
/* register single spl_autoload() */
zend_hash_find ( EG ( function_table ) , " spl_autoload " , sizeof ( " spl_autoload " ) , ( void * * ) & spl_func_ptr ) ;
if ( EG ( autoload_func ) = = spl_func_ptr ) {
success = SUCCESS ;
EG ( autoload_func ) = NULL ;
}
}
2006-02-21 20:12:43 +00:00
efree ( lc_name . v ) ;
2006-03-23 12:55:58 +00:00
zval_dtor ( & zfunc_name ) ;
2005-03-03 00:20:57 +00:00
RETURN_BOOL ( success = = SUCCESS ) ;
} /* }}} */
2006-11-04 20:12:26 +00:00
/* {{{ proto false|array spl_autoload_functions() U
2005-03-03 00:20:57 +00:00
Return all registered __autoload ( ) functionns */
PHP_FUNCTION ( spl_autoload_functions )
{
zend_function * fptr , * * func_ptr_ptr ;
HashPosition function_pos ;
if ( ! EG ( autoload_func ) ) {
if ( zend_hash_find ( EG ( function_table ) , ZEND_AUTOLOAD_FUNC_NAME , sizeof ( ZEND_AUTOLOAD_FUNC_NAME ) , ( void * * ) & fptr ) = = SUCCESS ) {
array_init ( return_value ) ;
add_next_index_stringl ( return_value , ZEND_AUTOLOAD_FUNC_NAME , sizeof ( ZEND_AUTOLOAD_FUNC_NAME ) - 1 , 1 ) ;
return ;
}
RETURN_FALSE ;
}
zend_hash_find ( EG ( function_table ) , " spl_autoload_call " , sizeof ( " spl_autoload_call " ) , ( void * * ) & fptr ) ;
if ( EG ( autoload_func ) = = fptr ) {
array_init ( return_value ) ;
zend_hash_internal_pointer_reset_ex ( SPL_G ( autoload_functions ) , & function_pos ) ;
while ( zend_hash_has_more_elements_ex ( SPL_G ( autoload_functions ) , & function_pos ) = = SUCCESS ) {
zend_hash_get_current_data_ex ( SPL_G ( autoload_functions ) , ( void * * ) & func_ptr_ptr , & function_pos ) ;
2005-07-28 20:59:44 +00:00
if ( ( * func_ptr_ptr ) - > common . scope ) {
zval * tmp ;
MAKE_STD_ZVAL ( tmp ) ;
array_init ( tmp ) ;
2005-08-22 13:32:46 +00:00
add_next_index_text ( tmp , ( * func_ptr_ptr ) - > common . scope - > name , 1 ) ;
add_next_index_text ( tmp , ( * func_ptr_ptr ) - > common . function_name , 1 ) ;
2005-07-28 20:59:44 +00:00
add_next_index_zval ( return_value , tmp ) ;
} else
2005-08-22 13:32:46 +00:00
add_next_index_text ( return_value , ( * func_ptr_ptr ) - > common . function_name , 1 ) ;
2005-07-28 20:59:44 +00:00
2005-03-03 00:20:57 +00:00
zend_hash_move_forward_ex ( SPL_G ( autoload_functions ) , & function_pos ) ;
}
return ;
}
array_init ( return_value ) ;
2005-08-22 13:32:46 +00:00
add_next_index_text ( return_value , EG ( autoload_func ) - > common . function_name , 1 ) ;
2005-03-03 00:20:57 +00:00
} /* }}} */
2006-11-04 20:12:26 +00:00
/* {{{ proto string spl_object_hash(object obj) U
2006-07-09 10:22:03 +00:00
Return hash id for given object */
PHP_FUNCTION ( spl_object_hash )
{
zval * obj ;
2007-01-19 23:23:08 +00:00
char * md5str ;
2006-07-09 10:22:03 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " o " , & obj ) = = FAILURE ) {
return ;
}
2007-01-19 23:23:08 +00:00
md5str = emalloc ( 33 ) ;
php_spl_object_hash ( obj , md5str TSRMLS_CC ) ;
RETVAL_STRING ( md5str , 0 ) ;
}
/* }}} */
PHPAPI void php_spl_object_hash ( zval * obj , char * md5str TSRMLS_DC ) /* { { { */
{
int len ;
char * hash ;
PHP_MD5_CTX context ;
unsigned char digest [ 16 ] ;
2006-07-09 10:22:03 +00:00
len = spprintf ( & hash , 0 , " %p:%d " , Z_OBJ_HT_P ( obj ) , Z_OBJ_HANDLE_P ( obj ) ) ;
md5str [ 0 ] = ' \0 ' ;
PHP_MD5Init ( & context ) ;
PHP_MD5Update ( & context , ( unsigned char * ) hash , len ) ;
PHP_MD5Final ( digest , & context ) ;
make_digest ( md5str , digest ) ;
efree ( hash ) ;
}
2007-01-19 23:23:08 +00:00
/* }}} */
2006-07-09 10:22:03 +00:00
2005-02-13 18:30:26 +00:00
int spl_build_class_list_string ( zval * * entry , char * * list TSRMLS_DC ) /* { { { */
2004-01-25 17:30:19 +00:00
{
char * res ;
2005-11-20 15:21:23 +00:00
spprintf ( & res , 0 , " %s, %v " , * list , Z_STRVAL_PP ( entry ) ) ;
2004-01-25 17:30:19 +00:00
efree ( * list ) ;
* list = res ;
return ZEND_HASH_APPLY_KEEP ;
2005-02-13 18:30:26 +00:00
} /* }}} */
2004-01-25 17:30:19 +00:00
/* {{{ PHP_MINFO(spl)
*/
PHP_MINFO_FUNCTION ( spl )
{
zval list ;
char * strg ;
php_info_print_table_start ( ) ;
php_info_print_table_header ( 2 , " SPL support " , " enabled " ) ;
INIT_PZVAL ( & list ) ;
array_init ( & list ) ;
SPL_LIST_CLASSES ( & list , 0 , 1 , ZEND_ACC_INTERFACE )
strg = estrdup ( " " ) ;
zend_hash_apply_with_argument ( Z_ARRVAL_P ( & list ) , ( apply_func_arg_t ) spl_build_class_list_string , & strg TSRMLS_CC ) ;
zval_dtor ( & list ) ;
php_info_print_table_row ( 2 , " Interfaces " , strg + 2 ) ;
efree ( strg ) ;
INIT_PZVAL ( & list ) ;
array_init ( & list ) ;
SPL_LIST_CLASSES ( & list , 0 , - 1 , ZEND_ACC_INTERFACE )
strg = estrdup ( " " ) ;
zend_hash_apply_with_argument ( Z_ARRVAL_P ( & list ) , ( apply_func_arg_t ) spl_build_class_list_string , & strg TSRMLS_CC ) ;
zval_dtor ( & list ) ;
php_info_print_table_row ( 2 , " Classes " , strg + 2 ) ;
efree ( strg ) ;
php_info_print_table_end ( ) ;
2003-05-01 23:28:28 +00:00
}
/* }}} */
2006-11-20 19:50:19 +00:00
static
2006-11-20 20:03:46 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_iterator_to_array , 0 , 0 , 1 )
2006-11-20 19:50:19 +00:00
ZEND_ARG_OBJ_INFO ( 0 , iterator , Traversable , 0 )
ZEND_ARG_INFO ( 0 , use_keys )
ZEND_END_ARG_INFO ( ) ;
2006-02-20 22:23:27 +00:00
static
ZEND_BEGIN_ARG_INFO ( arginfo_iterator , 0 )
2006-05-26 00:49:02 +00:00
ZEND_ARG_OBJ_INFO ( 0 , iterator , Traversable , 0 )
2006-05-26 00:37:33 +00:00
ZEND_END_ARG_INFO ( ) ;
static
ZEND_BEGIN_ARG_INFO_EX ( arginfo_iterator_apply , 0 , 0 , 2 )
2006-05-26 00:49:02 +00:00
ZEND_ARG_OBJ_INFO ( 0 , iterator , Traversable , 0 )
2006-05-26 00:37:33 +00:00
ZEND_ARG_INFO ( 0 , function )
2006-05-26 01:40:57 +00:00
ZEND_ARG_ARRAY_INFO ( 0 , args , 1 )
2006-02-20 22:23:27 +00:00
ZEND_END_ARG_INFO ( ) ;
2005-02-13 18:30:26 +00:00
/* {{{ spl_functions
*/
2007-09-27 18:28:44 +00:00
const zend_function_entry spl_functions [ ] = {
2005-02-13 18:30:26 +00:00
PHP_FE ( spl_classes , NULL )
2005-03-02 01:14:41 +00:00
PHP_FE ( spl_autoload , NULL )
PHP_FE ( spl_autoload_extensions , NULL )
PHP_FE ( spl_autoload_register , NULL )
2005-03-03 00:20:57 +00:00
PHP_FE ( spl_autoload_unregister , NULL )
PHP_FE ( spl_autoload_functions , NULL )
2005-03-02 01:14:41 +00:00
PHP_FE ( spl_autoload_call , NULL )
2005-02-13 18:30:26 +00:00
PHP_FE ( class_parents , NULL )
PHP_FE ( class_implements , NULL )
2006-07-09 10:22:03 +00:00
PHP_FE ( spl_object_hash , NULL )
2005-02-13 18:30:26 +00:00
# ifdef SPL_ITERATORS_H
2006-11-20 19:50:19 +00:00
PHP_FE ( iterator_to_array , arginfo_iterator_to_array )
2006-02-20 22:23:27 +00:00
PHP_FE ( iterator_count , arginfo_iterator )
2006-05-26 00:37:33 +00:00
PHP_FE ( iterator_apply , arginfo_iterator_apply )
2005-02-13 18:30:26 +00:00
# endif /* SPL_ITERATORS_H */
{ NULL , NULL , NULL }
} ;
/* }}} */
/* {{{ PHP_MINIT_FUNCTION(spl)
*/
PHP_MINIT_FUNCTION ( spl )
{
PHP_MINIT ( spl_iterators ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( spl_array ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( spl_directory ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( spl_sxe ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( spl_exceptions ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
PHP_MINIT ( spl_observer ) ( INIT_FUNC_ARGS_PASSTHRU ) ;
return SUCCESS ;
}
/* }}} */
2005-03-02 01:14:41 +00:00
PHP_RINIT_FUNCTION ( spl ) /* {{{ */
{
2006-12-20 22:11:14 +00:00
INIT_PZVAL ( & SPL_G ( autoload_extensions ) ) ;
ZVAL_ASCII_STRINGL ( & SPL_G ( autoload_extensions ) , " .inc,.php " , sizeof ( " .inc,.php " ) - 1 , 1 ) ;
2005-09-26 17:54:57 +00:00
SPL_G ( autoload_functions ) = NULL ;
2006-11-04 20:22:29 +00:00
SPL_G ( autoload_running ) = 0 ;
2005-03-02 01:14:41 +00:00
return SUCCESS ;
} /* }}} */
PHP_RSHUTDOWN_FUNCTION ( spl ) /* {{{ */
{
2006-12-20 22:11:14 +00:00
if ( Z_TYPE ( SPL_G ( autoload_extensions ) ) ! = IS_NULL ) {
zval_dtor ( & SPL_G ( autoload_extensions ) ) ;
ZVAL_NULL ( & SPL_G ( autoload_extensions ) ) ;
2005-03-02 01:14:41 +00:00
}
if ( SPL_G ( autoload_functions ) ) {
zend_hash_destroy ( SPL_G ( autoload_functions ) ) ;
FREE_HASHTABLE ( SPL_G ( autoload_functions ) ) ;
2005-09-26 17:54:57 +00:00
SPL_G ( autoload_functions ) = NULL ;
2005-03-02 01:14:41 +00:00
}
return SUCCESS ;
} /* }}} */
2005-06-17 16:42:54 +00:00
# ifdef HAVE_SIMPLEXML
2007-09-27 18:28:44 +00:00
static const zend_module_dep spl_deps [ ] = {
2005-06-17 16:42:54 +00:00
ZEND_MOD_REQUIRED ( " libxml " )
ZEND_MOD_REQUIRED ( " simplexml " )
{ NULL , NULL , NULL }
} ;
# endif
2005-02-13 18:30:26 +00:00
/* {{{ spl_module_entry
*/
zend_module_entry spl_module_entry = {
2005-06-17 16:42:54 +00:00
# ifdef HAVE_SIMPLEXML
STANDARD_MODULE_HEADER_EX , NULL ,
spl_deps ,
# else
2005-02-13 18:30:26 +00:00
STANDARD_MODULE_HEADER ,
2005-06-17 16:42:54 +00:00
# endif
2005-02-13 18:30:26 +00:00
" SPL " ,
spl_functions ,
PHP_MINIT ( spl ) ,
NULL ,
2005-03-02 01:14:41 +00:00
PHP_RINIT ( spl ) ,
PHP_RSHUTDOWN ( spl ) ,
2005-02-13 18:30:26 +00:00
PHP_MINFO ( spl ) ,
" 0.2 " ,
2006-06-13 13:12:20 +00:00
PHP_MODULE_GLOBALS ( spl ) ,
PHP_GINIT ( spl ) ,
NULL ,
NULL ,
STANDARD_MODULE_PROPERTIES_EX
2005-02-13 18:30:26 +00:00
} ;
/* }}} */
2003-05-01 23:28:28 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
* vim600 : fdm = marker
* vim : noet sw = 4 ts = 4
*/