Example #1
0
 public function send($template, array $params, $closure)
 {
     /** Write the supposed email to a log file for checking
      * 
      * @param type $template
      * @param array $params
      * @param type $closure
      */
     $msg = new Message(new Universal());
     $closure($msg);
     $emailFile = getAppLogDir() . '/testEmail-' . time() . "template-{$template}.htm";
     pkdebug("IN FAKE MAILER SEND; writing to: [{$emailFile}]!");
     $fp = fopen($emailFile, "w");
     $str = '';
     $str .= "<pre>\n";
     $str .= print_r($msg, 1);
     $str .= "</pre>\n\n";
     $str .= view($template, $params);
     fwrite($fp, $str);
 }
Example #2
0
/** Outputs to the destination specified by $useDebugLog
 * 
 * @staticvar boolean $first
 * @param type $str
 * @return boolean
 * @throws Exception
 */
function pkdebugOut($str, $logpath = null) {

  //PkLibConfig::$isWarning = 1;
  if ($logpath) error_log("Logpath is: [$logpath]");
  static $first = true;
  if ($logpath) $reset = false;
  else $reset = appLogReset();
  //if ($reset) {
  try {
    //$logpath = $_SERVER['DOCUMENT_ROOT'].'/../app/logs/app.log';
    //$logpath =  WP_CONTENT_DIR.'/app.log';
    //$logpath = $_SERVER['DOCUMENT_ROOT'] . '/logs/app.log';
    if (!$logpath) $logpath = appLogPath();
    if (PkLibConfig::$isWarning) {
      if (PkLibConfig::$warnLogDir) {
        $warnpath = PkLibConfig::$warnLogDir . '/' . PkLibConfig::$warnLogName;
      } else {
        $warnpath = getAppLogDir() . '/' . PkLibConfig::$warnLogName;
      }
      $fp = fopen($warnpath, 'a+');
      if (!$fp) {
        throw new Exception("Failed to open Warning Log [$warnpath] for writing");
      }
      fwrite($fp, $str);
      fclose($fp);
    }
    if ($first && $reset) {
      $first = false;
      $fp = fopen($logpath, 'w+');
    } else {
      $fp = fopen($logpath, 'a+');
    }
    if (!$fp)
        throw new Exception("Failed to open DebugLog [$logpath] for writing");
    fwrite($fp, $str);
    fclose($fp);
  } catch (Exception $e) {
    error_log("Error Writing to Debug Log: " . $e);
    return false;
  }
  //} else {
  // error_log($str);
  //}
  return true;
}