From: Marcus Boerger Date: Sun, 28 Jan 2007 22:11:28 +0000 (+0000) Subject: - Split commit into commit and setStub X-Git-Tag: RELEASE_1_0_0RC1~82 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0bc1b90ec354a4a74fbc2b6806a565a5b823fd1a;p=php - Split commit into commit and setStub --- diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 7a41917307..761f476c85 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -210,15 +210,11 @@ PHP_METHOD(Phar, begin) } /* }}} */ -/* {{{ proto bool Phar::commit([string|stream stub [, int len]]) - * Save the contents of a modified phar, with an optional change to the stub +/* {{{ proto bool Phar::commit() + * Save the contents of a modified phar */ PHP_METHOD(Phar, commit) { - zval *stub = NULL; - long len = -1; - php_stream *stream; -/* phar_archive_data *temp;*/ PHAR_ARCHIVE_OBJECT(); if (PHAR_G(readonly)) { @@ -226,26 +222,48 @@ PHP_METHOD(Phar, commit) "Cannot write out phar archive, phar is read-only"); } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zl", &stub, &len) == FAILURE) { - return; - } - phar_obj->arc.archive->donotflush = 0; - if (stub && Z_TYPE_P(stub) == IS_STRING) { - phar_flush(phar_obj->arc.archive, Z_STRVAL_P(stub), Z_STRLEN_P(stub) TSRMLS_CC); - } else if (stub && Z_TYPE_P(stub) == IS_RESOURCE && (php_stream_from_zval_no_verify(stream, &stub))) { - if (len > 0) { - len = -len; + phar_flush(phar_obj->arc.archive, 0, 0 TSRMLS_CC); +} +/* }}} */ + +/* {{{ proto bool Phar::setStub(string|stream stub [, int len]) + * Change the stub of the archive + */ +PHP_METHOD(Phar, setStub) +{ + zval *zstub; + char *stub; + int stub_len; + long len = -1; + php_stream *stream; + PHAR_ARCHIVE_OBJECT(); + + if (PHAR_G(readonly)) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "Cannot change stub, phar is read-only"); + } + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zstub, &len) == SUCCESS) { + if ((php_stream_from_zval_no_verify(stream, &zstub)) != NULL) { + if (len > 0) { + len = -len; + } else { + len = -1; + } + phar_flush(phar_obj->arc.archive, (char *) &zstub, len TSRMLS_CC); + RETURN_TRUE; } else { - len = -1; + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "Cannot change stub, unable to read from input stream"); } - phar_flush(phar_obj->arc.archive, (char *) &stub, len TSRMLS_CC); - } else { - phar_flush(phar_obj->arc.archive, 0, 0 TSRMLS_CC); + } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stub, &stub_len) == SUCCESS) { + phar_flush(phar_obj->arc.archive, stub, stub_len TSRMLS_CC); + RETURN_TRUE; } - - RETURN_TRUE; + + RETURN_FALSE; } /* }}} */ @@ -924,6 +942,7 @@ ZEND_END_ARG_INFO(); static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_setStub, 0, 0, 1) ZEND_ARG_INFO(0, newstub) + ZEND_ARG_INFO(0, maxlen) ZEND_END_ARG_INFO(); static @@ -954,12 +973,13 @@ zend_function_entry php_archive_methods[] = { PHP_ME(Phar, getModified, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, getSignature, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, getStub, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phar, setStub, arginfo_phar_setStub, ZEND_ACC_PUBLIC) PHP_ME(Phar, getVersion, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, begin, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, compressAllFilesGZ, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, compressAllFilesBZIP2, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, uncompressAllFiles, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Phar, commit, arginfo_phar_setStub, ZEND_ACC_PUBLIC) + PHP_ME(Phar, commit, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phar, offsetExists, arginfo_phar_offsetExists, ZEND_ACC_PUBLIC) PHP_ME(Phar, offsetGet, arginfo_phar_offsetExists, ZEND_ACC_PUBLIC) PHP_ME(Phar, offsetSet, arginfo_phar_offsetSet, ZEND_ACC_PUBLIC) diff --git a/ext/phar/tests/phar_commitwrite.phpt b/ext/phar/tests/phar_commitwrite.phpt index 7acfdec1a3..9e14e6067a 100644 --- a/ext/phar/tests/phar_commitwrite.phpt +++ b/ext/phar/tests/phar_commitwrite.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar::commit() +Phar::setStub()/commit() --SKIPIF-- --INI-- @@ -11,7 +11,7 @@ $p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar'); $p['file1.txt'] = 'hi'; $p->commit(); var_dump($p->getStub()); -$p->commit("setStub("commit(); var_dump($p->getStub()); -$p->commit("setStub("'; //// 2 -$phar->commit($file); +$phar->setStub($file); $fp = fopen($fname, 'rb'); echo fread($fp, strlen($file)) . "\n"; fclose($fp); @@ -40,7 +40,7 @@ fclose($fp); $fp = fopen($fname2, 'rb'); //// 3 -$phar->commit($fp); +$phar->setStub($fp); fclose($fp); $fp = fopen($fname, 'rb'); @@ -55,7 +55,7 @@ echo file_get_contents($fname2) . "\n"; $fp = fopen($fname2, 'rb'); //// 4 -$phar->commit($fp, strlen($file)); +$phar->setStub($fp, strlen($file)); fclose($fp); $fp = fopen($fname, 'rb'); diff --git a/ext/phar/tests/phar_stub_write.phpt b/ext/phar/tests/phar_stub_write.phpt index ed49cd0e20..56352564c8 100755 --- a/ext/phar/tests/phar_stub_write.phpt +++ b/ext/phar/tests/phar_stub_write.phpt @@ -25,7 +25,10 @@ var_dump($phar->getStub()); var_dump($phar->getStub() == $stub); $stub = ''; -$phar->commit($stub); +$phar->setStub($stub); +var_dump($phar->getStub()); +var_dump($phar->getStub() == $stub); +$phar->commit(); var_dump($phar->getStub()); var_dump($phar->getStub() == $stub); @@ -45,5 +48,7 @@ string(48) "" bool(true) string(49) "" bool(true) +string(49) "" +bool(true) bool(true) ===DONE===