/** * Gathers informations about Server, execution environment, occured errors * and creates log files */ public function createLogFile() { $logDir = Conf::get('logFileDir'); if (is_writable($logDir) && Conf::get('createLogFile')) { $logDisplayArray = $this->loadLogDisplay(); $header = "ignaszak/exception - https://github.com/ignaszak/\n" . sprintf("%-17.17s %s", "Date:", date('F d Y H:i:s')) . "\n" . sprintf("%-17.17s %s", "Reported errors:", $logDisplayArray['errorsCount']); $globalVars = Variable::getFormatedServerDataAsString(); $content = strip_tags("{$header}\n\n\n{$globalVars}\n\n\n{$logDisplayArray['errors']}"); $fileName = date('Y_m_d_H_i_s_u', time()) . '.log'; file_put_contents("{$logDir}/{$fileName}", $content); chmod("{$logDir}/{$fileName}", 0664); } }
/** * @return string */ private function getServerData() : string { return str_replace("\n", "<br>", str_replace(" ", " ", Variable::getFormatedServerDataAsString())); }
public function testFormatVariableType() { $formatVariableType = array(Variable::formatVariableType(1), Variable::formatVariableType('string', "'"), Variable::formatVariableType(array(1 => 1, 2 => 2)), Variable::formatVariableType(new \Exception('test')), Variable::formatVariableType(fopen(__FILE__, "r"))); $array = array(1, '\'string\'', print_r(array(1 => 1, 2 => 2), true), '(object) Exception', '(resource) stream'); $this->assertEquals($array, $formatVariableType); }
/** * Returns formated arguments as string * * @param mixed $args * @return string */ private function getFunctionArgs($args) : string { if (!is_array($args)) { $args = array($args); } $array = array(); foreach ($args as $value) { $array[] = Variable::formatVariableType(@$value, "'"); } return implode(', ', $array); }
public function testUnknownType() { $f = fopen(MockTest::mockFile('anyFile'), 'r'); fclose($f); $this->assertEquals('unknown type', Variable::formatVariableType($f)); }