public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Statistics(SystemTimer::getInstance()); } return self::$instance; }
public static function getInstance() { if (!isset(self::$instance)) { $config = FajrConfigLoader::getConfiguration(); $type = $config->get(FajrConfigOptions::DEBUG_TRACE); $uniqueID = sha1(uniqid('trace', true)); $header = 'Trace (id: ' . $uniqueID . ')'; $tags = array('unique-id' => $uniqueID); if ($type === FajrConfigOptions::DEBUG_TRACE_NONE) { self::$instance = new NullTrace(); } else { if ($type === FajrConfigOptions::DEBUG_TRACE_ARRAY) { self::$instance = new ArrayTrace(SystemTimer::getInstance(), $header); } else { // File-based trace $traceDir = $config->getDirectory(FajrConfigOptions::DEBUG_TRACE_DIR); if ($traceDir === null) { throw new \LogicException(FajrConfigOptions::DEBUG_TRACE_DIR . ' is not set, but is required for file-based traces'); } $ext = $type == FajrConfigOptions::DEBUG_TRACE_TEXT ? 'txt' : 'bin'; $filename = FajrUtils::joinPath($traceDir, 'trace' . $uniqueID . '.' . $ext); $file = @fopen($filename, 'ab'); if ($file === false) { throw new \Exception('Cannot open trace file'); } if ($type == FajrConfigOptions::DEBUG_TRACE_TEXT) { self::$instance = new FileTrace(SystemTimer::getInstance(), $file, 0, $header); } else { self::$instance = new BinaryFileTrace(SystemTimer::getInstance(), $file, $header, $tags); } } } } return self::$instance; }