Exemplo n.º 1
0
 /**
  * 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));
 }
Exemplo n.º 2
0
 /**
  * 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/2.0/en/console-and-shells.html#Shell::createFile
  */
 public function createFile($path, $contents)
 {
     $path = str_replace(DS . DS, DS, $path);
     $this->_io->out();
     if (is_file($path) && empty($this->params['force'])) {
         $this->_io->out(__d('cake_console', '<warning>File `%s` exists</warning>', $path));
         $key = $this->_io->askChoice(__d('cake_console', 'Do you want to overwrite?'), ['y', 'n', 'q'], 'n');
         if (strtolower($key) === 'q') {
             $this->_io->out(__d('cake_console', '<error>Quitting</error>.'), 2);
             return $this->_stop();
         } elseif (strtolower($key) !== 'y') {
             $this->_io->out(__d('cake_console', 'Skip `%s`', $path), 2);
             return false;
         }
     } else {
         $this->out(__d('cake_console', 'Creating file %s', $path));
     }
     $File = new File($path, true);
     if ($File->exists() && $File->writable()) {
         $data = $File->prepare($contents);
         $File->write($data);
         $this->_io->out(__d('cake_console', '<success>Wrote</success> `%s`', $path));
         return true;
     }
     $this->_io->err(__d('cake_console', '<error>Could not write to `%s`</error>.', $path), 2);
     return false;
 }