Your SlideShare is downloading. ×
CakePHP 2.0 - PHP Matsuri 2011
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

CakePHP 2.0 - PHP Matsuri 2011

3,507
views

Published on

My presentation from the PHP Matsuri 2011 conference. This presentation discusses the changes in CakePHP 2.0 and goes into more detail on some of the cooler features that PHP 5 allows us, and some of …

My presentation from the PHP Matsuri 2011 conference. This presentation discusses the changes in CakePHP 2.0 and goes into more detail on some of the cooler features that PHP 5 allows us, and some of the internal restructuring.

Published in: Technology

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,507
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
38
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • - I have recently been contributing to the CandyCane project\n- Its a great opportunity to work with japanese developers\n
  • - I am learning japanese\n- People can try and talk to me in Japanese\n- I will probably have too much trouble understanding\n- Best to stick to English\n- I can write Japanese better than I can speak Japanese\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • - Ask who in the audience has worked on a moderate sized application with translation capabilities\n- Mention how messy code can get when you have lots of shortcut usage in view files\n
  • - We have made the “double underscore” shortcut function return the result by default\n- Previously it would echo out the result, unless you supplied “true” as the second parameter\n- This makes __() usage shorter\n
  • \n
  • - If you wanted to inject values into a tranlated string, you need to use sprintf()\n- This lets you provide a translatable string, without hard coding data that changes\n- We now provide sprintf functionality inside the “double underscore” shortcut function\n- Makes code easier to read and maintain\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • - If you wanted to provide a custom Authentication component\n- You have to hack in the “Auth” variable on the controller instance\n- Not very flexible\n
  • - CakePHP 2 allows you to “alias” an object.\n- Here we use the “CustomAuthComponent” with the instance variable name “Auth”\n- Just defined the className for Auth at the Controller level\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • - Example output\n
  • - Writing documentation can be a tedious job\n- The option parser can generate console help for users\n
  • \n
  • \n
  • - Copying arrays uses a lot of memory if its done a large number of times\n- We’re referencing an object instead of duplicating arrays\n- Yields memory consumption benefits\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • - Was very tightly coupled\n- Separate adapters now\n- Easier to modify and extend\n
  • \n
  • - Built in Authentication mechanisms\n
  • \n
  • - Need to do login checking within the app\n- Its a couple of extra lines\n- Not too bad, given how easy it is to customise now\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. CakePHP 新バージョン 2.0
    • 2. Graham Weldon• PHP developer 11 years• CakePHP core contributor 4 years• Visiting Japan for 3 years
    • 3. CandyCanehttp://my.candycane.jp• Recently helping with CandyCane• Project managed by Ando• Lots of good fixes and updates made recently• Good fun working with Japanese developers• Check it out!
    • 4. Learning Japanese• I am learning Japanese• You can speak “very basic” Japanese with me• But I will have lots of problems understanding• Please forgive me for any mistakes• I can write Japanese better than I can speak it :-)
    • 5. CakeFest Conference• Manchester, UK• 4 days!• ~100 attendees• People from many countries• Lots of learning• Lots of drinking
    • 6. Overview
    • 7. Major Points• No more PHP4• Refactored throughout• New Features• Faster• New Conventions
    • 8. PHP5• 5.2.6+ (Including 5.3)• Exceptions• PDO Datasources• SPL• Filters• Support for anonymous functions
    • 9. Upgrade Console• Make upgrading simpler• Do all the tedious work for you• Automate as much as possible• Its not perfect
    • 10. Conventions
    • 11. File Naming• MyClass => my_class.php
    • 12. File Naming• MyClass => my_class.php
    • 13. File Naming• MyClass => my_class.php• MyClass => MyClass.php• CamelCased Directories• “Namespace-ish” separation• Preparing for PHP 5.3 and PSR-0
    • 14. File Naming• Singular directory names• Model/Behavior/MyBehavior.php• View/Helper/MyHelper.php
    • 15. Moved App* Classes• Model/AppModel.php• Controller/AppController.php
    • 16. New Class Loader• Goodbye to App::import()• Say Hello to App::uses()• Similar functionality• Looks like PHP 5.3 use keyword
    • 17. App::uses Example
    • 18. App::uses Example App::uses( ClassName, Package/SubPackage );
    • 19. App::uses Example App::uses( ClassName, Package/SubPackage );
    • 20. App::uses Example App::uses( ClassName, Package/SubPackage );
    • 21. Configuring Packages• Use App::build() to define where packages are located• Defaults to app/Lib• Core provides defaults
    • 22. App::build()• App::PREPEND• App::APPEND• Control your insertion order• Greater flexibility
    • 23. Exceptions and Errors
    • 24. cakeError()• No more cakeError()• Replaced • Exceptions • Exception Handlers• Much better!
    • 25. Benefits• Extensible error handling• Common sense default exceptions• Configurable handling• PHP 5.3 awesomeness (if you want)
    • 26. Custom Rendering
    • 27. PHP 5.3?
    • 28. We’re web developers• HTTP Exceptions• Named as you would expect• CakeException for development errors • Shows as Error 500 in production
    • 29. HTTP Exceptions• All the common HTTP Errors are built in• Renderer handles display and output
    • 30. Example
    • 31. Internationalization
    • 32. I18n Shortcut• Simpler• Returns by default• Automatic sprintf() functionality
    • 33. Return by default• CakePHP 1.x
    • 34. Return by default• CakePHP 1.x• CakePHP 2+
    • 35. sprintf() built in• CakePHP 1.x
    • 36. sprintf() built in• CakePHP 1.x• CakePHP 2+
    • 37. Collections
    • 38. CakePHP 1.x• Previously all extensions worked differently • Helpers • Behaviors • Components • Tasks• No common interface / API
    • 39. CakePHP 2.x• Collection objects to manage them• HelperCollection, TaskCollection, BehaviorCollection, ComponentCollection• Similar functionality, same API• Easy to use and extend
    • 40. Responsibilities• Load objects when required• Unload objects• Alias objects• Manage callbacks
    • 41. Object Loading• $this->Html now available• The same API exists for other collections: • Behaviors • Components • Tasks
    • 42. Aliasing• Handy for providing custom functionality• Used to be annoying to “override” defaults• Possible, but not an elegant solution
    • 43. CakePHP 1.x
    • 44. CakePHP 2.x
    • 45. Global usage• Once an alias is defined, its used everywhere• Anything else accessing $this->Auth would use CustomAuthComponent
    • 46. More control with Collections• Unload• Disable• Enable
    • 47. Console
    • 48. Console Changes• Console now has a home • app/Console• Coloured output• Better input handling• Generated help• Various output formats
    • 49. Colour• Simple markup to colourise your output • Warning • Error • Info • Question • ... and more
    • 50. Simple markup
    • 51. Colour
    • 52. Auto-Generated Help• Writing documentation sucks• Using the ConsoleOptionParser gives you help for free• Simple to use• Two birds with one stone
    • 53. ConsoleOptionParser
    • 54. Request &Response
    • 55. CakeRequest• All request information in a single place• Use $this->request everywhere• Memory use is lower • No more copies of copies of copies of arrays all over the place• Backwards compatible interface
    • 56. CakeResponse• Again, consolidate logic to a single location• Use $this->response everywhere• Backwards compatibility provided
    • 57. Sessions
    • 58. Sessions• Remove duplicated code (DRY)• Shouldn’t be always included (1.3 fix)• Modelise data handling• Access anywhere• Allow simple customisation• Separate Caching, Database, etc.
    • 59. Sessions SessionHandlerDatabase Cache PHP
    • 60. Sessions SessionHandlerDatabase Cache PHP
    • 61. Sessions SessionHandlerDatabase Cache PHP My Custom Engine
    • 62. Sessions SessionHandlerDatabase Cache PHP Cake Session My Custom Engine Handler Interface
    • 63. AuthenticationAuthorization
    • 64. AuthComponent AuthComponentAuthentication Authorization
    • 65. AuthComponent• No more magic logins• No more magic hashing• Easier to understand the workflow• Easier to extend• Easier to modify
    • 66. Authentication• Form• HTTP Basic• HTTP Digest• Custom
    • 67. Authorization• Controller• Action (ACL)• CRUD (ACL)• Custom
    • 68. Example Login
    • 69. Email
    • 70. EmailComponent• No longer a component• Set of separate classes• Easily used from Models and Consoles• Component is deprecated
    • 71. Email Example
    • 72. Email Example In Models!
    • 73. Unit Testing
    • 74. Unit Testing• PHPUnit is the de-facto standard for PHP• SimpleTest has less features• SimpleTest was not PHP5 ready when we started• PHPUnit offers greater features• More flexibility in testing
    • 75. Performance
    • 76. Performance• All round increases in performance • Lazy Loading • New Conventions => Less Inflector • Simpler dispatch • Persistent DBO cache
    • 77. Benchmark “Hello World”Benchmarks courtesy of Mark Story
    • 78. Benchmark “Basic Blog”Benchmarks courtesy of Mark Story
    • 79. Resources & Links
    • 80. CakePHP 2 Documentation• Book for CakePHP 2 • http://book.cakephp.org/2.0/ja/ • We need help for Japanese! • Hiromi helping
    • 81. CakePHP 2 API• API is already available • http://api20.cakephp.org• Updated every time a build succeeds• Automated + up to date
    • 82. CakePHP 2Continuous Integration• We are using Jenkins• Automated builds and reporting• Better quality framework• Consistent testing• http://ci.cakephp.org
    • 83. 質問はありますか?
    • 84. ありがとう