-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Add PhpScoper compactor #31
Conversation
bin/box
Outdated
@@ -26,8 +26,8 @@ define('BOX_PATH', dirname(__DIR__)); | |||
|
|||
if ($uri = Phar::running()) { | |||
require "$uri/vendor/autoload.php"; | |||
} elseif (class_exists('Extract')) { | |||
require __DIR__.'/../vendor/autoload.php'; | |||
//} elseif (class_exists('Extract')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code?! Booh! 👻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why it's a PoC :D
I was accidentally using humbug/php-scoper#117 which is not ready yet and was failing on this class because it couldn't find it
Status: requires more work on PHP-Scoper for now:
|
Reworked the configuration to make it easier to re-use: the command now provides the globalNamespaceWhitelister ready for use as well as the list of files with their contents. As the handler has a lot of IO-bound dependencies, it is actually very hard to re-use so it makes more sense to integrate it back to the command. This paves the way for box-project/box#31.
Continuing some work for box-project/box#31. The Scoper now takes the file contents as an argument. This allows the scoper to be used with non-exitent files (e.g. virtual files) or files for which we are modifying the content like in Box. Another benefit is that it removes the Scopers dependency to the file system layer.
Continuing some work for box-project/box#31. The Scoper now takes the file contents as an argument. This allows the scoper to be used with existent files (e.g. virtual files) or files for which we are modifying the content like in Box. Another benefit is that it removes the Scopers dependency to the file system layer.
c6e4399
to
577509c
Compare
This is exactly what I need 👍 |
7d8ba34
to
87e0456
Compare
bin/box
Outdated
@@ -50,6 +50,24 @@ $app->run(); | |||
*/ | |||
function load_composer_class_loader(?string $dir): ClassLoader | |||
{ | |||
if (file_exists($autoload = __DIR__.'/../../../autoload.php')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be greatly simplified in a separate PR I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #64
scoper.inc.php
Outdated
return [ | ||
'patchers' => [ | ||
function (string $filePath, string $prefix, string $contents): string { | ||
$file = 'vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Factory.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do a PR to fix that at the root
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually should no longer be necessary with the latest version of PHP-Scoper
src/Box.php
Outdated
@@ -175,6 +177,22 @@ function ($file): string { | |||
); | |||
} | |||
|
|||
$cwd = getcwd(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obviously this is not good enough
src/Box.php
Outdated
@@ -296,9 +314,13 @@ private function processContents(array $files): array | |||
self::replacePlaceholders($placeholders, $contents) | |||
); | |||
|
|||
(new Filesystem())->dumpFile($tmp.DIRECTORY_SEPARATOR.$local, $processedContents); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dumping the file shouldn't be done here
src/Compactor/PhpScoper.php
Outdated
return $this->scoper->scope( | ||
$file, | ||
$contents, | ||
'TODOAllowNullPrefix', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Configuration.php
Outdated
private static function retrievePhpScoperConfig(stdClass $raw, string $basePath): PhpScoperConfiguration | ||
{ | ||
if (!isset($raw->{'php-scoper'})) { | ||
$configFilePath = $basePath.DIRECTORY_SEPARATOR.self::PHP_SCOPER_CONFIG; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the file system
87e0456
to
16384b3
Compare
6039597
to
2eafeab
Compare
There is a bug with the Composer namespace: - Either do not prefix any Composer related package - Either add an e2e test with Composer in PHP-Scoper
2eafeab
to
5d2301a
Compare
Closes humbug/php-scoper#49