/** * Implements writing to log files. * * @param mixed $level The severity level of the message being written. * @param string $message The message you want to log. * @param array $context * @return bool success of write */ public function log($level, $message, array $context = array()) { $message = $this->_format($message); $output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message . "\n"; if (!empty($this->_size)) { $this->_rotateLines(); } $filename = $this->_path . $this->_file; $file = new File($filename); return $file->append($output); }
/** * Update the applications plugins.php file. * * @param string $plugin Name of plugin. * @param bool $hasBootstrap Whether or not bootstrap should be loaded. * @param bool $hasRoutes Whether or not routes should be loaded. * @param bool $hasAutoloader Whether or not there is an autoloader configured for * the plugin. * @return bool If modify passed. */ protected function _modifyBootstrap($plugin, $hasBootstrap, $hasRoutes, $hasAutoloader) { $bootstrap = new File($this->_pluginsFile, false); $contents = $bootstrap->read(); if (!preg_match("@\n\\s*PluginLoader::loadAll@", $contents)) { $autoloadString = $hasAutoloader ? "'autoload' => true" : ''; $bootstrapString = $hasBootstrap ? "'bootstrap' => true" : ''; $routesString = $hasRoutes ? "'routes' => true" : ''; $append = "\\PluginLoader::load('%s', [%s]);\n"; $options = implode(', ', array_filter([$autoloadString, $bootstrapString, $routesString])); $bootstrap->append(str_replace(', []', '', sprintf($append, $plugin, $options))); $this->out(''); $this->out(sprintf('%s modified', $this->_pluginsFile)); return true; } return false; }
/** * testAppend method * * @return void */ public function testAppend() { if (!($tmpFile = $this->_getTmpFile())) { return false; } if (file_exists($tmpFile)) { unlink($tmpFile); } $TmpFile = new File($tmpFile); $this->assertFalse(file_exists($tmpFile)); $fragments = ['CoreTyson\'s', ' test suite', ' was here ...']; $data = null; $size = 0; foreach ($fragments as $fragment) { $r = $TmpFile->append($fragment); $this->assertTrue($r); $this->assertTrue(file_exists($tmpFile)); $data = $data . $fragment; $this->assertEquals($data, file_get_contents($tmpFile)); $TmpFileInfo = new FileInfo($TmpFile); $newSize = $TmpFileInfo->size(); $this->assertTrue($newSize > $size); $size = $newSize; $TmpFile->close(); } $TmpFile->append(''); $this->assertEquals($data, file_get_contents($tmpFile)); $TmpFile->close(); }