Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Transforming Magento (NomadMage 2017)

Transforming Magento (NomadMage 2017)

Christopher Pitt

April 19, 2017
Tweet

More Decks by Christopher Pitt

Other Decks in Programming

Transcript

  1. TRANSFORMING
    MAGENTO

    View Slide

  2. HI

    View Slide

  3. THANKS:
    NOMADMAGE AND NOMADPHP

    View Slide

  4. DISCLAIMER:
    I'M REALLY NEW

    View Slide

  5. DISCLAIMER:
    HERE BE DRAGONS

    View Slide

  6. ! composer require tinify/magento2

    View Slide

  7. LOOK AT THESE
    GETTERS AND SETTERS

    View Slide

  8. EVER MISS FEATURES
    FROM ANOTHER LANGUAGE?

    View Slide

  9. TECHNICALLY:
    MAGIC METHODS

    View Slide

  10. IMAGINE WE COULD
    USE THIS SYNTAX...

    View Slide

  11. ALAS,
    THE TESTS FAIL

    View Slide

  12. ! composer require pre/class-accessors

    View Slide

  13. WHAT'S THIS,
    THE TESTS PASS

    View Slide

  14. WHAT HAPPENED?

    View Slide

  15. WHAT IF WE WANT OUR OWN
    MAGIC METHODS?

    View Slide

  16. YOU HEAR ABOUT THE
    TRAILING COMMAS
    PROPOSAL?

    View Slide

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

    View Slide

  18. SIDETRACK:
    STRANGE INCONSISTENCIES...

    View Slide

  19. LET'S TRY

    View Slide

  20. ! composer require pre/trailing-commas

    View Slide

  21. SOMETHING
    SERIOUSER

    View Slide

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

    View Slide

  23. LOOK AT THAT XML!

    View Slide

  24. ! composer require pre/parameter-loaders

    View Slide

  25. ! composer require pre/property-loaders

    View Slide

  26. CODE YOUR MUM
    WOULD APPROVE OF

    View Slide

  27. SOMETHING
    SIMPLER

    View Slide

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

    View Slide

  29. CAN'T RETURN IMMEDIATELY
    BECAUSE OF STUPID FILES

    View Slide

  30. ! composer require pre/deferred

    View Slide

  31. WITH
    50%
    MORE BLOCKS

    View Slide

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

    View Slide

  33. HOW DOES THIS WORK?

    View Slide

  34. SPOILERS:
    JUNE 22ND, NOMADPHP

    View Slide

  35. PAUL'S [FOURTH]
    STANDARDS
    RECOMMENDATION

    View Slide

  36. COMPILES:
    File.pre ! File.php

    View Slide

  37. github.com/marcioAlmada/yay

    View Slide

  38. WHAT DOES THIS
    CODE LOOK LIKE?

    View Slide

  39. class Sprocket
    {
    public $name = new Translatable(static::class);
    public function turn($spanner = factory("spanner"))
    {
    return $spanner->use($this);
    }
    }

    View Slide

  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);
    }
    }

    View Slide

  41. ! composer require friendsofphp/php-cs-fixer

    View Slide

  42. IS IT
    SLOW?

    View Slide

  43. ! composer du -o

    View Slide

  44. ! composer dump-autoload --optimize

    View Slide

  45. MAKES A LOCK FILE

    View Slide

  46. GREAT FOR DEV
    GREAT FOR PROD

    View Slide

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

    View Slide

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

    View Slide

  49. WHY WOULD I
    USE THIS?

    View Slide

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

    View Slide

  51. REASONS TO USE:
    ▸ New syntax could be clearer and more concise
    ▸ You want features from other languages
    ▸ You want to support old PHP

    View Slide

  52. process .."/helpers.pre";

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  57. REASONS NOT TO USE:
    ▸ No IDE support
    ▸ You have to teach developers new syntax
    ▸ You have to learn how .gitignore files work

    View Slide

  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

    View Slide

  59. twitter.com/assertchris
    preprocess.io

    View Slide