]> granicus.if.org Git - php/commitdiff
- Split commit into commit and setStub
authorMarcus Boerger <helly@php.net>
Sun, 28 Jan 2007 22:11:28 +0000 (22:11 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 28 Jan 2007 22:11:28 +0000 (22:11 +0000)
ext/phar/phar_object.c
ext/phar/tests/phar_commitwrite.phpt
ext/phar/tests/phar_create_in_cwd.phpt
ext/phar/tests/phar_stub.phpt
ext/phar/tests/phar_stub_write.phpt

index 7a419173070ff162ade0263546237f50113d2735..761f476c85a94b814741d7d1f72838472399bfc2 100755 (executable)
@@ -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)
index 7acfdec1a3925177c57121f185b21890eaa9daf9..9e14e6067a2141b04e3bfa3e25b668725da657d6 100644 (file)
@@ -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);
index 682bf71fad40b3af6846ed11a1545aa16c8835da..aed04c68df4831d6da4281f341292c93ca15ecec 100644 (file)
@@ -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);
index 1b4e1cb85e70884e7c8f456ae2b901427d61c3d4..3cf514b8362295072f6d4a4d28c697452583350d 100644 (file)
@@ -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');
index ed49cd0e20cf4aeada27552c742939e278c73009..56352564c898c5235ca0185198ecf62c86380850 100755 (executable)
@@ -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===