Skip to content

Commit

Permalink
refs #1052: Debug 클래스 조금 더 구조화시킴
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Oct 7, 2008
1 parent 85c543f commit 368a7e3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions framework/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)

class DebuggerError extends Exception {};

class Debug {
private $backend = 'logfile';
private $file = NULL;
Expand All @@ -14,7 +16,7 @@ function __construct($backend_name, $options = NULL) {
// always open in append mode
$this->file = fopen('./debug.log', 'a');
if ($this->file === FALSE)
return FALSE;
throw new DebuggerError("Creation failed because debug.log couldn't be opened.");
if ($options != NULL && $options['truncate'] == TRUE)
$this->truncate();
break;
Expand All @@ -27,10 +29,13 @@ function __construct($backend_name, $options = NULL) {
break;
case 'socket':
if ($options == NULL)
return FALSE;
$this->file = fsockopen($options['host'], $options['port']);
if ($this->file === FALSE)
return FALSE;
throw new DebuggerError("Insufficient options.");
$errno = 0;
if ($options['host'] == 'localhost')
$options['host'] = '127.0.0.1';
$this->file = @fsockopen($options['host'], $options['port'], $errno, $errstr, 10);
if ($this->file === FALSE || $errno != 0)
throw new DebuggerError("Creation failed due to socket error ($errno, $errstr)");
break;
default:
$backend_name = 'console';
Expand Down

0 comments on commit 368a7e3

Please sign in to comment.