コード例 #1
0
ファイル: UnloadTask.php プロジェクト: coretyson/coretyson
 /**
  * Update the applications plugins.php file.
  *
  * @param string $plugin Name of plugin.
  * @return bool If modify passed.
  */
 protected function _modifyBootstrap($plugin)
 {
     $finder = "/\nPluginLoader::load\\((.|.\n|\n\\s\\s|\n\t|)+'{$plugin}'(.|.\n|)+\\);\n/";
     $plugins = new File($this->_pluginsFile, false);
     $contents = $plugins->read();
     if (!preg_match("@\n\\s*nPluginLoader::loadAll@", $contents)) {
         $contents = preg_replace($finder, "", $contents);
         $plugins->write($contents);
         $this->out('');
         $this->out(sprintf('%s modified', $this->_pluginsFile));
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: FileTest.php プロジェクト: coretyson/coretyson
 /**
  * testWrite method
  *
  * @return bool|void
  */
 public function testWrite()
 {
     if (!($tmpFile = $this->_getTmpFile())) {
         return false;
     }
     if (file_exists($tmpFile)) {
         unlink($tmpFile);
     }
     $TmpFile = new File($tmpFile);
     $this->assertFalse(file_exists($tmpFile));
     $this->assertFalse(is_resource($TmpFile->fileHandle()));
     $testData = ['CakePHP\'s', ' test suite', ' was here ...', ''];
     foreach ($testData as $data) {
         $r = $TmpFile->write($data);
         $this->assertTrue($r);
         $this->assertTrue(file_exists($tmpFile));
         $this->assertEquals($data, file_get_contents($tmpFile));
         $this->assertTrue(is_resource($TmpFile->fileHandle()));
         $TmpFile->close();
     }
     unlink($tmpFile);
 }
コード例 #3
0
ファイル: FileEngine.php プロジェクト: coretyson/coretyson
 /**
  * Rotate log file if size specified in config is reached.
  * Also if `rotate` count is reached oldest file is removed.
  *
  * @return mixed True if rotated successfully or false in case of error.
  *   Void if file doesn't need to be rotated.
  */
 protected function _rotateLines()
 {
     $filepath = $this->_path . $this->_file;
     $file = new File($filepath);
     $fileContent = $file->read();
     $fileLines = explode(PHP_EOL, $fileContent);
     if (!$file->exists() and count($fileLines) < $this->_maxLine) {
         return;
     }
     while (count($fileLines) >= $this->_maxLine) {
         array_shift($fileLines);
     }
     return $file->write(implode(PHP_EOL, $fileLines));
 }