예제 #1
0
 /**
  * TODO: To be documented.
  *
  * @param <type> $name
  * @return <type>
  */
 public function display(Exception $exception)
 {
     $debug = false;
     if (Opl_Registry::getValue('opl_extended_errors')) {
         $debug = true;
     }
     $out = Opl_Registry::get('stdout');
     // Match the port to the exception.
     foreach ($this->_ports as $port) {
         if ($port->match($exception)) {
             $libraryName = $port->getName();
             if ($debug === true) {
                 $context = $port->getContext($exception);
             }
             break;
         }
     }
     if (!isset($libraryName)) {
         return false;
     }
     $out->writeLine('= ' . $libraryName . ' =');
     $out->writeLine('MESSAGE: ' . $exception->getMessage());
     $out->writeLine('CODE: ' . get_class($exception));
     if ($debug) {
         $out->writeLine('FILE: ' . $exception->getFile() . ' [LINE ' . $exception->getLine() . ']');
     } else {
         $out->writeLine('Debug mode is disabled. No additional information provided.');
     }
     if ($debug) {
         foreach ($context as $name => $params) {
             $informer = $this->getInformer($name);
             if ($informer !== null) {
                 $informer->display($exception, $params);
             } else {
                 $out->writeLine('Unknown informer: ' . $name);
             }
         }
     }
     return true;
 }
예제 #2
0
    /**
     * Displays an exception error message. The returned value reports
     * if the error handler managed to handle the exception.
     *
     * @param Exception $exception The exception to be displayed.
     * @return boolean
     */
    public function display(Exception $exception)
    {
        $debug = false;
        if (Opl_Registry::getValue('opl_extended_errors')) {
            $debug = true;
        }
        // Match the port to the exception.
        foreach ($this->_ports as $port) {
            if ($port->match($exception)) {
                $libraryName = $port->getName();
                if ($debug === true) {
                    $context = $port->getContext($exception);
                }
                break;
            }
        }
        if (!isset($libraryName)) {
            return false;
        }
        // Display the error.
        if (ob_get_level() > 0) {
            ob_end_clean();
        }
        echo <<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{$libraryName} error</title>
<style type="text/css">
/* <![CDATA[ */
html, body{  margin: 0; padding: 0; font-size: 10pt; background: #ffffff;  }
div#oplErrorFrame { font-family: Arial, Verdana, Tahoma, Helvetica, sans-serif; color: #222222; width: 700px; margin-top: 100px; margin-left: auto; margin-right: auto; padding: 2px; }
div#oplErrorFrame h1{ font-size: 16pt; text-align: center; padding: 10px; margin: 2px 0; background: #ffffff; border-top: 4px solid #e60066; }
div#oplErrorFrame div.object{ border: 1px solid #ffdecc; margin: 2px 0;background: #ffeeee; padding: 0; }
div#oplErrorFrame div.object div{ /*border-left: 15px solid #e33a3a;*/ margin: 0; padding: 1px; }
div#oplErrorFrame p{padding: 5px; margin: 5px 0;}
div#oplErrorFrame p.message { font-size: 13pt; }
div#oplErrorFrame p.code{ font-weight: bold; }
div#oplErrorFrame p span{ margin-right: 6px; }
div#oplErrorFrame p.call{ border-top: 1px solid #e33a3a; margin: 5px; padding: 5px 0; }
div#oplErrorFrame p.call span{ float: none; margin-right: 0; font-family: 'Courier New', Courier, monospaced;  font-size: 12px; }
div#oplErrorFrame p.directive span{ font-weight: bold; }
div#oplErrorFrame p.directive span.good{ color: #009900; }
div#oplErrorFrame p.directive span.maybe{ color: #777700; }
div#oplErrorFrame p.directive span.bad{ color: #770000; }
div#oplErrorFrame p.important{ font-weight: bold; text-align: center; width:100%; }
div#oplErrorFrame p.warning span{\tfloat: left; margin-right: 12px; font-weight: bold; }
div#oplErrorFrame a {font-weight: bold; color: #000000}
div#oplErrorFrame a:hover {}
div#oplErrorFrame ul {list-style: none; margin: 5px 15px; padding: 0}
div#oplErrorFrame ul li {margin: 0; padding: 0}
div#oplErrorFrame ul li p {padding:0;}

div#oplErrorFrame li { margin-top: 2px; margin-bottom: 2px; padding: 0; }
div#oplErrorFrame li.value { font-weight: bold; }
div#oplErrorFrame li span{  margin-right: 6px; }
div#oplErrorFrame li.value span.good{ color: #009900; }
div#oplErrorFrame li.value span.maybe{ color: #777700; }
div#oplErrorFrame li.value span.bad{ color: #770000; }

div#oplErrorFrame code{ font-family: 'Courier New', Courier, monospaced; background: #ffdddd;  }
/* ]]> */
</style>  
</head>
<body>

<div id="oplErrorFrame">
<h1>{$libraryName} error</h1>
<div class="object"><div>

EOF;
        echo '  			<p class="message">' . htmlspecialchars($exception->getMessage()) . "</p>\r\n";
        echo '  			<p class="code">' . get_class($exception) . "</p>\r\n";
        if ($debug) {
            echo '  			<p class="call"><span>' . $exception->getFile() . '</span> [<span>' . $exception->getLine() . "</span>]</p>\r\n";
        } else {
            echo "  \t\t\t<p class=\"call\">Debug mode is disabled. No additional information provided.</p>\r\n";
        }
        echo "  \t\t</div></div>\r\n";
        if ($debug) {
            echo "\t\t\t<div class=\"object\"><div>\r\n";
            foreach ($context as $name => $params) {
                $informer = $this->getInformer($name);
                if ($informer !== null) {
                    $informer->display($exception, $params);
                } else {
                    echo "\t\t<p class=\"directive\"><strong>Unknown informer:</strong> " . $name . "</p>\r\n";
                }
            }
            echo "  \t\t</div></div>\r\n";
        }
        echo <<<EOF
</div>
</body>
</html>
EOF;
        return true;
    }
예제 #3
0
    /**
     * Generates a HTML output for the debug console and flushes
     * it to the script output. The console is NOT displayed, if
     * the user registered a global state 'opl_custom_console'
     * in Opl_Registry.
     *
     * @static
     */
    public static function display()
    {
        // Skip, if the user has a custom console
        if (Opl_Registry::getValue('opl_custom_console')) {
            return;
        }
        $code = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>OPL Debug Console</title>
<style type="text/css"><!--
body{margin: 0; padding: 0; background: #ffffff; font-family: Arial, Tahoma, Verdana, Helvetica; font-size: 12px; }
div#all{ margin: 0; padding: 0 0; }
table.lay {border: none; border-spacing: 0; width: 100%; border-collapse: collapse;}
table.lay td.lay {width: 50%; vertical-align: top;}
table.info, table.list { width: 100%; padding: 0; margin: 0 0 10px 0; border-spacing: 0;  border: 1px #333333 solid; }
table caption { width: 100%; margin: 0; padding: 5px 0; font-weight: bold; font-size: 13px; background: #444444; color: #ffffff; }
table.info {}
table.info tbody td { border-bottom: 1px solid #ddd; padding: 3px 5px; font-size: 12px; margin: 0}
table.info tbody td.field{  width: 40%; color: #666666; background-color: #eeeeee;}
table.info tbody td.value{ width: 60%;   background-color: #ffffff;  }
table.list {}
table.list thead td{ text-align: left;padding: 3px 5px; font-size: 12px; color: #474747; border-bottom: 1px solid #b2b2b2; background-color: #dadada; font-weight: bold; }
table.list tbody td{ font-size: 12px; padding: 3px 5px; background-color: #ffffff; border-bottom: 1px solid #ddd;}
span.good{ color: #009900; }
span.maybe{ color: #777700; }
span.bad{ color: #770000; }
h1 {font-size: 22px; margin 0 0 10px 0; padding: 6px 15px; background:#FFFFCC; border-bottom: 2px solid #FFCC33}
--></style>
</head>
<body>
<h1>OPL Debug Console</h1>
<table class="lay"><tr><td class="lay">';
        foreach (self::$_lists as &$list) {
            $code .= '   <table class="info" cellspacing="0">
<caption>' . $list['title'] . '</caption>
<tbody>
';
            foreach ($list['values'] as $title => &$value) {
                if (is_bool($value)) {
                    $value = $value ? 'Yes' : 'No';
                }
                if (is_null($value)) {
                    $value = '<em>NULL</em>';
                }
                $code .= '    <tr>
 <td class="field">' . $title . '</td>
 <td class="value">' . $value . '</td>
</tr>
';
            }
            $code .= '    </tbody>
</table>
';
        }
        $code .= '</td><td class="lay">';
        foreach (self::$_tables as &$table) {
            $code .= '  <table class="list" cellspacing="0">
<caption>' . $table['title'] . '</caption>
<thead>
 <tr>
';
            foreach ($table['columns'] as $column) {
                if (($split = strpos($column, ':')) !== false) {
                    $code .= '      <td width="' . substr($column, 0, $split) . '">' . substr($column, $split) . '</td>';
                } else {
                    $code .= '      <td>' . $column . '</td>';
                }
            }
            $code .= '     </tr>
</thead>
<tbody>';
            if (is_null($table['information'])) {
                foreach ($table['values'] as &$data) {
                    $code .= '     <tr>';
                    foreach ($data as $item) {
                        $code .= '      <td>' . $item . '</td>';
                    }
                    $code .= '     </tr>';
                }
            } else {
                $code .= '     <tr>
	  <td colspan="' . sizeof($table['columns']) . '">' . $table['information'] . '</td>
	 </tr>
';
            }
            $code .= '    </tbody>
</table>
';
        }
        $code .= ' </td></tr></table>
</body>
</html>
';
        echo '<script type="text/javascript">';
        echo 'opl_console = window.open("","OPL_debug_console","width=1000,height=500,resizable,scrollbars=yes,menubar=no,toolbar=no,location=no,status=no");';
        echo 'opl_console.document.close();';
        echo 'opl_console.document.open();';
        $exp = explode("\n", $code);
        foreach ($exp as $line) {
            echo 'opl_console.document.write(\'' . addcslashes(trim($line), "'\\") . "');\r\n";
        }
        echo '</script>';
    }
예제 #4
0
 /**
  * @covers Opl_Registry::setValue
  * @covers Opl_Registry::getValue
  */
 public function testSettingState()
 {
     Opl_Registry::setValue('foo', 'bar');
     $this->assertEquals(Opl_Registry::getValue('foo'), 'bar');
 }