xp-framework / core

The XP Framework is an all-purpose, object oriented PHP framework.
Other
19 stars 6 forks source link

PSR autoloader and extensions support #302

Closed thekid closed 2 years ago

thekid commented 2 years ago

This pull request enables support for PSR-0, PSR-4 and class map autoloaders as well as extensions being specified via composer.json 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());

The reason we don't simply use Composer's autoloading mechanism here is that we cannot prevent it from loading XP Framework twice, which currently does not work.

thekid commented 2 years ago

https://github.com/sebastianbergmann/php-code-coverage/blob/master/composer.json is an example of a library using classmap

thekid commented 2 years ago

https://github.com/sebastianbergmann/php-code-coverage/blob/master/composer.json is an example of a library using classmap

This now works:

<?php namespace test;

use SebastianBergmann\CodeCoverage\Version from 'phpunit/php-code-coverage';
use util\cmd\Console;

Console::writeLine(Version::id());
thekid commented 2 years ago

Made obsolete by xp-runners/reference#85