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

Introducing The Instruction Pipeline

Introducing The Instruction Pipeline

Build your own middleware in PHP. A walkthrough of the complete design, development and testing workflow.

Presented at PHP Yorkshire.

Avatar for Stuart Herbert

Stuart Herbert

April 08, 2017
Tweet

More Decks by Stuart Herbert

Other Decks in Programming

Transcript

  1. @GanbaroDigital I’m going to show you how to build a

    pipeline that’s built to your specs.
  2. @GanbaroDigital “ We can chop and change the modules -

    and their order - without having to touch the modules themselves
  3. @GanbaroDigital “ We can chop and change the modules -

    and their order - without having to touch the modules themselves
  4. @GanbaroDigital “ We can chop and change the modules -

    and their order - without having to touch the modules themselves
  5. @GanbaroDigital “ We can chop and change the modules -

    and their order - without having to touch the modules themselves
  6. @GanbaroDigital Design Constraints 1. We must use the cloud-provider’s message

    queueing service 2. Different programming languages in use for transmitting and receiving systems
  7. @GanbaroDigital Traffic to and from the message queue goes over

    HTTPS. The messages are encrypted on the wire / in transit.
  8. @GanbaroDigital Design Constraints 1. We must use the cloud-provider’s message

    queueing service 2. Different programming languages in use for transmitting and receiving systems
  9. @GanbaroDigital Because We Built A Pipeline • Created new modules

    • Dropped them in where we needed them • Zero changes to signed-off code
  10. @GanbaroDigital Because We Built A Pipeline • Created new modules

    • Dropped them in where we needed them • Zero changes to signed-off code • Reduced impact on deployment pipeline
  11. @GanbaroDigital Encode To JSON Encrypt Add HMAC Encode To Ascii-Safe

    Instructions Decode From Ascii-Safe Verify & Strip HMAC Decrypt Decode From JSON Transmit Receive
  12. @GanbaroDigital Encrypt Instruction Builder HMAC Encode To JSON Ascii-Safe JSON

    Decode From JSON Transmit Pipeline Receive Pipeline
  13. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  14. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  15. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  16. @GanbaroDigital Instruction Verify & Strip HMAC Calc HMAC Add HMAC

    Find HMAC Remove HMAC Operation(s) Verify HMAC Add HMAC Calc HMAC
  17. @GanbaroDigital Instruction Verify & Strip HMAC Calc HMAC Add HMAC

    Find HMAC Remove HMAC Operation(s) Verify HMAC Add HMAC Calc HMAC
  18. @GanbaroDigital Operations are very boring. They’re just plain PHP code.

    In my experience, boring code is reliable code.
  19. @GanbaroDigital Instruction Verify & Strip HMAC Calc HMAC Add HMAC

    Find HMAC Remove HMAC Operation(s) Verify HMAC Add HMAC Calc HMAC
  20. @GanbaroDigital Instruction Verify & Strip HMAC Calc HMAC Add HMAC

    Find HMAC Remove HMAC Operation(s) Verify HMAC Add HMAC Calc HMAC
  21. @GanbaroDigital Instruction Verify & Strip HMAC Calc HMAC Add HMAC

    Find HMAC Remove HMAC Operation(s) Verify HMAC Add HMAC Calc HMAC
  22. @GanbaroDigital $next->process() Encode To JSON Encrypt Add HMAC Encode To

    Ascii-Safe $next->process() $next->process() $next->process() $next->process()
  23. @GanbaroDigital $next->process() Encode To JSON Encrypt Add HMAC Encode To

    Ascii-Safe $next->process() $next->process() $next->process()
  24. @GanbaroDigital We’re now starting to see how to use the

    underlying InstructionPipeline framework. ganbarodigital/ php-mv-instruction-pipeline
  25. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  26. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  27. @GanbaroDigital Now that we have working Instructions, we can build

    out their factories: the “Instruction Builders”
  28. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  29. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  30. @GanbaroDigital Encrypt Add HMAC Encode To Ascii-Safe Instruction Builder HMAC

    Verify & Strip HMAC Encode To JSON Decode From Ascii-Safe Ascii-Safe JSON Decode From JSON Encrypt Decrypt Transmit Pipeline Receive Pipeline
  31. @GanbaroDigital How do we execute the Instruction Builders to assemble

    the pipelines? We need to build one last helper class.
  32. @GanbaroDigital We Have Built … • 11 x Operations (inc

    base classes) • 10 x Instructions • 4 x Instruction Builders
  33. @GanbaroDigital We Have Built … • 11 x Operations (inc

    base classes) • 10 x Instructions • 4 x Instruction Builders
  34. @GanbaroDigital We Have Built … • 11 x Operations (inc

    base classes) • 10 x Instructions • 4 x Instruction Builders
  35. @GanbaroDigital They Are Supported By … • 8 x Robustness

    helpers 
 (Checks & Requirements) • 11 x Exceptions • 2 x Type-safety Interfaces
  36. @GanbaroDigital They Are Supported By … • 8 x Robustness

    helpers 
 (Checks & Requirements) • 11 x Exceptions • 2 x Type-safety Interfaces
  37. @GanbaroDigital They Are Supported By … • 8 x Robustness

    helpers 
 (Checks & Requirements) • 11 x Exceptions • 2 x Type-safety Interfaces
  38. @GanbaroDigital ?? ?? How hard is it to add type

    declarations to a library like MessagingPipeline?
  39. @GanbaroDigital Instructions are isolated from each other. They cannot know

    what data transformations will happen elsewhere on the pipeline.
  40. @GanbaroDigital Encrypt Instruction Builder HMAC Ascii-Safe JSON Transmit Pipeline Receive

    Pipeline mixed > string string > string string > string string > string string > string string > mixed string > string string > string
  41. @GanbaroDigital Encrypt Instruction Builder HMAC Ascii-Safe JSON Transmit Pipeline Receive

    Pipeline mixed > string string > string string > string string > string string > string string > mixed string > string string > string
  42. @GanbaroDigital Encrypt Instruction Builder HMAC Ascii-Safe JSON Transmit Pipeline Receive

    Pipeline mixed > string string > string string > string string > string string > string string > mixed string > string string > string
  43. @GanbaroDigital NextInstruction also enforces type safety. It’s unique to your

    library. Only Instructions written for your library will accept your NextInstruction.
  44. @GanbaroDigital Strict typing is the equivalent of ‘filters’ from ‘input

    filtering and validation’. Strict typing doesn’t cover your data validation responsibilities.
  45. @GanbaroDigital “With 100% code coverage, you could still ship bugs.

    Without 100% code coverage, you’re definitely shipping bugs.