This pull request uses Composer's autoloading mechanism for XP scripts. The following now works:
<?php
use Smalot\PdfParser\Parser from 'smalot/pdfparser';
use util\cmd\Console;
// See See https://github.com/smalot/pdfparser
$parser= new Parser();
$pdf= $parser->parseFile($argv[1]);
Console::writeLine($pdf->getText());
Unlike #302, which reimplements this mechanism, this pull request ensures the XP core is not loaded twice.
This means it only works for up-to-date framework versions. If an older XP version is inside the vendor directory, scripts will yield Compile error (Cannot redeclare __error() (previously declared in .../lang.base.php:104). To get around this, we should ship the following diff as bugfix release:
diff --git a/src/main/php/__xp.php b/src/main/php/__xp.php
index e0dfafe79..2b18fb619 100755
--- a/src/main/php/__xp.php
+++ b/src/main/php/__xp.php
@@ -4,6 +4,8 @@ if (PHP_VERSION_ID < 70000) {
throw new \Exception('This version of the XP Framework requires PHP 7.0.0+, have PHP '.PHP_VERSION);
}
+if (class_exists(xp::class, false)) return;
+
$p= max(strrpos(__FILE__, DIRECTORY_SEPARATOR), strrpos(__FILE__, '?'));
require_once substr(__FILE__, 0, $p + 1).'lang.base.php';
This pull request uses Composer's autoloading mechanism for XP scripts. The following now works:
Unlike #302, which reimplements this mechanism, this pull request ensures the XP core is not loaded twice.
This means it only works for up-to-date framework versions. If an older XP version is inside the vendor directory, scripts will yield Compile error (Cannot redeclare __error() (previously declared in .../lang.base.php:104). To get around this, we should ship the following diff as bugfix release: