Rector: Create PHAR with prefixes to avoid class and package version conflicts

Created on 29 Nov 2017  Â·  30Comments  Â·  Source: rectorphp/rector

Is a .phar build planned for this tool? I would be interested. :-)

Most helpful comment

The solution is closer than ever before... :)
https://github.com/rectorphp/rector/pull/2373

We got to overcome handful Symfony bugs at first, but now it looks good

All 30 comments

Why not :)

I like this approach: https://github.com/phpstan/phpstan-shim

Well, as I can have a link for a wget, I'm ok. :stuck_out_tongue:

Let's do this then :) could you prepare such repository and test it?
We can move the repo here afterwards and generate phar to GitHub pagest

Not sure to get time to learn how to build a .phar now. But if nobody does it, I'll do it one time.

About the .phar story. What is the interest of a -shim repository? Why not publish the phar on a website or on the release file instead like php-cs-fixer?

I think it's composer update approach. Install and forget.

I never update my phar deps

Feel free to re-open with PR or reference to demo repository.
Closing now to keep only valid issues open only

I'm making this priority, since the bin plugin doesn't work as expected

Once we have phar support could we add this to phive?

Sure. The phar is on hold now, I could not make it.
Any help is appreciated

As discusses @mssimi over hangouts, think of prefixing only:

Tried php-scoper atm I cannot whitelist namespace easily.

https://github.com/humbug/php-scoper/issues/192

Edit: Does not prefix config files either.

I'd consider using it as it cover 80 % cases.

The rest need to be resolve our way:

  • whitelist can be run done with string replace via cli

    • php-scoper: "Rector" => "Prefix123Rector"

    • sed in cli to original state

  • config files prefixing - simple script should handle that

What issues did you face when creating the phar?

Why/how create the compiler?

Where to start

phpstan-compiler isn't closed source, it was moved to phpstan/phpstan-src. See my tweet: https://twitter.com/OndrejMirtes/status/1191608448049451009

I've updated the link.

Btw, how can Rector use PHPStan now without requiring whole prefixed phar? I didn't find https://packagist.org/?query=phpstan-src on packagist :/

It should work exactly the same way for you. I encourage you to try to build Rector on top of phpstan/phpstan dev-master.

The problem is, most of vendor will be duplicated/prefixed.
To prefix Rector correctly using PHPStan's vendor, we would need to know the prefix string. It's not possible now

I don’t get it. PHPStan itself and nikic/php-parser aren’t prefixed. As PHPStan user (even of internals like types or Scope), you don’t have to care about the generated prefix of for example symfony/console. You’re not supposed to touch it.

There is symfony/console in PHPStan - prefixed,
and one in Rector - currently not prefixed.

That means almost double the load of files in vendor compared to shared dependencies - now.

I don't see the problem in practice.

That means almost double the load of files in vendor compared to shared dependencies - now.

There's going to be only one PHPStan file (the .phar) in vendor so this statement isn't true.

It is, PHPStan (the .phar with prefixed) + Rector's vendor.
The best solution to keep file load same as now would be to have phpstan-src on Packagist, as was phpstan before.

But why? Just try it and see that it works. No one cares about 5 more megabytes to download. It's better longterm like this.

Basically the main reason for the PHAR is that the latest version will be usable by more people, not creating conflicts in Composer. It was discussed here: phpstan/phpstan#2074

Thanks for the link. It looked very random with commit and no PR to master.

Just try it and see that it works. No one cares about 5 more megabytes to download. It's better longterm like this.

I don't mind that much, but not sure about the community. I'll refer people to this if they complain :)

The solution is closer than ever before... :)
https://github.com/rectorphp/rector/pull/2373

We got to overcome handful Symfony bugs at first, but now it looks good

Was this page helpful?
0 / 5 - 0 ratings