#!/bin/sh
-export SCRIPT_NAME=/frontcontroller9.php
-export PATH_INFO=/hi
-export SCRIPT_FILENAME=/home/cellog/workspace/php5/ext/phar/tests/cache_list/frontcontroller9.php
-export PATH_TRANSLATED=/home/cellog/workspace/php5/ext/phar/tests/cache_list/frontcontroller9.php
+export SCRIPT_NAME=/front.phar.php
+export PATH_INFO=/index.php
+export SCRIPT_FILENAME=/home/cellog/workspace/php5/ext/phar/tests/front.phar.php
+export PATH_TRANSLATED=/home/cellog/workspace/php5/ext/phar/tests/front.phar.php
export REDIRECT_STATUS=1
export REQUEST_METHOD=GET
-export REQUEST_URI=/frontcontroller9.php/hi
-cd /home/cellog/workspace/php5/ext/phar/tests/cache_list
-ddd ../../../../sapi/cgi/php-cgi &
+export REQUEST_URI=/front.phar.php/index.php
+cd /home/cellog/workspace/php5
+ddd sapi/cgi/php-cgi &
cd /home/cellog/workspace/php5/ext/phar
/* compressed phar */
#if PHP_VERSION_ID >= 50300
file_handle->type = ZEND_HANDLE_STREAM;
- file_handle->free_filename = 0;
/* we do our own reading directly from the phar, don't change the next line */
file_handle->handle.stream.handle = phar;
file_handle->handle.stream.reader = phar_zend_stream_reader;
memset(&file_handle->handle.stream.mmap, 0, sizeof(file_handle->handle.stream.mmap));
#else /* PHP_VERSION_ID */
file_handle->type = ZEND_HANDLE_STREAM;
- file_handle->free_filename = 0;
/* we do our own reading directly from the phar, don't change the next line */
file_handle->handle.stream.handle = phar;
file_handle->handle.stream.reader = phar_zend_stream_reader;
*/
static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) /* {{{ */
{
+ phar_archive_data *phar;
phar_entry_data *idata;
char *internal_file;
char *error;
}
return fpf;
} else {
+ if (!*internal_file && (options & STREAM_OPEN_FOR_INCLUDE)) {
+ /* retrieve the stub */
+ if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, NULL TSRMLS_CC)) {
+ php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "file %s is not a valid phar archive");
+ efree(internal_file);
+ php_url_free(resource);
+ return NULL;
+ }
+ if (phar->is_tar || phar->is_zip) {
+ if ((FAILURE == phar_get_entry_data(&idata, resource->host, host_len, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0 TSRMLS_CC)) || !idata) {
+ goto idata_error;
+ }
+ efree(internal_file);
+ if (opened_path) {
+ spprintf(opened_path, MAXPATHLEN, "%s", phar->fname);
+ }
+ php_url_free(resource);
+ goto phar_stub;
+ } else {
+ phar_entry_info *entry;
+
+ entry = (phar_entry_info *) ecalloc(1, sizeof(phar_entry_info));
+ entry->is_temp_dir = 1;
+ entry->filename = "";
+ entry->filename_len = 0;
+ entry->phar = phar;
+ entry->offset = entry->offset_abs = 0;
+ entry->compressed_filesize = entry->uncompressed_filesize = phar->halt_offset;
+ entry->is_crc_checked = 1;
+
+ idata = (phar_entry_data *) ecalloc(1, sizeof(phar_entry_data));
+ idata->fp = phar_get_pharfp(phar TSRMLS_CC);
+ idata->phar = phar;
+ idata->internal_file = entry;
+ if (!phar->is_persistent) {
+ ++(entry->phar->refcount);
+ }
+ ++(entry->fp_refcount);
+ php_url_free(resource);
+ if (opened_path) {
+ spprintf(opened_path, MAXPATHLEN, "%s", phar->fname);
+ }
+ efree(internal_file);
+ goto phar_stub;
+ }
+ }
/* read-only access is allowed to magic files in .phar directory */
if ((FAILURE == phar_get_entry_data(&idata, resource->host, host_len, internal_file, strlen(internal_file), "r", 0, &error, 0 TSRMLS_CC)) || !idata) {
+idata_error:
if (error) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, error);
efree(error);
PHAR_G(cwd) = NULL;
}
}
- fpf = php_stream_alloc(&phar_ops, idata, NULL, mode);
if (opened_path) {
spprintf(opened_path, MAXPATHLEN, "phar://%s/%s", idata->phar->fname, idata->internal_file->filename);
}
efree(internal_file);
+phar_stub:
+ fpf = php_stream_alloc(&phar_ops, idata, NULL, mode);
return fpf;
}
/* }}} */
*/
static int phar_stream_close(php_stream *stream, int close_handle TSRMLS_DC) /* {{{ */
{
+ phar_entry_info *entry = ((phar_entry_data *)stream->abstract)->internal_file;
+
phar_entry_delref((phar_entry_data *)stream->abstract TSRMLS_CC);
+ if (entry->is_temp_dir) {
+ /* phar archive stub, free it */
+ efree(entry);
+ }
return 0;
}
/* }}} */
$pname = 'phar://' . $fname;
$file = "<?php
Phar::mapPhar('hio');
+var_dump(__FILE__);
+var_dump(substr(__FILE__, 0, 4) != 'phar');
__HALT_COMPILER(); ?>";
$files = array();
$files['a'] = 'abc';
include 'files/phar_test.inc';
-include $fname;
+include $pname;
$dir = opendir('phar://hio');
?>
--CLEAN--
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
--EXPECTF--
+string(%d) "%s017.phar.php"
+bool(true)
+
Warning: opendir(phar://hio): failed to open dir: phar error: no directory in "phar://hio", must have at least phar://hio/ for root directory (always use full path to a new phar)
phar url "phar://hio" is unknown in %s017.php on line %d
\ No newline at end of file
--FILE--
<?php
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
+$pname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php';
$p = new Phar($fname);
var_dump($p->isFileFormat(Phar::ZIP));
$p['a'] = '<?php include "b/c.php";' . "\n";
$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";';
$p['d'] = "in d\n";
$p->setStub('<?php
+var_dump(__FILE__);
+var_dump(substr(__FILE__, 0, 4) != "phar");
set_include_path("phar://" . __FILE__);
include "phar://" . __FILE__ . "/a";
__HALT_COMPILER();');
-include $fname;
+include $pname;
?>
===DONE===
--CLEAN--
?>
--EXPECTF--
bool(true)
+string(%d) "%sphar_magic.phar.zip.php"
+bool(true)
in b
<?php include "b/c.php";
in d