Skip to content

Commit cd1b5cf

Browse files
committed
Fix pake crashes
1 parent d0f30cc commit cd1b5cf

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

includes/pakeFunction.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,18 @@ function pake_exception_default_handler($exception)
390390
}
391391
set_exception_handler('pake_exception_default_handler');
392392

393+
function pake_STDIN() {
394+
return fopen('php://stdin', 'rb');
395+
}
396+
397+
function pake_STDOUT() {
398+
return fopen('php://stdout', 'wb');
399+
}
400+
401+
function pake_STDERR() {
402+
return fopen('php://stderr', 'wb');
403+
}
404+
393405
// fix php behavior if using cgi php
394406
// from http://www.sitepoint.com/article/php-command-line-1/3
395407
if (false !== strpos(PHP_SAPI, 'cgi'))
@@ -404,11 +416,6 @@ function pake_exception_default_handler($exception)
404416
ini_set('html_errors', false);
405417
ini_set('magic_quotes_runtime', false);
406418

407-
// define stream constants
408-
define('STDIN', fopen('php://stdin', 'r'));
409-
define('STDOUT', fopen('php://stdout', 'w'));
410-
define('STDERR', fopen('php://stderr', 'w'));
411-
412419
// change directory
413420
if (isset($_SERVER['PWD']))
414421
{

lib/vendor/pake/pakeColor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ static function style($name, $options = array())
2929
self::$styles[$name] = $options;
3030
}
3131

32-
static function colorize($text = '', $parameters = array(), $stream = STDOUT)
32+
static function colorize($text = '', $parameters = array(), $stream)
3333
{
34+
$stream = $stream ?: pake_STDOUT();
3435
// disable colors if not supported (windows or non tty console)
3536
if (DIRECTORY_SEPARATOR == '\\' || !function_exists('posix_isatty') || !@posix_isatty($stream))
3637
{

lib/vendor/pake/pakeException.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* This file is part of the pake package.
55
* (c) 2004, 2005 Fabien Potencier <[email protected]>
6-
*
6+
*
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
@@ -46,18 +46,18 @@ function render($e)
4646

4747
$messages[] = str_repeat(' ', $len);
4848

49-
fwrite(STDERR, "\n");
49+
fwrite(pake_STDERR(), "\n");
5050
foreach ($messages as $message)
5151
{
52-
fwrite(STDERR, pakeColor::colorize($message, 'ERROR', STDERR)."\n");
52+
fwrite(pake_STDERR(), pakeColor::colorize($message, 'ERROR', pake_STDERR())."\n");
5353
}
54-
fwrite(STDERR, "\n");
54+
fwrite(pake_STDERR(), "\n");
5555

5656
$pake = pakeApp::get_instance();
5757

5858
if ($pake->get_trace())
5959
{
60-
fwrite(STDERR, "exception trace:\n");
60+
fwrite(pake_STDERR(), "exception trace:\n");
6161

6262
$trace = $this->trace($e);
6363
for ($i = 0, $count = count($trace); $i < $count; $i++)
@@ -68,11 +68,11 @@ function render($e)
6868
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
6969
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
7070

71-
fwrite(STDERR, sprintf(" %s%s%s at %s:%s\n", $class, $type, $function, pakeColor::colorize($file, 'INFO', STDERR), pakeColor::colorize($line, 'INFO', STDERR)));
71+
fwrite(pake_STDERR(), sprintf(" %s%s%s at %s:%s\n", $class, $type, $function, pakeColor::colorize($file, 'INFO', pake_STDERR()), pakeColor::colorize($line, 'INFO', pake_STDERR())));
7272
}
7373
}
7474

75-
fwrite(STDERR, "\n");
75+
fwrite(pake_STDERR(), "\n");
7676
}
7777

7878
function trace($exception)

0 commit comments

Comments
 (0)