/** * Compresses a file or combination of files in the archive * @param array|zibo\library\filesystem\File $source File objects of the files to compress * @param zibo\library\filesystem\File $prefix The path for the files in the archive * @return null * @throws zibo\library\archive\exception\ArchiveException when no source or an invalid source has been provided * @throws zibo\library\archive\exception\ArchiveException when the archive could not be created * @throws zibo\library\archive\exception\ArchiveException when the phars could not be written due to the configuration of PHP */ public function compress($source, File $prefix = null) { if (!PhpPhar::canWrite()) { throw new ArchiveException('Phar library is not allowed to write phars. Check the PHP configuration for the phar.readonly setting.'); } if (empty($source)) { throw new ArchiveException('No files provided'); } $path = $this->file->getAbsolutePath(); $parent = $this->file->getParent(); $parent->create(); if (!is_array($source)) { $source = array($source); } try { $phar = new PhpPhar($path); } catch (UnexpectedValueException $e) { throw new ArchiveException('Could not open ' . $path); } if (!$phar->isWritable()) { throw new ArchiveException('Archive ' . $this->file->getAbsolutePath() . ' is not writable'); } $phar->startBuffering(); foreach ($source as $file) { if (!$file instanceof File) { throw new ArchiveException('Invalid source provided: ' . $file); } $this->compressFile($phar, $file, $prefix); } $phar->stopBuffering(); }
public function __construct($file, $flags = 0) { $this->name = $file; $this->file = __DIR__ . '/' . $file; $p = new Phar($this->file, Phar::CURRENT_AS_FILEINFO, $file); if (!$p->isWritable()) { throw new Exception("hoge"); } $p->startBuffering(); $this->driver = $p; }
var_dump($a['a.php']->isWritable()); var_dump($a['a.php']->isReadable()); ini_set('phar.readonly', 1); clearstatcache(); var_dump($a['a.php']->isWritable()); var_dump($a['a.php']->isReadable()); ini_set('phar.readonly', 0); clearstatcache(); var_dump($a['a.php']->isWritable()); var_dump($a['a.php']->isReadable()); ?> archive <?php ini_set('phar.readonly', 0); $p = new Phar('doesnotexisthere.phar'); var_dump($p->isWritable()); clearstatcache(); var_dump($a->isWritable()); var_dump($b->isWritable()); ini_set('phar.readonly', 1); clearstatcache(); var_dump($a->isWritable()); var_dump($b->isWritable()); chmod($fname2, 00); clearstatcache(); var_dump($a->isWritable()); var_dump($b->isWritable()); chmod($fname2, 0666); ?> ===DONE===
$file = $argv[2]; } else { $file = $argv[2] . ".phar"; } if (file_exists($file)) { try { $phar = new Phar($file, 0); if ($phar->hasMetadata()) { $metadata = metadataToString($phar->getMetadata()); } else { $metadata = "No metadata found\n"; } echo "Size: " . round(filesize($file) * 0.0009765625 * 0.0009765625, 2) . " MB (" . round(filesize($file) * 0.0009765625, 3) . " KB)\n"; echo "Signature: " . $phar->getSignature()["hash"] . "\n"; echo "Signature type: " . $phar->getSignature()["hash_type"] . "\n"; echo "Writable: " . strbool($phar->isWritable()) . "\n"; echo "Readable: " . strbool($phar->isReadable()) . "\n"; echo "Metadata: " . $metadata; echo "Show stub (y, n)? "; $input = fopen("php://stdin", "r"); $line = fgets($input); if (trim($line) == 'y') { echo $phar->getStub(); } echo "\n"; } catch (Exception $e) { echo "Invalid phar file\n"; } } else { echo "File not found\n"; }