Alexander M. Turek
Total Page:16
File Type:pdf, Size:1020Kb
Painfl Migration Paths Alexander M. Turek [AMT] 1 Alexander M. Turek about:me Freelance software developer. Builds web applications with php. Lives in Frankfurt München Berlin. Likes Symfony. Likes digging into legacy code. [AMT] 2 Alexander M. Turek Disclaimer This session is not about bashing the developers of the libraries shown in the examples. I have a lot of respect for open source developers who spend a large part of their free time on improving and maintaining those awesome libraries. [AMT] 3 Alexander M. Turek Framework Migration • Your framework evolves while you're using it. • Follow the upstream development or lose support. • Outdated dependencies might block upgrade paths of other dependencies. [AMT] 4 Alexander M. Turek PHP / Composer Limitations • PHP has no concept of loading different versions of a library at the same time. • Composer does not allow to install multiple versions of the same package at the same time. [AMT] 5 Alexander M. Turek How do you refactor code? [AMT] 6 Alexander M. Turek My Recent Painfl Migrations • Guzzle 3 —> Guzzle 6 • Silex 1 —> Silex 2 • Behat 2 —> Behat 3 [AMT] 7 Alexander M. Turek Guzzle • HTTP client library. • Guzzle 4 was a complete rewrite. • All code that used the same guzzle client instance had to be migrated at once. • Good: Guzzle switched namespace/package name. • Bad: Guzzle 3 blocks Symfony upgrades. [AMT] 8 Alexander M. Turek Silex • Symfony-based micro framework. • Tightly coupled to the Pimple DIC. • Silex 1 blocks Symfony upgrades. • All-or-nothing migration. [AMT] 9 Alexander M. Turek Tight coupling via inheritance namespace Silex; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\TerminableInterface; class Application extends \Pimple implements HttpKernelInterface, TerminableInterface [AMT] 10 Alexander M. Turek Service Providers • Silex' DI extension mechanism. • Functionality was moved to Pimple. Partly. • No compatibility layer. [AMT] 11 Alexander M. Turek Silex 1.3 with Pimple 1.1 [AMT] 12 Alexander M. Turek Silex 2.0 with Pimple 3.0 [AMT] 13 Alexander M. Turek Migrate Services • Switch all service providers to the new interfaces. public function share($callable) { Shim the share method. return $callable; • } • Wrap all factory services into the factory method. • Remove all calls to the share method. • Drop the shim. [AMT] 14 Alexander M. Turek The Ugly Parts • Semantics of passing a callable to the container has changed. • Forgotten factory services are turned into shared services silently. • More restrictive behavior: Shared services are frozen after construction. [AMT] 15 Alexander M. Turek Behat • BDD testing framework for php. • Between 2.5 and 3.0, most interfaces and abstract classes used for extension have been renamed. • Communication between feature contexts removed. • Behat 2.5 blocks Symfony upgrades. [AMT] 16 Alexander M. Turek Documentation? https://github.com/Behat/Behat/issues/799 [AMT] 17 Alexander M. Turek Behat migration path • Refactor code shared by feature contexts into traits or reusable classes. • Create an abstract feature context class that shims old methods used by your code. • Change all extensions to use the new interfaces. • Remove calls to the shimmed methods. [AMT] 18 Alexander M. Turek Nice Migration Paths • Create compatibility layers. • Make deprecated usage discoverable. • Enable forward compatible development. • Document the migration path! • Don't force me into an all-or-nothing migration. [AMT] 19 Alexander M. Turek Thank You spam me: [email protected] follow me: @derrabus hire me: https://derrabus.de [AMT] 20 Alexander M. Turek.