Skip to content

Commit

Permalink
separated autoload from cli initialization. refs #28
Browse files Browse the repository at this point in the history
  • Loading branch information
indeyets committed Sep 10, 2012
1 parent ff640ad commit 6d23b98
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 44 deletions.
4 changes: 3 additions & 1 deletion bin/pake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ if (is_dir(__DIR__.'/../../../../vendor')) {
require_once realpath(__DIR__.'/../../../..').'/vendor/autoload.php';
} else {
// fallback to custom autoloader
require_once realpath(__DIR__.'/..').'/lib/pake/init.php';
require_once realpath(__DIR__.'/..').'/lib/pake/autoload.php';
}

require_once realpath(__DIR__.'/..').'/lib/pake/cli_init.php';

$retval = pakeApp::get_instance()->run();

if (false === $retval) {
Expand Down
3 changes: 2 additions & 1 deletion bin/pake.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
set_include_path(dirname(__FILE__).'/../lib'.PATH_SEPARATOR.get_include_path());
}

require 'pake/init.php';
require 'pake/autoload.php';
require 'pake/cli_init.php';

if (basename(__FILE__) == basename($_SERVER['SCRIPT_NAME'])) {
$retval = pakeApp::get_instance()->run();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"ext-posix": "*"
},
"autoload": {
"files": ["lib/pake/init.php"]
"files": ["lib/pake/autoload.php"]
},
"bin": ["bin/pake"]
}
42 changes: 1 addition & 41 deletions lib/pake/init.php → lib/pake/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/**
* @package pake
* @author Alexey Zakhlestin <[email protected]>
* @copyright 2009–2012 Alexey Zakhlestin <[email protected]>
* @copyright 2004-2005 Fabien Potencier <[email protected]>
* @copyright 2012 Alexey Zakhlestin <[email protected]>
* @license see the LICENSE file included in the distribution
*/

Expand Down Expand Up @@ -50,44 +49,5 @@ function pake_autoloader($classname)
}
spl_autoload_register('pake_autoloader');

// register our default exception handler
function pake_exception_default_handler($exception)
{
pakeException::render($exception);
exit(1);
}
set_exception_handler('pake_exception_default_handler');

mb_internal_encoding('utf-8');

// fix php behavior if using cgi php
// from http://www.sitepoint.com/article/php-command-line-1/3
if (false !== strpos(PHP_SAPI, 'cgi'))
{
// handle output buffering
@ob_end_flush();
ob_implicit_flush(true);

// PHP ini settings
set_time_limit(0);
ini_set('track_errors', true);
ini_set('html_errors', false);
ini_set('magic_quotes_runtime', false);

// define stream constants
define('STDIN', fopen('php://stdin', 'r'));
define('STDOUT', fopen('php://stdout', 'w'));
define('STDERR', fopen('php://stderr', 'w'));

// change directory
if (isset($_SERVER['PWD']))
{
chdir($_SERVER['PWD']);
}

// close the streams on script termination
register_shutdown_function(create_function('', 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;'));
}

// enabling pake's helper-functions
require PAKE_DIR.'/pakeFunction.php';
48 changes: 48 additions & 0 deletions lib/pake/cli_init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* @package pake
* @author Alexey Zakhlestin <[email protected]>
* @copyright 2009–2012 Alexey Zakhlestin <[email protected]>
* @copyright 2004-2005 Fabien Potencier <[email protected]>
* @license see the LICENSE file included in the distribution
*/

// register our default exception handler
function pake_exception_default_handler($exception)
{
pakeException::render($exception);
exit(1);
}
set_exception_handler('pake_exception_default_handler');

mb_internal_encoding('utf-8');

// fix php behavior if using cgi php
// from http://www.sitepoint.com/article/php-command-line-1/3
if (false !== strpos(PHP_SAPI, 'cgi'))
{
// handle output buffering
@ob_end_flush();
ob_implicit_flush(true);

// PHP ini settings
set_time_limit(0);
ini_set('track_errors', true);
ini_set('html_errors', false);
ini_set('magic_quotes_runtime', false);

// define stream constants
define('STDIN', fopen('php://stdin', 'r'));
define('STDOUT', fopen('php://stdout', 'w'));
define('STDERR', fopen('php://stderr', 'w'));

// change directory
if (isset($_SERVER['PWD']))
{
chdir($_SERVER['PWD']);
}

// close the streams on script termination
register_shutdown_function(create_function('', 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;'));
}

0 comments on commit 6d23b98

Please sign in to comment.