@param string|array $file
@param int $time
@param bool $debugMode

@return string
762938
public static function computeHash($file, $time, $debugMode)
	{
		$debug = $debugMode ? 1 : 0;
		$file = is_array($file) ? implode(',', $file) : $file;
		$md5Raw = md5("$debug;$file;$time", TRUE);
		$base64 = Strings::replace(base64_encode($md5Raw), '~\W~');

		return Strings::substring(Strings::webalize($base64), 0, 8);
	}
609705
protected static function __formatMessage( array $error, $template = null ) {
    static $patterns = [
      '~\:\:time~us',
      '~\:\:microtime~us',
      '~\:\:class~us',
      '~\:\:code~us',
      '~\:\:message~us',
    ];
    if( empty( $error ['time'] )) $error ['time'] = microtime( true );
    if( empty( $error ['class'] )) $error ['class'] = __NAMESPACE__ .'\DeferredExceptionsException';
    if( empty( $error ['code'] )) $error ['code'] = 0;
    if( empty( $error ['message'] )) $error ['message'] = '';

    $time= [];
    preg_match('~(\d*)(\.(\d{0,6}))?~', $error ['time'], $time);
    $sec =  (int) $time [1];
    $usec = sprintf( '%0-6s', isset( $time [3]) ? (int) $time [3] : 0);

    $replaces = [
      date('Y-m-d H:i:s', $sec),
      date('Y-m-d H:i:s', $sec) . ':' . $usec,
      $error ['class'],
      $error ['code'],
      $error ['message'],
    ];

    return preg_replace(
        $patterns, $replaces,
        ! empty( $template ) && is_string( $template )
          ? $template
          : DeferredExceptionsGlobal::$defExcDefaultErrorListTemplate
    );
  }
1325918
private function saveFile($file, $content, $time)
    {
        // create directory if not exists
        if (!is_dir($dir = dirname($file))) {
            // @codeCoverageIgnoreStart
            if (!make_dir($dir, 0775)) {
                throw new RuntimeException(sprintf('View Template Engine was not able to create directory "%s"', $dir)); // @codeCoverageIgnore
            }
            // @codeCoverageIgnoreEnd
        } // @codeCoverageIgnore

        // save file
        if (file_exists($file)) {
            unlink($file); // so we will to be the owner at the new file
        }

        if (file_put_contents($file, $content, LOCK_EX) === false) {
            throw new RuntimeException(sprintf('View Template Engine was not able to save file "%s"', $file)); // @codeCoverageIgnore
        }

        @chmod($file, 0664);

        // set file modification time
        if (!@touch($file, $time)) {
            throw new RuntimeException(sprintf('View Template Engine was not able to modify time of file "%s"', $file)); // @codeCoverageIgnore
        }
    }
274208
public function getCreatedTime($file)
    {
        $this->temporaryFileManager->enterModule('Templating');

        $fileInfo = $this->temporaryFileManager->getFileInfo($file . '.php');
        if (!$fileInfo->isFile()) {
            return 0;
        }

        $this->temporaryFileManager->exitModule();

        return $fileInfo->getMTime();
    }
103141
public function validateDynamicPattern($path, &$debugInformation)
    {
        if (empty($this->pattern)) {
            return false;
        }

        $value = $this->pattern->testPattern($path, $this->parameters, $debugInformation);

        $this->validatedData = $this->pattern->getValidatedData();

        return $value;
    }
110296
public function getValuesFromFile($file, $failOnMissing = true)
    {
        $result = [];

        if (!FileSystem::isFileReadable($file)) {
            if ($failOnMissing) {
                throw new RuntimeException("Path [$file] is not a readable file");
            }
            return $result;
        }

        $file = file($file);
        if (empty($file)) {
            return $result;
        }

        foreach ($file as $line) {
            $line = trim($line);
            if (!preg_match('#^(.*)?=(.*)?$#', $line, $matches)) {
                continue;
            }
            $result[$matches[1]] = $matches[2];
        }

        return $result;
    }
152886
public function touch($file, $time = null)
    {
        global $php_errormsg;

        if (null === $time) {
            $error = @touch($file);
        } else {
            $error = @touch($file, $time);
        }

        if (false === $error) { // FAILED.
            // Add error from php to end of log message. $php_errormsg.
            $msg = "FileSystem::touch() FAILED. Cannot touch '$file'. $php_errormsg";
            throw new Exception($msg);
        }
    }
491627
public static function convert(float $time, string $unit, string $destUnit, string $mode)
    {
        self::validateMode($mode);

        if ($mode === self::MODE_TIME) {
            return self::convertTo($time, $unit, $destUnit);
        }

        return self::convertInto($time, $unit, $destUnit);
    }
208550
public function debugLog($message)
  {
    if($this->DebugAddTime){
      // adding datetime to message (useful when DebugMethod=='echoplain')
      if($this->DebugMultiLine){
        // multiline is enabled, so add the time for each line in the $message
        $message_changed='';
        foreach(explode("\n",$message) as $sub_msg){
          if($message_changed!==''){
            // only add a newline for each newline we lost due to the explode
            $message_changed.="\n";
          }
          $message_changed.=date("Y-m-d H:i:s ").$sub_msg;
        }
        $message=$message_changed;
      }else{
        $message=date("Y-m-d H:i:s ").$message;
      }
    }
    if($this->DebugMethod=='error_log'){
      // error_log entries are automatically truncated at ~8130 chars.
      // by default the message is displayed as one single line where newlines are replaced by literal \n
      // in fact, all non ascii characters are replaced by escaped values (often \xnn)
      // we support two config settings to change this behaviour: error_log_multiline, error_log_wrap
      // both are enabled by default
      if($this->DebugMultiLine){
        foreach(explode("\n",$message) as $sub_msg){
          if($this->ManagerConfig['error_log_wrap']){
            self::error_log_wrap($sub_msg);
          }else{
            error_log($sub_msg);
          }
        }
      }else{
        if($this->ManagerConfig['error_log_wrap']){
          self::error_log_wrap($message);
        }else{
          error_log($message);
        }
      }
    } else if($this->DebugMethod=='echoplain'){
      echo $message."\n";
    }else{
      echo $message."<br />\n";
    }
  }
1012389
public static function sql($time = null): string
    {
        return self::factory($time)->format(self::SQL_FORMAT);
    }
608623
private static function debugEnd()
    {
        // SWATDB_DEBUG is legacy, use SwatDB::setDebug() instead
        if (defined('SWATDB_DEBUG') || self::$debug) {
            self::$debug_wrapper_depth--;

            if (self::$debug_wrapper_depth === 0) {
                $count = 0;
                $depth = 0;

                foreach (self::$debug_info as $info) {
                    if ($info['depth'] < $depth) {
                        echo str_repeat(
                            '</blockquote>',
                            $depth - $info['depth']
                        );
                    } elseif ($info['depth'] > $depth) {
                        echo '<blockquote class="swat-db-debug">';
                    } elseif ($info['depth'] === 0) {
                        echo '<hr />';
                    }

                    echo "\n" . $info['message'] . "\n";

                    $locale = SwatI18NLocale::get();
                    printf(
                        "<p>Query #%s</p>\n",
                        $locale->formatNumber($info['count'])
                    );

                    if (count(self::$debug_info) > $count + 1) {
                        $time = self::$debug_info[$count + 1]['time'];
                    } else {
                        $time = microtime(true) * 1000;
                    }

                    $ms = $time - $info['time'];

                    printf(
                        "<p><strong>%s ms</strong></p>\n",
                        $locale->formatNumber($ms, 3)
                    );

                    if ($info['depth'] === 0 && count(self::$debug_info) > 1) {
                        $ms =
                            microtime(true) * 1000 -
                            self::$debug_info[0]['time'];

                        echo '<p><strong>';

                        printf(
                            Swat::_(
                                'Total time: %s ms (includes ' .
                                    'queries within the wrapper)'
                            ),
                            $locale->formatNumber($ms, 3)
                        );

                        echo '</strong></p>';
                    }

                    $count++;
                    $depth = $info['depth'];
                }

                if ($depth > 0) {
                    echo str_repeat('</blockquote>', $depth);
                }

                // reset debug info for the next query
                self::$debug_info = array();
            }
        }
    }
227480
protected function _timeToMongoDate($time)
    {
        if(!is_numeric($time)) {
            $time = strtotime($time);
            if(!$time) {
                $time = time();
            }
        }
        
        return new \MongoDate($time);
    }
409938
public function save(string $filename, bool $debug = false): bool
    {
        $yaml = false;
        try {
            $fileObject = !$debug
                ? new \SplFileObject($filename, 'w')
                : new \SplTempFileObject();

            $yaml = Export::save($fileObject, $this->show());

        } catch (YamlException $e) {
            !$this->_strict ?: die();
        }

        return $yaml;
    }
1352327
public function time(array $time = null)
    {
        if (is_null($time)) {
            return $this->time;
        }

        $validKeys = (count(array_diff(['hour', 'minute', 'second'], array_keys($time))) === 0);

        if (false === $validKeys) {
            throw new \InvalidArgumentException('Invalid arguments provided: '.implode($time));
        }

        $this->time = $time;

        return $this;
    }
907132
protected function extractCacheContent($file) {
		$content = (string)file_get_contents($file);

		$cacheTime = 0;
		$content = preg_replace_callback('/^\<\!--cachetime\:(\d+)--\>/', function ($matches) use (&$cacheTime) {
			$cacheTime = (int)$matches[1];
			return '';
		}, $content);

		if (Configure::read('debug')) {
			$modifiedTime = date('Y-m-d H:i:s', filemtime($file));
			$content = '<!--created:' . $modifiedTime . '-->' . $content . '<!--end-->';
		}

		return [
			'content' => $content,
			'time' => $cacheTime
		];
	}
1185279
protected function save_to_debug($string)
    {
        if ($this->debug) {
            $file = fopen($this->debug_file, 'a+');

            if (!$file) {
                $this->error = 604;
            } else {
                fwrite($file, '[' . date('Y-m-d H:i:s') . '] (' . $this->version . ') ' . $string . "\n");
                fclose($file);
            }
        }
    }
164785
public static function debug($file=''){
    $debug = array_map(function($a){
      if ( isset($a['object']) ){
        unset($a['object']);
      }
      return $a;
    }, debug_backtrace());
    if ( empty($file) ){
      self::hdump($debug);
    }
    else{
      self::log($debug, $file);
    }
  }