当前位置: 首页>>代码示例>>PHP>>正文


PHP File::writable方法代码示例

本文整理汇总了PHP中Cake\Filesystem\File::writable方法的典型用法代码示例。如果您正苦于以下问题:PHP File::writable方法的具体用法?PHP File::writable怎么用?PHP File::writable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Filesystem\File的用法示例。


在下文中一共展示了File::writable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createFile

 /**
  * Creates a file at given path
  *
  * @param string $path Where to put the file.
  * @param string $contents Content to put in the file.
  * @return bool Success
  * @link http://book.cakephp.org/3.0/en/console-and-shells.html#creating-files
  */
 public function createFile($path, $contents)
 {
     $path = str_replace(DS . DS, DS, $path);
     $this->_io->out();
     if (is_file($path) && empty($this->params['force']) && $this->interactive) {
         $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path));
         $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'a', 'q'], 'n');
         if (strtolower($key) === 'q') {
             $this->_io->out('<error>Quitting</error>.', 2);
             return $this->_stop();
         }
         if (strtolower($key) === 'a') {
             $this->params['force'] = true;
             $key = 'y';
         }
         if (strtolower($key) !== 'y') {
             $this->_io->out(sprintf('Skip `%s`', $path), 2);
             return false;
         }
     } else {
         $this->out(sprintf('Creating file %s', $path));
     }
     $File = new File($path, true);
     if ($File->exists() && $File->writable()) {
         $data = $File->prepare($contents);
         $File->write($data);
         $this->_io->out(sprintf('<success>Wrote</success> `%s`', $path));
         return true;
     }
     $this->_io->err(sprintf('<error>Could not write to `%s`</error>.', $path), 2);
     return false;
 }
开发者ID:a53ali,项目名称:CakePhP,代码行数:40,代码来源:Shell.php

示例2: testWritable

 /**
  * testWritable method
  *
  * @return void
  */
 public function testWritable()
 {
     $someFile = new File(TMP . 'some_file.txt', false);
     $this->assertTrue($someFile->open());
     $this->assertTrue($someFile->writable());
     $someFile->close();
     $someFile->delete();
 }
开发者ID:Slayug,项目名称:castor,代码行数:13,代码来源:FileTest.php


注:本文中的Cake\Filesystem\File::writable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。