]> granicus.if.org Git - php/commitdiff
implement Phar->setAlias()
authorGreg Beaver <cellog@php.net>
Thu, 23 Aug 2007 04:49:39 +0000 (04:49 +0000)
committerGreg Beaver <cellog@php.net>
Thu, 23 Aug 2007 04:49:39 +0000 (04:49 +0000)
ext/phar/TODO
ext/phar/package.php
ext/phar/package.xml
ext/phar/phar_object.c
ext/phar/tests/phar_setalias.phpt [new file with mode: 0644]

index cde6eadc933b2429ca33d1ac5c47c7e8de463957..f4c920e14660ac85474b6b1a91677419a385523d 100644 (file)
@@ -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
 
index c9b96e17e7f9d5d46b7fc192b9e1f34da23c468e..638a4d6bed1e19351481d44700e326cf0bc5d0b5 100644 (file)
@@ -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]
index 86d5a22366a75723d6b638d95e9c8979a409b2c7..1b459f334f905aa1b8494f3d0a280b215725257f 100644 (file)
@@ -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" />
index aab5e07fbc459b7d3a51fcc5e297db17b0e77b2c..85375441c07495a87e0f09d1c788bb79eff98a92 100755 (executable)
@@ -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 (file)
index 0000000..1132484
--- /dev/null
@@ -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===