Transforming Magento (NomadMage 2017)

Transforming Magento (NomadMage 2017)

061e3bae4ce4234a2194d20a382e5d19?s=128

Christopher Pitt

April 19, 2017
Tweet

Transcript

  1. TRANSFORMING MAGENTO

  2. HI

  3. THANKS: NOMADMAGE AND NOMADPHP

  4. DISCLAIMER: I'M REALLY NEW

  5. DISCLAIMER: HERE BE DRAGONS

  6. ! composer require tinify/magento2

  7. LOOK AT THESE GETTERS AND SETTERS

  8. EVER MISS FEATURES FROM ANOTHER LANGUAGE?

  9. TECHNICALLY: MAGIC METHODS

  10. IMAGINE WE COULD USE THIS SYNTAX...

  11. ALAS, THE TESTS FAIL

  12. ! composer require pre/class-accessors

  13. WHAT'S THIS, THE TESTS PASS

  14. WHAT HAPPENED?

  15. WHAT IF WE WANT OUR OWN MAGIC METHODS?

  16. YOU HEAR ABOUT THE TRAILING COMMAS PROPOSAL?

  17. wiki.php.net/rfc/list-syntax-trailing-commas

  18. SIDETRACK: STRANGE INCONSISTENCIES...

  19. LET'S TRY

  20. ! composer require pre/trailing-commas

  21. SOMETHING SERIOUSER

  22. HANDS UP IF YOU'VE EVER USED DEPENDENCY INJECTION

  23. LOOK AT THAT XML!

  24. ! composer require pre/parameter-loaders

  25. ! composer require pre/property-loaders

  26. CODE YOUR MUM WOULD APPROVE OF

  27. SOMETHING SIMPLER

  28. EVER OPEN A FILE HANDLE ...OR CREATE A MUTEX LOCK?

  29. CAN'T RETURN IMMEDIATELY BECAUSE OF STUPID FILES

  30. ! composer require pre/deferred

  31. WITH 50% MORE BLOCKS

  32. $handle = fopen("path/to/file); defer { fclose($handle); unlink("path/to/file"); } return fgets($handle);

  33. HOW DOES THIS WORK?

  34. SPOILERS: JUNE 22ND, NOMADPHP

  35. PAUL'S [FOURTH] STANDARDS RECOMMENDATION

  36. COMPILES: File.pre ! File.php

  37. github.com/marcioAlmada/yay

  38. WHAT DOES THIS CODE LOOK LIKE?

  39. class Sprocket { public $name = new Translatable(static::class); public function

    turn($spanner = factory("spanner")) { return $spanner->use($this); } }
  40. class Sprocket { use \Pre\PropertyLoaders\PropertyLoadersTrait; private $name; private function loadNameProperty()

    { $this->name = new Translatable(static::class); } public function turn($spanner = null) { if (is_null($spanner)) { $spanner = factory("spanner"); } return $spanner->use($this); } }
  41. ! composer require friendsofphp/php-cs-fixer

  42. IS IT SLOW?

  43. ! composer du -o

  44. ! composer dump-autoload --optimize

  45. MAKES A LOCK FILE

  46. GREAT FOR DEV GREAT FOR PROD

  47. CAN I USE THIS TO MAKE MY OWN SYNTAX?

  48. OTHER THINGS: ▸ immutable classes ▸ short arrow functions

  49. WHY WOULD I USE THIS?

  50. REASONS TO USE: ▸ You like the syntax I've shown

    ▸ You repeat code ▸ You repeat code
  51. REASONS TO USE: ▸ New syntax could be clearer and

    more concise ▸ You want features from other languages ▸ You want to support old PHP
  52. process .."/helpers.pre";

  53. process __DIR__ . "/helpers.pre";

  54. \Pre\processAndRequire(__DIR__ . "/helpers.pre");

  55. process __DIR__ . "/helpers.pre";

  56. process .."/helpers.pre";

  57. REASONS NOT TO USE: ▸ No IDE support ▸ You

    have to teach developers new syntax ▸ You have to learn how .gitignore files work
  58. HOW TO GET THOSE REASONS OFF THE PLANE: [HUMANELY] ▸

    Pay someone to develop IDE support (or do it yourself) ▸ Help me make the docs better ▸ Learn how .gitignore files work
  59. twitter.com/assertchris preprocess.io