示例#1
0
 /**
  * New application
  */
 public function __construct()
 {
     try {
         exit($this->main($GLOBALS['argc'], $GLOBALS['argv']));
     } catch (Exception $e) {
         print $GLOBALS['argv'][0] . ': ' . ABException::format($e, true, false);
         exit($e->getCode() ? $e->getCode() : 1);
     }
 }
示例#2
0
文件: log.php 项目: rsms/phpab
/**
 * @param  $sto  int  stacktrace offset
 * @ignore
 */
function log_msg($msg, &$level, $sto)
{
    $logfile = ABLog::$defaultFile;
    if (!ABLog::$msgPrefix) {
        $f = debug_backtrace();
        $f1 = @$f[$sto + 1];
        $f = $f[$sto];
        $file =& $f['file'];
        $prefix = (strpos($file, @$_SERVER['DOCUMENT_ROOT']) === 0 ? substr($file, strlen(@$_SERVER['DOCUMENT_ROOT']) + 1) : $file) . ':' . $f['line'];
    } else {
        $prefix = ABLog::$msgPrefix;
    }
    $args = array();
    $_msg2 = '';
    foreach ($msg as $m) {
        if (is_object($m) and $m instanceof Exception) {
            $_msg2 .= ABException::format($m, true, false) . "\n";
        } else {
            $args[] = $m;
        }
    }
    $_msg = '';
    if ($count = count($args)) {
        if ($count > 1) {
            $fmt = array_shift($args);
            $_msg = vsprintf($fmt, $args) . ($_msg ? ' ' . rtrim($_msg) : '');
        } else {
            $_msg = $args[0];
        }
    }
    if ($_msg2 && $_msg) {
        $_msg .= "\n" . $_msg2;
    }
    if (ABLog::$includeTimestamp) {
        $msg = date('[Y-m-d H:i:s') . " {$level} {$prefix}] {$_msg}";
    } else {
        $msg = "[{$level} {$prefix}] {$_msg}";
    }
    if (!$logfile) {
        return error_log($msg, 0);
    } else {
        return error_log($msg, 3, ABLog::$dir . $logfile . '.log');
    }
}
示例#3
0
文件: index.php 项目: rsms/phpab
	<body>
		<h1>Unit test</h1>
		<?php 
foreach ($cases as $case) {
    # Assemble class info
    $classInfo = $case->getClassInfo();
    $ifs = $classInfo->getInterfaces();
    $ifNames = array();
    foreach ($ifs as $if) {
        $ifNames[] = $if->getName();
    }
    # Render HTML
    print '<div class="case">' . '<h2 class="header ' . ($case->passed() ? 'passed' : 'failed') . '">' . ($classInfo->isAbstract() ? ' abstract' : '') . ($classInfo->isFinal() ? ' final' : '') . ($classInfo->isInterface() ? ' interface' : ' class') . ' ' . $classInfo->getName() . ($classInfo->getParentClass() ? ' extends ' . $classInfo->getParentClass()->getName() : '') . ($ifNames ? ' implements ' . implode(' ', $ifNames) : '') . '</h2>' . '<div class="body">' . 'Defined in ' . $classInfo->getFileName() . '<br />';
    # Render exception, if any
    if ($case->hasException()) {
        print ABException::format($case->getException());
    }
    # Render each assertion
    if ($case->getAssertions()) {
        $numAssertions = count($case->getAssertions());
        print '<h3>' . $numAssertions . ' failure' . ($numAssertions > 1 ? 's' : '') . ':</h3>';
        foreach ($case->getAssertions() as $assertion) {
            print '<div class="assertion html">' . $assertion->toHTML() . '</div>';
        }
    }
    # Finish him!
    print '</div>' . '</div>';
}
?>
	</body>
</html>
示例#4
0
<?php

/*
Copyright (c) 2005-2007, Rasmus Andersson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
 * @version    $Id$
 * @package    ab
 * @subpackage mvc
 */
http_error('500 Internal Error', 0, ABException::format($e));
示例#5
0
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
 * @version    $Id$
 * @package    ab
 * @subpackage mvc
 */
$path = $_SERVER['REQUEST_URI'];
if (($p = strpos($path, '?')) !== false) {
    $path = substr($path, 0, $p);
}
$html = '<p>Recognition failed for ' . htmlentities($path) . '</p>';
if (MVC_DEV_MODE) {
    $html .= '<p><small>' . ABException::format($e) . '</small></p>';
}
http_error('404 Not Found', 'Routing Error', $html);
示例#6
0
文件: LogRecord.php 项目: rsms/phpab
 /**
  * String representation of this log record
  * 
  * @return string
  */
 public function toString()
 {
     // Date & Level
     $msg = '[' . $this->getTimeFormat() . ' ' . $this->getLevelName();
     // Name
     if ($this->logger->getDisplaysName()) {
         $msg .= ' ' . $this->logger->getName();
     }
     $msg .= '] ';
     // Message
     if ($this->message) {
         $msg .= $this->message . ' ';
     }
     if ($this->thrown) {
         $msg .= ABException::format($this->thrown, true, false);
     }
     return "{$msg}";
 }
示例#7
0
 /**
  * @param  LogRecord
  * @return bool  If false, the filter chain will break
  * @throws Exception
  */
 public function filter(LogRecord $rec)
 {
     // dont't filter?
     if ($rec->getLevel() < $this->parameters['level'] || cdCtx('cli_debug')) {
         return true;
     }
     // Message
     $msg = '';
     if ($rec->getMessage()) {
         $msg .= $rec->getMessage() . "\n";
     }
     if ($rec->getThrown()) {
         $msg .= ABException::format($rec->getThrown(), true, false);
     }
     $msg = trim($msg);
     // forward
     $this->insertRecord($rec, $msg);
     return true;
 }
示例#8
0
 /**
  * @param  string
  * @param  int
  * @return bool  If the message should be passed on to the next filter or to the log handler.
  * @throws Exception
  */
 public function filter(LogRecord $rec)
 {
     // dont't filter?
     if ($rec->getLevel() < $this->conf['level'] || cdCtx('cli_debug')) {
         return true;
     }
     // get group
     $group = '?';
     if (($id = @posix_getegid()) !== false) {
         if (($id = @posix_getgrgid($id)) !== false) {
             $group = $id['name'];
         }
     }
     // Date & Level
     $msg = 'Time:       ' . $rec->getTimeFormat() . "\n" . 'Group:User: '******':' . cdUser() . "\n" . 'CWD:        ' . getcwd() . "\n" . 'Level:      ' . $rec->getLevelName() . "\n";
     // Prefix
     $prefix = $rec->getPrefix();
     if ($prefix) {
         $msg .= "Log Prefix: {$prefix}\n";
     } else {
         $prefix = 'main';
     }
     $msg .= "\n";
     // Message
     if ($rec->getThrown()) {
         $msg .= ABException::format($rec->getThrown(), true, false);
     }
     if ($rec->getMessage()) {
         $msg .= $rec->getMessage();
     }
     // Email headers
     $headers = 'From: ' . $this->conf['from'] . "\r\nX-Mailer: contentd/" . cdVersion();
     // Subject
     // %e = exception name, %l = log level, %j = job name
     $logLevelName = ucfirst(trim(strtolower($rec->getLevelName())));
     $subject = strtr($this->conf['subject'], array('%e' => $rec->getThrown() ? get_class($rec->getThrown()) : $logLevelName, '%l' => $logLevelName, '%j' => $prefix));
     // Action
     if (!mail($this->conf['to'], $subject, $msg, $headers)) {
         $rec->setMessage($rec->getMessage() . '. Additionaly, the Mail log filter failed to mail "' . $this->conf['to'] . '"');
     }
     return true;
 }
示例#9
0
 /**
  * @param  string
  * @return void
  */
 protected function importClassFiles($path)
 {
     $org_cwd = getcwd();
     chdir($path);
     foreach (scandir($path) as $file) {
         if ($file[0] == '.') {
             continue;
         }
         $filepath = $path . '/' . $file;
         if (strrchr($file, '.') == '.php') {
             if (!preg_match('/^[A-Z]/', $file)) {
                 continue;
             }
             $guessedClass = substr($file, 0, -4);
             if ($this->log) {
                 $this->log->debug("Loading class %s from %s/%s ... ", $guessedClass, basename($path), basename($file));
             }
             if (!class_exists($guessedClass) && !interface_exists($guessedClass, false)) {
                 $e = new Exception();
                 print "\nFATAL unittest error in " . __FILE__ . ':' . (__LINE__ - 2) . ":\n  Unable to find probable class or interface \"{$guessedClass}\" for file \n" . ABException::formatTrace($e, false);
                 exit(1);
             }
             if ($this->log) {
                 $this->log->debug("OK\n");
             }
         } elseif ($this->recursive && is_dir($filepath) && is_readable($filepath)) {
             # Recurse down the alley...
             $this->importClassFiles($filepath);
         }
     }
     chdir($org_cwd);
 }
示例#10
0
文件: exception.php 项目: rsms/phpab
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
 * @version    $Id$
 * @package    ab
 * @subpackage mvc
 */
$html = '<pre>' . strip_tags(get_class($e) . " from " . $e->getFile() . ':' . $e->getLine() . ': ' . $e->getMessage());
$errmsg = "Killed by " . strip_tags(get_class($e) . " from " . $e->getFile() . ':' . $e->getLine() . ': ' . $e->getMessage());
if (MVC_DEV_MODE) {
    if ($e instanceof ABException) {
        $ts = ABException::formatTrace($e, false);
    } else {
        $ts = $e->getTraceAsString();
    }
    $errmsg .= "\n   " . strip_tags(str_replace("\n", "\n   ", $ts));
    $html .= "\n<small>\n   " . strip_tags(str_replace("\n", "\n   ", $ts)) . '</small>';
}
http_error('500 Internal Error', 0, $html . '</pre>');
示例#11
0
文件: php_error.php 项目: rsms/phpab
}
$fileLine = "on line {$line} in ";
if (isset($_SERVER['DOCUMENT_ROOT'])) {
    $fileLine .= File::relativePath($file, $_SERVER['DOCUMENT_ROOT']);
} elseif (isset($GLOBALS['argv'][0])) {
    $fileLine .= File::relativePath($file, dirname($GLOBALS['argv'][0]));
} else {
    $fileLine .= $file;
}
switch ($errno) {
    case E_PARSE:
    case E_USER_ERROR:
    case E_ERROR:
        break;
    case E_NOTICE:
    case E_USER_NOTICE:
        if (PHP::isCLI()) {
            IO::writeError("{$GLOBALS['argv'][0]}: WARNING: {$str} {$fileLine}\n");
        } else {
            error_log("WARNING: {$str} {$fileLine}");
        }
        return;
}
if (PHP::isCLI()) {
    IO::writeError("{$GLOBALS['argv'][0]}: FATAL: {$str} {$fileLine}\n\t" . str_replace("\n", "\n\t", ABException::formatTrace(new Exception(), false, array('__errhandler'))) . "\n");
} else {
    $s = ABException::formatTrace(new Exception(), true, array('__errhandler'));
    error_log("FATAL: {$str} ({$fileLine}) {$s}");
    print "<div class=\"err\"><b>FATAL:</b> {$str} <span class=\"file\">{$fileLine}</span>\n" . '<div class="trace">' . $s . '</div>' . '</div>';
}
exit(1);
示例#12
0
文件: boot.php 项目: rsms/phpab
/** @ignore */
function __exhandler($e)
{
    try {
        $err = ABException::format($e, true, ini_get('html_errors') != '0');
    } catch (Exception $e) {
        $err = nl2br(strval($e));
    }
    if (ini_get('display_errors')) {
        die($err);
    } else {
        error_log($err);
        exit(1);
    }
}
示例#13
0
 /**
  * @param  string
  * @param  int
  * @param  string
  */
 public function __construct($msg = null, $errno = 0, $error_info = '')
 {
     parent::__construct($msg, $errno, null, -1, null);
     $this->errorInfo = $error_info;
 }