本文整理匯總了PHP中SplFileObject::isWritable方法的典型用法代碼示例。如果您正苦於以下問題:PHP SplFileObject::isWritable方法的具體用法?PHP SplFileObject::isWritable怎麽用?PHP SplFileObject::isWritable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::isWritable方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __destruct
/**
* Saves the current connection to `$this->file` if set.
*/
public function __destruct()
{
if (isset($this->file) && $this->file->isWritable()) {
$this->file->ftruncate(0);
$this->file->rewind();
$this->file->fwrite($this->toJson());
}
}
示例2: testInit
/**
* @return void
*/
public function testInit()
{
$filePath = __DIR__ . '/example_write1.txt';
$fileObject = new FileWriter($filePath);
$this->assertEquals($filePath, $fileObject->getPathname());
$this->assertTrue($fileObject->isWritable());
$filePath = __DIR__ . '/example_write2.txt';
$fileObject = new \SplFileObject($filePath, 'r+');
$this->assertEquals($filePath, $fileObject->getPathname());
$this->assertTrue($fileObject->isWritable());
}
示例3: write
public function write($filename = null, Config $config = null, $exclusiveLock = null)
{
if (null !== $filename) {
$this->setFilename($filename);
}
if (null !== $config) {
$this->setConfig($config);
}
if (null !== $exclusiveLock) {
$this->setExclusiveLock($exclusiveLock);
}
if (null === $this->_filename) {
require_once '/Exception/Exception.php';
throw new MPFConfigException("沒有設置文件名");
}
if (null === $this->_filename) {
require_once 'MPF/Core/Config/Exception.php';
throw new MPFConfigException("沒有設置配置");
}
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
$arrayString = "<?php\n" . "return " . var_export($data, true) . ";\n";
$flags = 0;
if ($this->_exclusiveLock) {
$flags |= LOCK_EX;
}
$file = new SplFileObject($this->_filename, 'w+');
$file->setFlags($flags);
if ($file->isWritable()) {
$result = $file->fwrite($arrayString);
} else {
require_once 'MPF/Core/Config/Exception.php';
throw new MPFConfigException("文件不可寫");
}
return $result;
}
示例4: create
public static function create($file, $data, $has_clumn_name = false)
{
touch($file);
$file = new SplFileObject($file, 'w');
if (count($data) > 0 && !$file->isWritable()) {
delete($file);
return false;
}
if ($has_clumn_name) {
$file->fputcsv(array_keys($data[0]));
}
foreach ($data as $line) {
$file->fputcsv($line);
}
return true;
}
示例5: bindRspecTearDown
/**
* Build RSpec teardown
* @TODO: Complete function comment
*
* @param SplFileObject $rspecFileObj The file object of the test suite
*
* @throws {BadMethodCallException} If the $rspecFileObj param, wich is an SplFileObject object, stands for a non writable file.
*
* @return Void
*/
public function bindRspecTearDown($rspecFileObj)
{
if ($rspecFileObj->isWritable()) {
$content = " after(:all) do\n";
$content .= " @valid.teardown()\n";
$content .= " end\n\n";
$rspecFileObj->fwrite($content);
} else {
throw new BadMethodCallException('Something went wrong when trying to write to test suite file "' . $this->_testSuiteFile . '".');
}
}