diff options
author | Greg Beaver <cellog@php.net> | 2007-08-23 04:49:39 +0000 |
---|---|---|
committer | Greg Beaver <cellog@php.net> | 2007-08-23 04:49:39 +0000 |
commit | 0bd0d856737fffe6243955000badde4f240aed73 (patch) | |
tree | f8bf67e8898fae558d5fd818659cf10984a9ad1d | |
parent | 214dbdd8b42d98afbc76d13cc0e10b28b7b3a2b1 (diff) | |
download | php-git-0bd0d856737fffe6243955000badde4f240aed73.tar.gz |
implement Phar->setAlias()
-rw-r--r-- | ext/phar/TODO | 2 | ||||
-rw-r--r-- | ext/phar/package.php | 3 | ||||
-rw-r--r-- | ext/phar/package.xml | 1 | ||||
-rwxr-xr-x | ext/phar/phar_object.c | 33 | ||||
-rw-r--r-- | ext/phar/tests/phar_setalias.phpt | 36 |
5 files changed, 74 insertions, 1 deletions
diff --git a/ext/phar/TODO b/ext/phar/TODO index cde6eadc93..f4c920e146 100644 --- a/ext/phar/TODO +++ b/ext/phar/TODO @@ -54,7 +54,7 @@ Version 1.2.0 Version 1.2.1 X Add Phar::getAlias() [Marcus] - * Add Phar::setAlias() + X Add Phar::setAlias() [Greg] X Make -a optional in pack subcommand of phar.phar [Marcus] X Make Phar::loadPhar() and Phar::mapPhar() ignore extracted archives diff --git a/ext/phar/package.php b/ext/phar/package.php index c9b96e17e7..638a4d6bed 100644 --- a/ext/phar/package.php +++ b/ext/phar/package.php @@ -1,6 +1,9 @@ <?php $notes = ' + * add Phar::setAlias() [Greg] + * fix too many open file handles issue [Greg] + * fix rename [Greg] * add Phar::getAlias() [Marcus] * Made -a optional in pack subcommand of phar.phar [Marcus] * Fix issue with apache module and extracted archives [Marcus] diff --git a/ext/phar/package.xml b/ext/phar/package.xml index 86d5a22366..1b459f334f 100644 --- a/ext/phar/package.xml +++ b/ext/phar/package.xml @@ -154,6 +154,7 @@ avaiable then SHA-256 and SHA-512 signatures are supported as well.</description <file name="phar_oo_compressed_002b.phpt" role="test" /> <file name="phar_oo_test.inc" role="test" /> <file name="phar_oo_uncompressall.phpt" role="test" /> + <file name="phar_setalias.phpt" role="test" /> <file name="phar_setsignaturealgo1.phpt" role="test" /> <file name="phar_setsignaturealgo2.phpt" role="test" /> <file name="phar_stub.phpt" role="test" /> diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index aab5e07fbc..85375441c0 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -300,6 +300,38 @@ PHP_METHOD(Phar, getAlias) } /* }}} */ +/* {{{ proto bool Phar::setAlias(string alias) + * Set the alias for the PHAR + */ +PHP_METHOD(Phar, setAlias) +{ + char *alias, *error; + phar_archive_data *fd, **fd_ptr; + int alias_len; + PHAR_ARCHIVE_OBJECT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &alias, &alias_len) == SUCCESS) { + if (SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_alias_map), phar_obj->arc.archive->alias, phar_obj->arc.archive->alias_len, (void**)&fd_ptr)) { + zend_hash_del(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len); + fd = *fd_ptr; + if (alias && alias_len) { + zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, (void*)&fd, sizeof(phar_archive_data*), NULL); + } + } + + efree(phar_obj->arc.archive->alias); + phar_obj->arc.archive->alias = estrndup(alias, alias_len); + phar_obj->arc.archive->alias_len = alias_len; + phar_flush(phar_obj->arc.archive, NULL, 0, &error TSRMLS_CC); + if (error) { + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, error); + efree(error); + } + RETURN_TRUE; + } + + RETURN_FALSE; +} + /* {{{ proto string Phar::getVersion() * Return version info of Phar archive */ @@ -1418,6 +1450,7 @@ zend_function_entry php_archive_methods[] = { PHP_ME(Phar, getVersion, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, isBuffering, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, hasMetadata, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phar, setAlias, arginfo_phar_mapPhar, ZEND_ACC_PUBLIC) PHP_ME(Phar, setMetadata, arginfo_entry_setMetadata, ZEND_ACC_PUBLIC) PHP_ME(Phar, setStub, arginfo_phar_setStub, ZEND_ACC_PUBLIC) PHP_ME(Phar, setSignatureAlgorithm, arginfo_entry_setMetadata, ZEND_ACC_PUBLIC) diff --git a/ext/phar/tests/phar_setalias.phpt b/ext/phar/tests/phar_setalias.phpt new file mode 100644 index 0000000000..1132484b47 --- /dev/null +++ b/ext/phar/tests/phar_setalias.phpt @@ -0,0 +1,36 @@ +--TEST-- +Phar::setAlias() +--SKIPIF-- +<?php if (!extension_loaded("phar")) print "skip"; ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$file = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>'; + +$files = array(); +$files['a'] = 'a'; +$files['b'] = 'b'; +$files['c'] = 'c'; + +include 'phar_test.inc'; + +$phar = new Phar($fname); +echo $phar->getAlias() . "\n"; +$phar->setAlias('test'); +echo $phar->getAlias() . "\n"; +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php'); +__HALT_COMPILER(); +?> +--EXPECT-- +hio +test +===DONE=== |