ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF HISTORY 8 ๏ THE MVC PATTERN VIEW 1 VIEW 2 CONTROLLER MODEL USER INPUT MODIFIES UPDATES
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF HISTORY 12 "THE MVC PATTERN SOLVES A PROBLEM THAT DOESN’T EXIST IN THE WEB."
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF HISTORY 13 "THE MVC PATTERN SOLVES A PROBLEM THAT DOESN’T EXIST IN THE WEB."
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF HISTORY 22 […] the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF HISTORY 23 ๏ RULES SUMMARISED (FOR WEBSITES) ๏ A POST request MUST NOT not respond with UI content ๏ A POST request SHOULD change the application state ๏ A POST request SHOULD respond with a redirect ๏ A GET request SHOULD respond with UI content representing the current application state ๏ A GET request MUST NOT change the application state (read-only)
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FACTS 28 ๏ MAIN COMPONENT: icehawk/icehawk 1.533 Logical lines of code (LLOC) 0 composer dependencies 0 third-party php extension dependencies v2.1.0 current stable v7.x.x php compatibility (only) STRICT typed MIT license FULLY documented at icehawk.github.io LOC Lines of code 1965 Logical lines of code 1533 Comment lines of code 433 Average volume 71.86 Average comment weight 21.28 Average intelligent content 21.28 Logical lines of code by class 29 Logical lines of code by method 5 Object oriented programming Classes 52 Interface 33 Methods 279 Methods by class 5.37 Lack of cohesion of methods 0.62 Average afferent coupling 0.66 Average efferent coupling 1.15 Average instability 0.61 Complexity Average Cyclomatic complexity by class 1.65 Average Relative system complexity 17.92 Average Difficulty 2.6
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE 35 class IceHawk { public function __construct( $config, $delegate ) public function init() {} public function handleRequest() {} }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - DELEGATION 38 final class IceHawkDelegate implements SetsUpEnvironment { public function setUpGlobalVars() { # Change your global vars $_SERVER, $_GET, $_POST, etc. # here, before IceHawk will use them. } public function setUpErrorHandling( ProvidesRequestInfo $requestInfo ) { # PHP's default error handling is used unless you set up # something else here. } public function setUpSessionHandling( ProvidesRequestInfo $requestInfo ) { # PHP's default session handling is used unless you set up # something else here. } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - DELEGATION 39 final class IceHawkDelegate implements SetsUpEnvironment { public function setUpGlobalVars() { # Change your global vars $_SERVER, $_GET, $_POST, etc. # here, before IceHawk will use them. } public function setUpErrorHandling( ProvidesRequestInfo $requestInfo ) { # PHP's default error handling is used unless you set up # something else here. } public function setUpSessionHandling( ProvidesRequestInfo $requestInfo ) { # PHP's default session handling is used unless you set up # something else here. } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - DELEGATION 40 final class IceHawkDelegate implements SetsUpEnvironment { public function setUpGlobalVars() { # Change your global vars $_SERVER, $_GET, $_POST, etc. # here, before IceHawk will use them. } public function setUpErrorHandling( ProvidesRequestInfo $requestInfo ) { # PHP's default error handling is used unless you set up # something else here. } public function setUpSessionHandling( ProvidesRequestInfo $requestInfo ) { # PHP's default session handling is used unless you set up # something else here. } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - CONFIGURATION 42 final class IceHawkConfig implements ConfiguresIceHawk { use Defaults\Traits\DefaultRequestInfoProviding; use Defaults\Traits\DefaultReadRouting; use Defaults\Traits\DefaultWriteRouting; use Defaults\Traits\DefaultRequestBypassing; use Defaults\Traits\DefaultEventSubscribing; use Defaults\Traits\DefaultCookieProviding; use Defaults\Traits\DefaultFinalReadResponding; use Defaults\Traits\DefaultFinalWriteResponding; }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - CONFIGURATION 43 final class IceHawkConfig implements ConfiguresIceHawk { use Defaults\Traits\DefaultRequestInfoProviding; use Defaults\Traits\DefaultReadRouting; use Defaults\Traits\DefaultWriteRouting; use Defaults\Traits\DefaultRequestBypassing; use Defaults\Traits\DefaultEventSubscribing; use Defaults\Traits\DefaultCookieProviding; use Defaults\Traits\DefaultFinalReadResponding; use Defaults\Traits\DefaultFinalWriteResponding; }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - CONFIGURATION 44 final class MyHawkConfig extends IceHawkConfig { public function getReadRoutes() { return [ new ReadRoute( new Literal( '/' ), new SayHelloRequestHandler() ), ]; } public function getWriteRoutes() { return [ new WriteRoute( new Literal( '/do-something' ), new DoSomethingRequestHandler() ), ]; } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - CONFIGURATION 45 # Literal route new ReadRoute( new Literal( '/' ), new SayHelloRequestHandler() ); # RegExp route with parameters from matches new ReadRoute( new RegExp("#^/post/([0-9]+)/?$#i", ['postId'] ), new ShowBlogPostRequestHandler() ); # NamedRegExp route with named matches new ReadRoute( new NamedRegExp("^/post/(?[0-9]+)/?$", 'i'), new ShowBlogPostRequestHandler() );
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - CONFIGURATION 46 # Literal route new ReadRoute( new Literal( '/' ), new SayHelloRequestHandler() ); # RegExp route with parameters from matches new ReadRoute( new RegExp("#^/post/([0-9]+)/?$#i", ['postId'] ), new ShowBlogPostRequestHandler() ); # NamedRegExp route with named matches new ReadRoute( new NamedRegExp("^/post/(?[0-9]+)/?$", 'i'), new ShowBlogPostRequestHandler() );
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - CONFIGURATION 47 # Literal route new ReadRoute( new Literal( '/' ), new SayHelloRequestHandler() ); # RegExp route with parameters from matches new ReadRoute( new RegExp("#^/post/([0-9]+)/?$#i", ['postId'] ), new ShowBlogPostRequestHandler() ); # NamedRegExp route with named matches new ReadRoute( new NamedRegExp("^/post/(?[0-9]+)/?$", 'i'), new ShowBlogPostRequestHandler() );
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - REQUEST BYPASSING 50 final class IceHawkConfig implements ConfiguresIceHawk { use Defaults\Traits\DefaultRequestInfoProviding; use Defaults\Traits\DefaultReadRouting; use Defaults\Traits\DefaultWriteRouting; use Defaults\Traits\DefaultRequestBypassing; use Defaults\Traits\DefaultEventSubscribing; use Defaults\Traits\DefaultCookieProviding; use Defaults\Traits\DefaultFinalReadResponding; use Defaults\Traits\DefaultFinalWriteResponding; }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - REQUEST BYPASSING 51 final class MyHawkConfig extends IceHawkConfig { public function getRequestBypasses() { return [ new RequestBypass( new Literal('/came/via/get'), '/do/some/write/action', HttpMethod::POST ), ]; } public function getWriteRoutes() { return [ new WriteRoute( new Literal( '/do/some/write/action' ), new DoSomethingRequestHandler() ), ]; } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - REQUEST BYPASSING 52 final class MyHawkConfig extends IceHawkConfig { public function getRequestBypasses() { return [ new RequestBypass( new Literal('/came/via/get'), '/do/some/write/action', HttpMethod::POST ), ]; } public function getWriteRoutes() { return [ new WriteRoute( new Literal( '/do/some/write/action' ), new DoSomethingRequestHandler() ), ]; } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - EVENTS & SUBSCRIBERS 57 final class IceHawkConfig implements ConfiguresIceHawk { use Defaults\Traits\DefaultRequestInfoProviding; use Defaults\Traits\DefaultReadRouting; use Defaults\Traits\DefaultWriteRouting; use Defaults\Traits\DefaultRequestBypassing; use Defaults\Traits\DefaultEventSubscribing; use Defaults\Traits\DefaultCookieProviding; use Defaults\Traits\DefaultFinalReadResponding; use Defaults\Traits\DefaultFinalWriteResponding; }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - FINAL RESPONDING 61 final class IceHawkConfig implements ConfiguresIceHawk { use Defaults\Traits\DefaultRequestInfoProviding; use Defaults\Traits\DefaultReadRouting; use Defaults\Traits\DefaultWriteRouting; use Defaults\Traits\DefaultRequestBypassing; use Defaults\Traits\DefaultEventSubscribing; use Defaults\Traits\DefaultCookieProviding; use Defaults\Traits\DefaultFinalReadResponding; use Defaults\Traits\DefaultFinalWriteResponding; }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FEATURES & CODE - FINAL RESPONDING 62 final class MyHawkConfig extends IceHawkConfig { public function getFinalReadResponder() : RespondsFinallyToReadRequest { return MyFinalReadResponder(); } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF SESSION - REGISTER DATA MAPPERS 69 # Add the data mapper for all keys in the registry $session->addDataMapper( new MyDataMapper() ); # Add the data mapper for one specific key in the registry $session->addDataMapper( new MyDataMapper(), [Session::KEY_SOME_STRING_VALUE] ); # Add the data mapper for multiple keys in the registry $session->addDataMapper( new MyDataMapper(), [ Session::KEY_SOME_STRING_VALUE, Session::KEY_SOME_OTHER_VALUE ] );
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FORMS 71 ๏ DTO TO BE STORED IN SESSION ๏ CSRF protection using tokens (with expiration) ๏ Data pre-setting ๏ Gets input validation feedback (with severity) on write side ๏ Provides input validation feedback on read side
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF FORMS - READ SIDE INITIALISATION 72 $form = new Form( new FormId('profile') ); $form->renewToken(); if ( !$form->wasDataSet() ) { # Set up some default data (single) $form->set( 'username', 'johndoe' ); }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF PUBSUB 75 ๏ BASIC PUBLISH SUBSCRIBE SYSTEM TO DECOUPLE BUSINESS LOGIC ๏ Defines interfaces for messages, channels and subscribers ๏ Provides a message bus for publishing and subscribing ๏ Provides abstract message subscriber with auto-method resolving
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF PUBSUB - A MESSAGE 76 final class YourMessage implements CarriesInformation { public function getMessageId() : IdentifiesMessage { return new MessageId('message-xyz'); } public function getMessageName() : NamesMessage { return new MessageName('User email address changed'); } public function getContent() : string { return '[email protected]'; } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF PUBSUB - A SUBSCRIBER 77 final class YourSubscriber extends AbstractMessageSubscriber { protected function whenSomethingHadHappened( YourMessage $yourMessage, Channel $channel ) { printf( 'Message named "%s" with ID "%s" ' . 'was published on channel "%" with content: "%s"', $yourMessage->getMessageName(), $yourMessage->getMessageId(), $channel, $yourMessage->getContent() ); } }
ICEHAWK FRAMEWORK • JANUARY, 19TH 2017 • PHPUGFFM • FRANKFURT AM MAIN HOLGER WOLTERSDORF PUBSUB - THE SUBSCRIPTION 78 $messageBus = new MessageBus(); $messageBus->subscribe( new Channel('ListenToMe'), new YourSubscriber() );