/** * @ignore */ public function storageReplace($uKey, $uObject, $uDirect = false) { // path $tPath = Io::translatePath($this->path . $uKey, true); if ($uDirect) { Io::write($tPath, $uObject); return; } Io::writeSerialize($tPath, $uObject, $this->keyphase); }
/** * Outputs all parts in single output. * * @returns string Output */ public function output() { $tOutputFile = Io::translatePath('{writable}cache/assets/' . $this->outputName); foreach ($this->classes as $tClassName) { $tOutputFile .= '_' . $tClassName; } $tOutputFile .= '.' . $this->outputType; if (!Framework::$disableCaches && Io::isReadable($tOutputFile, $this->cacheTtl)) { return Io::read($tOutputFile); } $tContent = ""; foreach ($this->parts as $tPart) { if ($tPart['class'] !== null && !in_array($tPart['class'], $this->classes, true)) { continue; } if ($tPart['bindtype'] === 'function') { $tValue = call_user_func($tPart['value'], $tPart); $tDescription = 'function ' . $tPart['value']; } elseif ($tPart['bindtype'] === 'string') { $tValue = $tPart['value']; $tDescription = 'string'; } else { $tValue = Io::read(Io::translatePath($tPart['value'])); $tDescription = 'file ' . $tPart['value']; } if (array_key_exists($tPart['parttype'], self::$fileProcessors)) { $tContent .= call_user_func(self::$fileProcessors[$tPart['parttype']], $tValue, $tDescription); } else { $tContent .= $tValue; } } if (array_key_exists($this->outputType, self::$packProcessors)) { $tContent = call_user_func(self::$packProcessors[$this->outputType], $tContent); } if (!Framework::$readonly) { Io::write($tOutputFile, $tContent); } return $tContent; }
/** * Logs with an arbitrary level. * * @param string $uClass * @param mixed $uLevel * @param array $uContext * @return null */ public static function write($uClass, $uLevel, array $uContext = array()) { if (!isset($uContext['type'])) { $uContext['type'] = $uLevel === LogLevel::DEBUG || $uLevel === LogLevel::INFO ? 'log' : 'error'; } self::$typeCounts[$uContext['type']]++; $uContext['class'] = $uClass; $uContext['category'] = $uLevel; $uContext['ip'] = $_SERVER['REMOTE_ADDR']; if (isset($uContext['message'])) { $uContext['message'] = String::prefixLines($uContext['message'], '- ', PHP_EOL); } if (isset($uContext['file'])) { if (Framework::$development) { $uContext['location'] = Io::extractPath($uContext['file']); if (isset($uContext['line'])) { $uContext['location'] .= ' @' . $uContext['line']; } } else { $uContext['location'] = pathinfo($uContext['file'], PATHINFO_FILENAME); } } else { $uContext['location'] = '-'; } $uContext['stackTrace'] = array(); foreach (array_slice(debug_backtrace(), 2) as $tFrame) { $tArgs = array(); /* if (isset($tFrame['args'])) { foreach ($tFrame['args'] as $tArg) { $tArgs[] = var_export($tArg, true); } } */ if (isset($tFrame['class'])) { $tFunction = $tFrame['class'] . $tFrame['type'] . $tFrame['function']; } else { $tFunction = $tFrame['function']; } if (isset($tFrame['file'])) { if (Framework::$development) { $tLocation = Io::extractPath($tFrame['file']); if (isset($tFrame['line'])) { $tLocation .= ' @' . $tFrame['line']; } } else { $tLocation = pathinfo($tFrame['file'], PATHINFO_FILENAME); } } else { $tLocation = '-'; } $uContext['stackTrace'][] = $tFunction . '(' . implode(', ', $tArgs) . ') in ' . $tLocation; } $uContext['eventDepth'] = Events::$eventDepth; Events::$disabled = true; if (!Framework::$readonly) { $tContent = '+ ' . String::format(Logger::$line, $uContext); $tFilename = Io::translatePath('{writable}logs/' . String::format(Logger::$filename, $uContext), true); Io::write($tFilename, $tContent, LOCK_EX | FILE_APPEND); } self::$console[] = $uContext; Events::$disabled = false; if (isset($uContext['halt']) && $uContext['halt']) { Events::invoke('reportError', $uContext); Framework::end(-1); } }