summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2007-12-09 21:57:44 +0000
committerGreg Beaver <cellog@php.net>2007-12-09 21:57:44 +0000
commit688aef57f861840828449e5b161efaf951d39e64 (patch)
tree15d232b9b33af752e77b2883285b4431df9dfcaf
parent5a14715596711dcdba597f6cadb9c71de9b07cb3 (diff)
downloadphp-git-688aef57f861840828449e5b161efaf951d39e64.tar.gz
add the ability to automatically resolve includes inside a phar to files within that phar, so
no code modification is needed to include/require
-rw-r--r--ext/phar/phar.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index 6ddb4c4cdd..436943b36c 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -3757,6 +3757,51 @@ static void php_phar_init_globals_module(zend_phar_globals *phar_globals)
}
/* }}} */
+static zend_op_array *(*orig_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
+
+static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) /* {{{ */
+{
+ zend_op_array *res;
+ char *fname = NULL;
+ int fname_len;
+
+ zend_compile_file = orig_compile_file;
+ if (zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map))) {
+ char *arch, *entry;
+ int arch_len, entry_len;
+ fname = zend_get_executed_filename(TSRMLS_C);
+ if (strncasecmp(fname, "phar://", 7)) {
+ goto skip_phar;
+ }
+ fname_len = strlen(fname);
+ if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len TSRMLS_CC)) {
+ char *s, *name;
+
+ efree(entry);
+ entry = file_handle->filename;
+ /* include within phar, if :// is not in the url, then prepend phar://<archive>/ */
+ entry_len = strlen(entry);
+ for (s = entry; s < (entry + entry_len - 4); s++) {
+ if (*s == ':' && *(s + 1) == '/' && *(s + 2) == '/') {
+ efree(arch);
+ goto skip_phar;
+ }
+ }
+ /* auto-convert to phar:// */
+ spprintf(&name, 4096, "phar://%s/%s", arch, entry);
+ efree(arch);
+ file_handle->type = ZEND_HANDLE_FILENAME;
+ file_handle->free_filename = 1;
+ file_handle->filename = name;
+ }
+ }
+skip_phar:
+ res = orig_compile_file(file_handle, type TSRMLS_CC);
+ zend_compile_file = phar_compile_file;
+ return res;
+}
+/* }}} */
+
PHP_MINIT_FUNCTION(phar) /* {{{ */
{
ZEND_INIT_MODULE_GLOBALS(phar, php_phar_init_globals_module, NULL);
@@ -3765,6 +3810,8 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */
PHAR_G(has_gnupg) = zend_hash_exists(&module_registry, "gnupg", sizeof("gnupg"));
PHAR_G(has_bz2) = zend_hash_exists(&module_registry, "bz2", sizeof("bz2"));
PHAR_G(has_zlib) = zend_hash_exists(&module_registry, "zlib", sizeof("zlib"));
+ orig_compile_file = zend_compile_file;
+ zend_compile_file = phar_compile_file;
phar_object_init(TSRMLS_C);
return php_register_url_stream_wrapper("phar", &php_stream_phar_wrapper TSRMLS_CC);
@@ -3774,6 +3821,7 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */
PHP_MSHUTDOWN_FUNCTION(phar) /* {{{ */
{
return php_unregister_url_stream_wrapper("phar" TSRMLS_CC);
+ zend_compile_file = orig_compile_file;
}
/* }}} */