Exemple #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);
     }
 }
Exemple #2
0
/**
 * @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');
    }
}
Exemple #3
0
	<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>
Exemple #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));
Exemple #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);
Exemple #6
0
 /**
  * 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}";
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #9
0
/** @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);
    }
}