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

PHAR alternative - build PrefixedRector #449

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
!/temp/.gitkeep
/example
/vendor
/build
composer.lock
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@
"vendor/bin/ecs check bin packages src tests --fix",
"bin/clean_levels.sh"
],
"phpstan": "vendor/bin/phpstan.phar analyse packages src tests --level max --configuration phpstan.neon"
"phpstan": "vendor/bin/phpstan.phar analyse packages src tests --level max --configuration phpstan.neon",
"prefix-rector": [
"rm -rf build/",
"php php-scoper.phar add-prefix --no-interaction --prefix='RectorPrefixed'",
"find build/ -type f -name '*.yml' | xargs perl -pi -e 's/((?:\\\\{1,2}\\w+|\\w+\\\\{1,2})(?:\\w+\\\\{0,2})+)/RectorPrefixed\\\\\\1/g'",
"find build/ -type f | xargs sed -i 's/RectorPrefixed\\\\Rector/Rector/g'",
"find build/ -type f | xargs sed -i 's/RectorPrefixed\\\\\\\\Rector/Rector/g'",
"find build/ -type f | xargs sed -i 's/use Symfony/use RectorPrefixed\\\\\\\\Symfony/g'",
"cp composer.json build/composer.json",
"cd build && composer dump-autoload",
"cd build && php bin/rector"
]
},
"bin": [
"bin/rector",
Expand Down
Binary file added php-scoper.phar
Binary file not shown.
14 changes: 14 additions & 0 deletions php-scoper.phar.pubkey
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxKi/ABhiCMn7hqH9/W0x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP Scoper should be a dependnecy in composer.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In docs it is not recommended.

Copy link
Member

@TomasVotruba TomasVotruba Apr 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs is not a dog, nor God :)
Still, should be dependency in composer.json. Without that we have to maintain phar manually.

What advantages do you see?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflict avoidance.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bamarni/composer-bin-plugin or phive can both help out there (see this article)[https://medium.com/@tfidry/managing-your-dependencies-in-php-321d584441ab]. But I advise against relying on committing the PHAR:

  • it's really heavy on the Git history
  • it's much harder to cherry-pick a branch to try a bugfix or something

If you want to go that way nonetheless, I recommend to mark the public key as a binary file as well in .gitattributes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried bamarni/composer-bin-plugin but it cannot work due to php-parser 3/4 conflict.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So phar seems as the best option for the time being. It doesn't evolve much and the php-parser 4 + better reflectoin is main blocker there, so missing update-ability won't be such a problem.

v2WKZDtUTDoSFRMl3WMBRL0wEmwvEajOJkzgAZLLomg6DCGrH7dSgZXBaxWyq1yY
efw1qj9HcFlRs82Y8OfzdDRGDbRobERXH+sulukN0Su7jADOJHyILlQgc64Zql2J
+BXQbBXJGIeoVk3I1hKg6GALpoA5kfFMw3l8FztKiRFcBMSRdeFQJlcsB/FCXnfN
LJMnaB2LJnnV6eTj4xD3dXrKky8KxBKMxrryxNFcXqMMfL5gBdaU6CH4VUn5yPDs
R/1KBsCgTmnFY6QmRlp+kI1ogmS5Eqk66xs5WBmuCHeB+phP7CFwvfF4kFGIGITl
5nKMJ7GJWG9CFEbPlZAcfgK3e12NyHuX+XUoc94IxbfzvcWxC/ZiuFSOAbTG95ut
Ue51KkeIxq0GmW8djFySSJM4PZbPHtr7b2LhkJzjQ66dXWyTJjqxZRskmKQota6o
qe8YWALClKLaG+LYM7ZFC4Q6fb4gs1x05feucbmuiWboeJyfL/CmoafnB6MqYXxX
DXXJhMWYbrTZuawNXUe/WhEQIdiGJsoI61y7DgvKw6ExdnelIakAO9EOfkffY5wE
KVZf+2kuEqm5UPvKmwozp/g/WmMAEEn6OJbHxeqKX7Ds/eLFiE2WlZm1YO3/JNbF
HshwDz0FnMzwQom3CiykuOsCAwEAAQ==
-----END PUBLIC KEY-----
28 changes: 28 additions & 0 deletions scoper.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use Isolated\Symfony\Component\Finder\Finder;

return [
'prefix' => 'RectorPrefixed',
'finders' => [
Finder::create()
->files()
->ignoreVCS(true)
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/')
->in('*')
->exclude([
'docs',
'Tests'
])
,
],
'patchers' => [
function (string $filePath, string $prefix, string $contents): string {
// Change the contents here.

return $contents;
},
],
];