當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::prepare方法代碼示例

本文整理匯總了PHP中Cake\Filesystem\File::prepare方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::prepare方法的具體用法?PHP File::prepare怎麽用?PHP File::prepare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Filesystem\File的用法示例。


在下文中一共展示了File::prepare方法的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: testPrepare

 /**
  * testPrepare method
  *
  * @return void
  */
 public function testPrepare()
 {
     $string = "some\nvery\ncool\r\nteststring here\n\n\nfor\r\r\n\n\r\n\nhere";
     if (DS === '\\') {
         $expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
         $expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
     } else {
         $expected = "some\nvery\ncool\nteststring here\n\n\nfor\n\n\n\n\nhere";
     }
     $this->assertSame($expected, File::prepare($string));
     $expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n";
     $expected .= "for\r\n\r\n\r\n\r\n\r\nhere";
     $this->assertSame($expected, File::prepare($string, true));
 }
開發者ID:Slayug,項目名稱:castor,代碼行數:19,代碼來源:FileTest.php


注:本文中的Cake\Filesystem\File::prepare方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。