}
/* }}} */
+/* {{{ proto string PharFileInfo::getContents()
+ * return the complete file contents of the entry (like file_get_contents)
+ */
+PHP_METHOD(PharFileInfo, getContents)
+{
+ char *error;
+ php_stream *fp;
+ PHAR_ENTRY_OBJECT();
+
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Phar error: Cannot retrieve contents, \"%s\" in phar \"%s\" is a directory", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname);
+ return;
+ }
+ if (SUCCESS != phar_open_entry_fp(entry_obj->ent.entry, &error TSRMLS_CC)) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Phar error: Cannot retrieve contents, \"%s\" in phar \"%s\": %s", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname, error);
+ efree(error);
+ return;
+ }
+ if (!(fp = phar_get_efp(entry_obj->ent.entry TSRMLS_CC))) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
+ "Phar error: Cannot retrieve contents of \"%s\" in phar \"%s\"", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname);
+ return;
+ }
+ phar_seek_efp(entry_obj->ent.entry, 0, SEEK_SET, 0 TSRMLS_CC);
+ Z_TYPE_P(return_value) = IS_STRING;
+ Z_STRLEN_P(return_value) = php_stream_copy_to_mem(fp, &(Z_STRVAL_P(return_value)), entry_obj->ent.entry->uncompressed_filesize, 0);
+}
+/* }}} */
+
/* {{{ proto int PharFileInfo::setCompressedGZ()
* Instructs the Phar class to compress the current file using zlib
*/
PHP_ME(PharFileInfo, __destruct, NULL, 0)
PHP_ME(PharFileInfo, chmod, arginfo_entry_chmod, 0)
PHP_ME(PharFileInfo, delMetadata, NULL, 0)
+ PHP_ME(PharFileInfo, getContents, NULL, 0)
PHP_ME(PharFileInfo, getCompressedSize, NULL, 0)
PHP_ME(PharFileInfo, getCRC32, NULL, 0)
PHP_ME(PharFileInfo, getMetadata, NULL, 0)
--- /dev/null
+--TEST--
+Phar object: getContents()
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+
+$phar = new Phar($fname);
+$phar['a'] = 'file contents
+this works';
+echo $phar['a']->getContents() . "\n";
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+file contents
+this works
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+Phar object: getContents() (verify it works with compression)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.phar.php';
+
+$phar = new Phar($fname);
+$phar['a'] = 'file contents
+this works';
+$phar['a']->setCompressedGZ();
+copy($fname, $fname2);
+$phar2 = new Phar($fname2);
+var_dump($phar2['a']->isCompressed());
+echo $phar2['a']->getContents() . "\n";
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.phar.php');
+__halt_compiler();
+?>
+--EXPECT--
+bool(true)
+file contents
+this works
+===DONE===
\ No newline at end of file