Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Cleanup for Building in PHP 7.0 #183

Merged
merged 19 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ crashlytics-build.properties
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

# Visual Studio code
.vscode/**
settings.json
launch.json

## Build generated
build/
DerivedData
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ language: php
php:
- '5.3.3'
- '5.4'
- '7.0'
- '7.1.6'
env:
global:
- NODE_VERSION=6
Expand Down
3 changes: 1 addition & 2 deletions classes/CCR/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function factory(
$mask = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE
| E_STRICT | E_DEPRECATED | E_USER_DEPRECATED;

if ($e !== NULL && ($e['type'] & $mask) == 0) {
if ($e !== null && ($e['type'] & $mask) == 0) {
$logger->crit(array(
'message' => $e['message'],
'file' => $e['file'],
Expand Down Expand Up @@ -278,4 +278,3 @@ protected static function getConfiguration($option)
return xd_utilities\getConfiguration('logger', $option);
}
}

150 changes: 74 additions & 76 deletions configuration/linker.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,31 @@
$include_path .= ":" . $baseDir . '/classes/User';
$include_path .= ":" . $baseDir . '/classes/ReportTemplates';
$include_path .= ":" . $baseDir . '/classes/AppKernel';
$include_path .= ":" . $baseDir . '/external_libraries/Zend/library';
$include_path .= ":" . $baseDir . '/libraries/HighRoller_1.0.5';

ini_alter('include_path', $include_path);

function xdmodAutoload($className)
{
$pathList = explode(":", ini_get('include_path'));
$pathList = explode(":", ini_get('include_path'));

// if class does not have a namespace
if(strpos($className,'\\') === FALSE) {
$includeFile = $className.".php";
foreach ($pathList as $path) {
if (is_readable("$path/$includeFile")) {
require_once("$path/$includeFile");
break;
}
}
} else {
// convert namespace to full file path
$class = dirname(__FILE__) . '/../classes/'
if(strpos($className, '\\') === false) {
$includeFile = $className.".php";
foreach ($pathList as $path) {
if (is_readable("$path/$includeFile")) {
require_once("$path/$includeFile");
break;
}
}
} else {
// convert namespace to full file path
$class = dirname(__FILE__) . '/../classes/'
. str_replace('\\', '/', $className) . '.php';
if (is_readable("$class")) {
require_once($class);
}
}
if (is_readable("$class")) {
require_once($class);
}
}
}

spl_autoload_register('xdmodAutoload');
Expand All @@ -65,14 +64,14 @@ function xdmodAutoload($className)
$libraries = scandir($baseDir . '/libraries');

foreach ($libraries as $library) {
$file = "$baseDir/libraries/$library";
if (is_dir($file)) {
continue;
}
require_once($file);
$file = "$baseDir/libraries/$library";
if (is_dir($file)) {
continue;
}
require_once($file);
}

class HttpCodeMessages
class HttpCodeMessages
{
// HTTP 1.1 messages from: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Expand Down Expand Up @@ -136,73 +135,73 @@ class HttpCodeMessages
*/
function handle_uncaught_exception($exception)
{
$logfile = LOG_DIR . "/" . xd_utilities\getConfiguration('general', 'exceptions_logfile');
$logfile = LOG_DIR . "/" . xd_utilities\getConfiguration('general', 'exceptions_logfile');

$logConf = array('mode' => 0644);
$logger = Log::factory('file', $logfile, 'exception', $logConf);
$logConf = array('mode' => 0644);
$logger = \Log::factory('file', $logfile, 'exception', $logConf);

$logger->log('Exception Code: '.$exception->getCode(), PEAR_LOG_ERR);
$logger->log('Message: '.$exception->getMessage(), PEAR_LOG_ERR);
$logger->log('Origin: '.$exception->getFile().' (line '.$exception->getLine().')', PEAR_LOG_INFO);
$logger->log('Exception Code: '.$exception->getCode(), PEAR_LOG_ERR);
$logger->log('Message: '.$exception->getMessage(), PEAR_LOG_ERR);
$logger->log('Origin: '.$exception->getFile().' (line '.$exception->getLine().')', PEAR_LOG_INFO);

$stringTrace = (get_class($exception) == 'UniqueException') ? $exception->getVerboseTrace() : $exception->getTraceAsString();
$stringTrace = (get_class($exception) == 'UniqueException') ? $exception->getVerboseTrace() : $exception->getTraceAsString();

$logger->log("Trace:\n".$stringTrace."\n-------------------------------------------------------", PEAR_LOG_INFO);
$logger->log("Trace:\n".$stringTrace."\n-------------------------------------------------------", PEAR_LOG_INFO);

// If working in a server context, build headers to output.
$httpCode = 500;
$headers = array();
$isServerContext = isset($_SERVER['SERVER_PROTOCOL']);
if ($isServerContext) {
$uncheckedExceptionHttpCode = null;
if ($exception instanceof XDException) {
$uncheckedExceptionHttpCode = $exception->httpCode;
$headers = $exception->headers;
} else if ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface) {
$uncheckedExceptionHttpCode = $exception->getStatusCode();
$headers = $exception->getHeaders();
}

if ($uncheckedExceptionHttpCode !== null) {
if (array_key_exists($uncheckedExceptionHttpCode, HttpCodeMessages::$messages)) {
$httpCode = $uncheckedExceptionHttpCode;
}
}
}

$exceptionData = xd_response\buildError($exception);
$content = json_encode($exceptionData);
if ($isServerContext) {
$headers['Content-Type'] = 'application/json';
}

return array(
$httpCode = 500;
$headers = array();
$isServerContext = isset($_SERVER['SERVER_PROTOCOL']);
if ($isServerContext) {
$uncheckedExceptionHttpCode = null;
if ($exception instanceof XDException) {
$uncheckedExceptionHttpCode = $exception->httpCode;
$headers = $exception->headers;
} elseif ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface) {
$uncheckedExceptionHttpCode = $exception->getStatusCode();
$headers = $exception->getHeaders();
}

if ($uncheckedExceptionHttpCode !== null) {
if (array_key_exists($uncheckedExceptionHttpCode, HttpCodeMessages::$messages)) {
$httpCode = $uncheckedExceptionHttpCode;
}
}
}

$exceptionData = xd_response\buildError($exception);
$content = json_encode($exceptionData);
if ($isServerContext) {
$headers['Content-Type'] = 'application/json';
}

return array(
'content' => $content,
'isServerContext' => $isServerContext,
'headers' => $headers,
'httpCode' => $httpCode,
);
);
} // handle_uncaught_exception

function global_uncaught_exception_handler($exception)
{
// Perform logging and output building for the exception.
$exceptionOutput = handle_uncaught_exception($exception);
$exceptionOutput = handle_uncaught_exception($exception);

// If running in a server context...
if ($exceptionOutput['isServerContext']) {
// Set the exception's headers (if any).
foreach ($exceptionOutput['headers'] as $headerKey => $headerValue) {
header("$headerKey: $headerValue");
}
if ($exceptionOutput['isServerContext']) {
// Set the exception's headers (if any).
foreach ($exceptionOutput['headers'] as $headerKey => $headerValue) {
header("$headerKey: $headerValue");
}

// Set the status code header.
$httpCode = $exceptionOutput['httpCode'];
header("{$_SERVER['SERVER_PROTOCOL']} $httpCode ".HttpCodeMessages::$messages[$httpCode]);
}
// Set the status code header.
$httpCode = $exceptionOutput['httpCode'];
header("{$_SERVER['SERVER_PROTOCOL']} $httpCode ".HttpCodeMessages::$messages[$httpCode]);
}

// Print the exception's content.
echo $exceptionOutput['content'];
echo $exceptionOutput['content'];
} // global_uncaught_exception_handler

set_exception_handler('global_uncaught_exception_handler');
Expand All @@ -212,14 +211,13 @@ function global_uncaught_exception_handler($exception)
$config = Xdmod\Config::factory();

$org = $config['organization'];
define('ORGANIZATION_NAME', $org['name']);
define('ORGANIZATION_NAME', $org['name']);
define('ORGANIZATION_NAME_ABBREV', $org['name']);

$hierarchy = $config['hierarchy'];
define('HIERARCHY_TOP_LEVEL_LABEL', $hierarchy['top_level_label']);
define('HIERARCHY_TOP_LEVEL_INFO', $hierarchy['top_level_info']);
define('HIERARCHY_TOP_LEVEL_LABEL', $hierarchy['top_level_label']);
define('HIERARCHY_TOP_LEVEL_INFO', $hierarchy['top_level_info']);
define('HIERARCHY_MIDDLE_LEVEL_LABEL', $hierarchy['middle_level_label']);
define('HIERARCHY_MIDDLE_LEVEL_INFO', $hierarchy['middle_level_info']);
define('HIERARCHY_MIDDLE_LEVEL_INFO', $hierarchy['middle_level_info']);
define('HIERARCHY_BOTTOM_LEVEL_LABEL', $hierarchy['bottom_level_label']);
define('HIERARCHY_BOTTOM_LEVEL_INFO', $hierarchy['bottom_level_info']);

define('HIERARCHY_BOTTOM_LEVEL_INFO', $hierarchy['bottom_level_info']);
6 changes: 0 additions & 6 deletions open_xdmod/modules/xdmod/assets/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ assets_dir="$(
module_dir="$assets_dir/.."
xdmod_dir="$module_dir/../../.."

echo Removing existing dependencies
rm -rf $xdmod_dir/external_libraries

echo Creating directory for external libraries
mkdir $xdmod_dir/external_libraries

echo Installing composer managed dependencies
cd $xdmod_dir
composer install --no-dev
Expand Down
1 change: 0 additions & 1 deletion open_xdmod/modules/xdmod/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"classes",
"db",
"etl",
"external_libraries",
"html",
"libraries",
"reporting",
Expand Down
3 changes: 2 additions & 1 deletion open_xdmod/modules/xdmod/tests/lib/Common/IdentityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function tearDown() {
}

/**
* @expectedException InvalidArgumentException
* @expectedException ArgumentCountError
* @requires PHP 7.1
*/
public function testNoDefaultParameterToConstructor()
{
Expand Down
3 changes: 3 additions & 0 deletions shippable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ build:
- composer install --no-progress
- cp ~/assets/secrets open_xdmod/modules/xdmod/integration_tests/.secrets
- ./open_xdmod/modules/xdmod/integration_tests/runtests.sh --log-junit `pwd`/shippable/testresults/results.xml
on_failure:
- cat /var/log/xdmod/*