本文整理汇总了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 . '".');
}
}