]> granicus.if.org Git - php/commitdiff
add the ability to automatically resolve includes inside a phar to files within that...
authorGreg Beaver <cellog@php.net>
Sun, 9 Dec 2007 21:57:44 +0000 (21:57 +0000)
committerGreg Beaver <cellog@php.net>
Sun, 9 Dec 2007 21:57:44 +0000 (21:57 +0000)
no code modification is needed to include/require

ext/phar/phar.c

index 6ddb4c4cdd0c5de38f54e2cca2bf08c9f7907a92..436943b36cf4dde67047f6d2a4108d3ad0e5dcfb 100644 (file)
@@ -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;
 }
 /* }}} */