Cakephpstudy5 hacks

Embed Size (px)

DESCRIPTION

 

Text of Cakephpstudy5 hacks

  • 1. 5 CakePHP @Tokyo ON 2010/5/29( )

2. Files

  • http://bit.ly/cakestudy_hiromi

3. About me

  • Name: Shimizu Hiroki
  • Call me hiromi ! @hiromi2424
  • Action about CakePHP
    • Translation
    • New features report
    • TransitionComponent
    • Few Patches/Tickets
  • I love singing, Ramen andBeer!

4. INDEX

  • Introduction
  • Hacks
    • Components
    • Helpers
    • Models
    • CakeRoute
    • Engines

5. Introduction 6. Why hack?

  • Embedding Application Policy

7. Why hack?

  • Deep Debugging

8. Why hack?

  • For Stub (Mock object)

9. How hack?

  • Hook object mapping like alias
    • This session focuses this
  • Provided hook

10. Userland import

  • App/libs/*
  • Copy the file from Core to App
  • Replace, done

Dirty Hack 11. Impossible/Non-elegance

  • Static Classes
  • Basic functions

Use Lithium 12. Hacks 13. Hack components 14. Components - ACL

  • Provided hook
  • Configure::write('Acl.classname, MyAcl)
  • MyAclComponent extends AclBase
  • Implements methods
    • lots of.

15. Components - Others

  • Replaces mapped objects
  • Component::_loaded[$key]
    • Reference to object
  • Hook timing
    • Initialize()

16. Components - Others

  • Component class flow

init() initialize() startup() Configuration Mapping objects Starting process Hook 17. Components - Others

  • var $components = (Session, Auth, Security);

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. Components - Others

  • $Component->enabled = boolean
  • SessionComponent::__construct($base)
  • Workaround double initialized
  • Import original settings

AliasComponent 19. Hack helpers 20. Helpers

  • Replaces mapped objects
  • $view::loaded[$key]
    • Reference to object
  • Hook timing
    • beforeRender()
  • View::_loadHelpers()

AliasHelper 21. Hacks Models 22. Models

  • ClassRegistry::init()
  • alias option
  • Example
    • ClassRegistry::init(array( class => MockPost, alias => Post, ))
  • Initialization timing
    • Before Controller::constructClasses

23. Hacks CakeRoute 24. CakeRoute

  • From 1.3
  • (Plugin | App)/libs/routes/my_route.php
  • App::import(Lib, routes/MyRoute)
  • Router::connect(, , array(routeClass => MyRoute))
  • class MyRoute extends CakeRoute
  • Implement methods
    • parse()
    • match()
    • ETC

25. CakeRoute

  • parse()
    • Parsing given URL to parameters.
    • Helping additional parameters

26. CakeRoute

  • match()
    • Convert parameters to proper URL.
    • Reverse Routing
    • Helping generation of URL

27. CakeRoute

  • Example
    • Mark Story wrote great example on his BLOG
    • I added reverse routing

28. Engines 29. Cache

  • (Plugin | App)/libs/cache/my_cache.php
  • Cache::config(default, array(engine => MyCache))
  • class MyCache extends CacheEngine
  • Implement methods
    • write()
    • read()
    • delete()

30. CakeLog

  • From 1.3
  • (Plugin | App)/libs/log/my_logger.php
  • CakeLog::config(my, array(engine => MyCache))
  • class MyLogger
  • Implement methods
    • write() only
  • Example
    • if($type == error)
    • file logging and mail to admin

31. Conclusion

  • Hacks rarely needed?
  • CakePHP is realy needed?
  • Learn Possible/Impossible
  • CakePHP2.0 features -> alias