Browse Source

- Split commit into commit and setStub

migration/RELEASE_1_0_0
Marcus Boerger 20 years ago
parent
commit
0bc1b90ec3
  1. 64
      ext/phar/phar_object.c
  2. 4
      ext/phar/tests/phar_commitwrite.phpt
  3. 2
      ext/phar/tests/phar_create_in_cwd.phpt
  4. 6
      ext/phar/tests/phar_stub.phpt
  5. 7
      ext/phar/tests/phar_stub_write.phpt

64
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)

4
ext/phar/tests/phar_commitwrite.phpt

@ -1,5 +1,5 @@
--TEST--
Phar::commit()
Phar::setStub()/commit()
--SKIPIF--
<?php if (!extension_loaded("phar")) print "skip"; ?>
--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("<?php
$p->setStub("<?php
function __autoload(\$class)
{
include 'phar://' . str_replace('_', '/', \$class);

2
ext/phar/tests/phar_create_in_cwd.phpt

@ -12,7 +12,7 @@ $p = new Phar('brandnewphar.phar');
$p['file1.txt'] = 'hi';
$p->commit();
var_dump($p->getStub());
$p->commit("<?php
$p->setStub("<?php
function __autoload(\$class)
{
include 'phar://' . str_replace('_', '/', \$class);

6
ext/phar/tests/phar_stub.phpt

@ -27,7 +27,7 @@ $phar = new Phar($fname);
$file = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
//// 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');

7
ext/phar/tests/phar_stub_write.phpt

@ -25,7 +25,10 @@ var_dump($phar->getStub());
var_dump($phar->getStub() == $stub);
$stub = '<?php echo "second stub\n"; __HALT_COMPILER(); ?>';
$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) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>"
bool(true)
string(49) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>"
bool(true)
string(49) "<?php echo "second stub\n"; __HALT_COMPILER(); ?>"
bool(true)
bool(true)
===DONE===
Loading…
Cancel
Save