コアライブラリの エレガントなハック 第 5 回 CakePHP 勉強会 @Tokyo ON 2010/5/29( 土 )
Files <ul><li>http://bit.ly/cakestudy_hiromi </li></ul>
About me <ul><li>Name:  清水 紘己( Shimizu Hiroki ) </li></ul><ul><li>Call me hiromi !  ( @hiromi2424 ) </li></ul><ul><li>Acti...
INDEX <ul><li>Introduction </li></ul><ul><li>Hacks </li></ul><ul><ul><li>Components </li></ul></ul><ul><ul><li>Helpers </l...
Introduction
Why hack? <ul><li>Embedding Application Policy </li></ul>
Why hack? <ul><li>Deep Debugging </li></ul>
Why hack? <ul><li>For Stub (Mock object) </li></ul>
How hack? <ul><li>Hook object mapping like alias </li></ul><ul><ul><li>This session focuses this </li></ul></ul><ul><li>Pr...
Userland import <ul><li>App/libs/* </li></ul><ul><li>Copy the file from Core to App </li></ul><ul><li>Replace, done </li><...
Impossible/Non-elegance <ul><li>Static Classes </li></ul><ul><li>Basic functions </li></ul>Use Lithium
Hacks
Hack components
Components - ACL <ul><li>Provided hook </li></ul><ul><li>Configure::write('Acl.classname‘, ‘MyAcl’) </li></ul><ul><li>MyAc...
Components - Others <ul><li>Replaces mapped objects </li></ul><ul><li>Component::_loaded[$key] </li></ul><ul><ul><li>Refer...
Components - Others <ul><li>Component class flow </li></ul>init() initialize() startup() Configuration Mapping objects Sta...
Components - Others <ul><li>var $components = (‘Session’, ’Auth’, ‘Security’); </li></ul>Initializing now NO Auth initiali...
Components - Others <ul><li>$Component->enabled = boolean </li></ul><ul><li>SessionComponent::__construct($base) </li></ul...
Hack helpers
Helpers <ul><li>Replaces mapped objects </li></ul><ul><li>$view::loaded[$key] </li></ul><ul><ul><li>Reference to object </...
Hacks Models
Models <ul><li>ClassRegistry::init() </li></ul><ul><li>alias option </li></ul><ul><li>Example </li></ul><ul><ul><li>ClassR...
Hacks CakeRoute
CakeRoute <ul><li>From 1.3 </li></ul><ul><li>(Plugin | App)/libs/routes/my_route.php </li></ul><ul><li>App::import(‘Lib’, ...
CakeRoute <ul><li>parse() </li></ul><ul><ul><li>Parsing given URL to parameters. </li></ul></ul><ul><ul><li>Helping additi...
CakeRoute <ul><li>match() </li></ul><ul><ul><li>Convert parameters to proper URL. </li></ul></ul><ul><ul><li>Reverse Routi...
CakeRoute <ul><li>Example </li></ul><ul><ul><li>Mark Story wrote great example on his BLOG </li></ul></ul><ul><ul><li>I ad...
Engines
Cache <ul><li>(Plugin | App)/libs/cache/my_cache.php </li></ul><ul><li>Cache::config(‘default’, array(‘engine’ => MyCache)...
CakeLog <ul><li>From 1.3 </li></ul><ul><li>(Plugin | App)/libs/log/my_logger.php </li></ul><ul><li>CakeLog::config(‘my’, a...
Conclusion <ul><li>Hacks rarely needed? </li></ul><ul><li>CakePHP is realy needed? </li></ul><ul><li>Learn Possible/Imposs...
Upcoming SlideShare
Loading in …5
×

Cakephpstudy5 hacks

1,422 views
1,385 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,422
On SlideShare
0
From Embeds
0
Number of Embeds
542
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cakephpstudy5 hacks

  1. 1. コアライブラリの エレガントなハック 第 5 回 CakePHP 勉強会 @Tokyo ON 2010/5/29( 土 )
  2. 2. Files <ul><li>http://bit.ly/cakestudy_hiromi </li></ul>
  3. 3. About me <ul><li>Name: 清水 紘己( Shimizu Hiroki ) </li></ul><ul><li>Call me hiromi ! ( @hiromi2424 ) </li></ul><ul><li>Action about CakePHP </li></ul><ul><ul><li>Translation </li></ul></ul><ul><ul><li>New features report </li></ul></ul><ul><ul><li>TransitionComponent </li></ul></ul><ul><ul><li>Few Patches/Tickets </li></ul></ul><ul><li>I love singing, Ramen and Beer! </li></ul>
  4. 4. INDEX <ul><li>Introduction </li></ul><ul><li>Hacks </li></ul><ul><ul><li>Components </li></ul></ul><ul><ul><li>Helpers </li></ul></ul><ul><ul><li>Models </li></ul></ul><ul><ul><li>CakeRoute </li></ul></ul><ul><ul><li>Engines </li></ul></ul>
  5. 5. Introduction
  6. 6. Why hack? <ul><li>Embedding Application Policy </li></ul>
  7. 7. Why hack? <ul><li>Deep Debugging </li></ul>
  8. 8. Why hack? <ul><li>For Stub (Mock object) </li></ul>
  9. 9. How hack? <ul><li>Hook object mapping like alias </li></ul><ul><ul><li>This session focuses this </li></ul></ul><ul><li>Provided hook </li></ul>
  10. 10. Userland import <ul><li>App/libs/* </li></ul><ul><li>Copy the file from Core to App </li></ul><ul><li>Replace, done </li></ul>Dirty Hack
  11. 11. Impossible/Non-elegance <ul><li>Static Classes </li></ul><ul><li>Basic functions </li></ul>Use Lithium
  12. 12. Hacks
  13. 13. Hack components
  14. 14. Components - ACL <ul><li>Provided hook </li></ul><ul><li>Configure::write('Acl.classname‘, ‘MyAcl’) </li></ul><ul><li>MyAclComponent extends AclBase </li></ul><ul><li>Implements methods </li></ul><ul><ul><li>… lots of. </li></ul></ul>
  15. 15. Components - Others <ul><li>Replaces mapped objects </li></ul><ul><li>Component::_loaded[$key] </li></ul><ul><ul><li>Reference to object </li></ul></ul><ul><li>Hook timing </li></ul><ul><ul><li>Initialize() </li></ul></ul>
  16. 16. Components - Others <ul><li>Component class flow </li></ul>init() initialize() startup() Configuration Mapping objects Starting process Hook
  17. 17. Components - Others <ul><li>var $components = (‘Session’, ’Auth’, ‘Security’); </li></ul>Initializing now NO Auth initialized Undefined $loaded[‘Security’] YES NO Session initialized NO NO Security initialized Undefined $loaded[‘Auth’] Existent Existent $loaded[‘Session’] Auth::initialize() Auth::__construct()
  18. 18. Components - Others <ul><li>$Component->enabled = boolean </li></ul><ul><li>SessionComponent::__construct($base) </li></ul><ul><li>Workaround double initialized </li></ul><ul><li>Import original settings </li></ul>AliasComponent
  19. 19. Hack helpers
  20. 20. Helpers <ul><li>Replaces mapped objects </li></ul><ul><li>$view::loaded[$key] </li></ul><ul><ul><li>Reference to object </li></ul></ul><ul><li>Hook timing </li></ul><ul><ul><li>beforeRender() </li></ul></ul><ul><li>View::_loadHelpers() </li></ul>AliasHelper
  21. 21. Hacks Models
  22. 22. Models <ul><li>ClassRegistry::init() </li></ul><ul><li>alias option </li></ul><ul><li>Example </li></ul><ul><ul><li>ClassRegistry::init(array( ‘class’ => ‘MockPost’, ‘alias’ => ‘Post’, )) </li></ul></ul><ul><li>Initialization timing </li></ul><ul><ul><li>Before Controller::constructClasses </li></ul></ul>
  23. 23. Hacks CakeRoute
  24. 24. CakeRoute <ul><li>From 1.3 </li></ul><ul><li>(Plugin | App)/libs/routes/my_route.php </li></ul><ul><li>App::import(‘Lib’, ‘routes/MyRoute’) </li></ul><ul><li>Router::connect(…, …, array(‘routeClass’ => ‘MyRoute’)) </li></ul><ul><li>class MyRoute extends CakeRoute </li></ul><ul><li>Implement methods </li></ul><ul><ul><li>parse() </li></ul></ul><ul><ul><li>match() </li></ul></ul><ul><ul><li>ETC… </li></ul></ul>
  25. 25. CakeRoute <ul><li>parse() </li></ul><ul><ul><li>Parsing given URL to parameters. </li></ul></ul><ul><ul><li>Helping additional parameters </li></ul></ul>
  26. 26. CakeRoute <ul><li>match() </li></ul><ul><ul><li>Convert parameters to proper URL. </li></ul></ul><ul><ul><li>Reverse Routing </li></ul></ul><ul><ul><li>Helping generation of URL </li></ul></ul>
  27. 27. CakeRoute <ul><li>Example </li></ul><ul><ul><li>Mark Story wrote great example on his BLOG </li></ul></ul><ul><ul><li>I added reverse routing </li></ul></ul>
  28. 28. Engines
  29. 29. Cache <ul><li>(Plugin | App)/libs/cache/my_cache.php </li></ul><ul><li>Cache::config(‘default’, array(‘engine’ => MyCache)) </li></ul><ul><li>class MyCache extends CacheEngine </li></ul><ul><li>Implement methods </li></ul><ul><ul><li>write() </li></ul></ul><ul><ul><li>read() </li></ul></ul><ul><ul><li>delete() </li></ul></ul>
  30. 30. CakeLog <ul><li>From 1.3 </li></ul><ul><li>(Plugin | App)/libs/log/my_logger.php </li></ul><ul><li>CakeLog::config(‘my’, array(‘engine’ => MyCache)) </li></ul><ul><li>class MyLogger </li></ul><ul><li>Implement methods </li></ul><ul><ul><li>write() only </li></ul></ul><ul><li>Example </li></ul><ul><ul><li>if($type == ‘error’) </li></ul></ul><ul><ul><li>file logging and mail to admin </li></ul></ul>
  31. 31. Conclusion <ul><li>Hacks rarely needed? </li></ul><ul><li>CakePHP is realy needed? </li></ul><ul><li>Learn Possible/Impossible </li></ul><ul><li>CakePHP2.0 features -> alias </li></ul>

×