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

Design for Scalability with HMVC

Design for Scalability with HMVC

Sam de Freyssinet

June 10, 2010
Tweet

More Decks by Sam de Freyssinet

Other Decks in Programming

Transcript

  1. “Thomas & Friends”, “The Fat Controller” © 2010 Gullane (Thomas)

    Limited. The Thomas name and character and the Thomas & Friends logo are trademarks of Gullane (Thomas) Limited and its affiliates and are registered in many jurisdictions throughout the world. Friday, 25 May 12
  2. C V M C V M C V M C

    V M C V M C V M Dashboard Posts Pages ACL Users Media Friday, 25 May 12
  3. “HMVC provides a powerful yet easy-to- understand layered design methodology

    for developing a complete presentation layer. While MVC provides an efficient framework for developing GUI interaction, HMVC scales it to the entire client tier.” “[...] the traditional MVC scope falls short when it comes to the control of GUI elements (widgets). MVC does not handle the complexities of data management, event management, and application flows [...]” Friday, 25 May 12
  4. “SOA separates functions into distinct units, or services, which developers

    make accessible over a network in order to allow users to combine and reuse them in the production of applications.” http://en.wikipedia.org/wiki/Service-oriented_architecture Friday, 25 May 12
  5. C V M C V M C V M C

    V M C V M C V M Request Request Request Request Request Request Request Request Request Request Request Request C V M C V M C V M C V M C V M C V M Request Request Request Request Request Request Request Friday, 25 May 12
  6. 0% 20% 40% 60% 80% 100% 2010 2011 2012 2013

    2014 0 100,000 200,000 300,000 400,000 500,000 Available capacity Users Friday, 25 May 12
  7. Properties & methods create read (view/load) update delete find find_all

    [...] id username password full name nickname email [...] Friday, 25 May 12
  8. // Load an instance of sian user using HMVC $user

    = Request::factory('user/load/sian.json') ->execute(); Friday, 25 May 12
  9. // Load an instance of sian user $user = User::instance()

    ->load('sian'); // Load an instance of sian user using HMVC $user = Request::factory('user/load/sian.json') ->execute(); FTW Friday, 25 May 12
  10. HTTP server Handle client request PHP initialisation PHP runs, index.php

    executed Bootstrap Framework loads all required dependencies Request The server request is parsed producing a request object Routing The request is examined and matched to a registered route Application logic The matched controller action is invoked. The business logic of the request takes place here, including loading of models and views, gathering data and rendering the result. Framework execution Friday, 25 May 12
  11. // If there is no cached user if ( !

    $user = Cache::instance() ->load('sian12345')) { // Load an instance of sian // user using HMVC $user = Request::factory('user/sian') ->execute(); } Friday, 25 May 12
  12. // If there is no cached user if ( !

    $user = Cache::instance() ->load('sian12345')) { // Load an instance of sian user $user = User::instance() ->load('sian'); } // If there is no cached user if ( ! $user = Cache::instance() ->load('sian12345')) { // Load an instance of sian user using HMVC $user = Request::factory('user/sian') ->execute(); } Friday, 25 May 12
  13. // Create a URI for the user route $uri =

    Route::get('users') ->uri(array('username' => 'sian')); // Load the URI with a request Request::factory($uri) ->execute(); $uri => /user/load/sian.json Friday, 25 May 12
  14. Route::set('users', 'user/<action>/<username>(<format>)', array('username' => '\w+', 'format' => '\.\w+')) ->defaults(array( 'controller'

    => 'user', 'action' => 'load', 'format' => '.json', )); Route::set('users', 'user/<action>/<username>(<format>)', array('username' => '\w+', 'format' => '\.\w+')) ->defaults(array( 'controller' => 'user', 'action' => 'load', 'format' => '.json', 'host' => 'users.myhost.tld', )); Friday, 25 May 12
  15. + - + mysite.com Home Archive Blog Web board About

    us My Website Buy content login username password ******* Register | Forget password 12 - “RDX Wall Art: The Making Of” iand new short documentary iand new short isa new short - isa new short documentary - highlighting iand new sho documentary - some of the pioneers highlighting iand new sho more ... Foobar 12 - “RDX Wall Art: The Making Of” iand new short documentary iand new short isa new short - isa new short documentary - highlighting iand new sho documentary - some of the pioneers highlighting iand new sho more ... Foobar Friday, 25 May 12
  16. + - + mysite.com Home Archive Blog Web board About

    us username siân password ******* Register | Forget password OK Login Friday, 25 May 12
  17. <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Login page</title> </head> <body>

    <form action="/auth/login" method="post" accept-charset="utf-8"> <p> <label for "username">Username :</label> <br /> <input type="test" name="username" value="" id="username"> </p> <p> <label for "password">Password :</label> <br /> <input type="test" name="password" value="" id="password"> </p> <p> <input type="submit" value="Login &rarr;"> </p> </form> </body> </html> Friday, 25 May 12
  18. + - + mysite.com Home Archive Blog Web board About

    us My Website Buy content login username password ******* Register | Forget password 12 - “RDX Wall Art: The Making Of” iand new short documentary iand new short isa new short - isa new short documentary - highlighting iand new sho documentary - some of the pioneers highlighting iand new sho more ... Foobar 12 - “RDX Wall Art: The Making Of” iand new short documentary iand new short isa new short - isa new short documentary - highlighting iand new sho documentary - some of the pioneers highlighting iand new sho more ... Foobar Friday, 25 May 12
  19. <form action="/auth/login" method="post" accept-charset="utf-8"> <p> <label for "username">Username :</label> <br

    /> <input type="test" name="username" value="" id="username"> </p> <p> <label for "password">Password :</label> <br /> <input type="test" name="password" value="" id="password"> </p> <p> <input type="submit" value="Login &rarr;"> </p> </form> Friday, 25 May 12
  20. // Test the request for reduced style if ($this->request->header('X-Login-Style') ===

    'reduced') { // Return the reduced login form $this->response->body = View::factory('login/reduced.phtml'); } else { // Return the full login form $this->response->body = View::factory('login/reduced.phtml'); } Friday, 25 May 12
  21. Kohana 3 Website ~ http://kohanaframework.org Source ~ http://github.com/kohana Kohana 3.1

    development ~ http://github.com/samsoir/core/tree/3.1 Friday, 25 May 12