本文整理汇总了PHP中Phar::isWritable方法的典型用法代码示例。如果您正苦于以下问题:PHP Phar::isWritable方法的具体用法?PHP Phar::isWritable怎么用?PHP Phar::isWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phar
的用法示例。
在下文中一共展示了Phar::isWritable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compress
/**
* 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();
}
示例2: __construct
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;
}
示例3: Phar
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===
示例4: Phar
$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";
}