Slide 1

Slide 1 text

TRANSFORMING MAGENTO

Slide 2

Slide 2 text

HI

Slide 3

Slide 3 text

THANKS: NOMADMAGE AND NOMADPHP

Slide 4

Slide 4 text

DISCLAIMER: I'M REALLY NEW

Slide 5

Slide 5 text

DISCLAIMER: HERE BE DRAGONS

Slide 6

Slide 6 text

! composer require tinify/magento2

Slide 7

Slide 7 text

LOOK AT THESE GETTERS AND SETTERS

Slide 8

Slide 8 text

EVER MISS FEATURES FROM ANOTHER LANGUAGE?

Slide 9

Slide 9 text

TECHNICALLY: MAGIC METHODS

Slide 10

Slide 10 text

IMAGINE WE COULD USE THIS SYNTAX...

Slide 11

Slide 11 text

ALAS, THE TESTS FAIL

Slide 12

Slide 12 text

! composer require pre/class-accessors

Slide 13

Slide 13 text

WHAT'S THIS, THE TESTS PASS

Slide 14

Slide 14 text

WHAT HAPPENED?

Slide 15

Slide 15 text

WHAT IF WE WANT OUR OWN MAGIC METHODS?

Slide 16

Slide 16 text

YOU HEAR ABOUT THE TRAILING COMMAS PROPOSAL?

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

SIDETRACK: STRANGE INCONSISTENCIES...

Slide 19

Slide 19 text

LET'S TRY

Slide 20

Slide 20 text

! composer require pre/trailing-commas

Slide 21

Slide 21 text

SOMETHING SERIOUSER

Slide 22

Slide 22 text

HANDS UP IF YOU'VE EVER USED DEPENDENCY INJECTION

Slide 23

Slide 23 text

LOOK AT THAT XML!

Slide 24

Slide 24 text

! composer require pre/parameter-loaders

Slide 25

Slide 25 text

! composer require pre/property-loaders

Slide 26

Slide 26 text

CODE YOUR MUM WOULD APPROVE OF

Slide 27

Slide 27 text

SOMETHING SIMPLER

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

CAN'T RETURN IMMEDIATELY BECAUSE OF STUPID FILES

Slide 30

Slide 30 text

! composer require pre/deferred

Slide 31

Slide 31 text

WITH 50% MORE BLOCKS

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

HOW DOES THIS WORK?

Slide 34

Slide 34 text

SPOILERS: JUNE 22ND, NOMADPHP

Slide 35

Slide 35 text

PAUL'S [FOURTH] STANDARDS RECOMMENDATION

Slide 36

Slide 36 text

COMPILES: File.pre ! File.php

Slide 37

Slide 37 text

github.com/marcioAlmada/yay

Slide 38

Slide 38 text

WHAT DOES THIS CODE LOOK LIKE?

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

! composer require friendsofphp/php-cs-fixer

Slide 42

Slide 42 text

IS IT SLOW?

Slide 43

Slide 43 text

! composer du -o

Slide 44

Slide 44 text

! composer dump-autoload --optimize

Slide 45

Slide 45 text

MAKES A LOCK FILE

Slide 46

Slide 46 text

GREAT FOR DEV GREAT FOR PROD

Slide 47

Slide 47 text

CAN I USE THIS TO MAKE MY OWN SYNTAX?

Slide 48

Slide 48 text

OTHER THINGS: ▸ immutable classes ▸ short arrow functions

Slide 49

Slide 49 text

WHY WOULD I USE THIS?

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

process .."/helpers.pre";

Slide 53

Slide 53 text

process __DIR__ . "/helpers.pre";

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

process __DIR__ . "/helpers.pre";

Slide 56

Slide 56 text

process .."/helpers.pre";

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

twitter.com/assertchris preprocess.io