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.
2. Graham Weldon
• PHP developer 11 years
• CakePHP core
contributor 4 years
• Visiting Japan for 3 years
3. CandyCane
http://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
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
52. Auto-Generated Help
• Writing documentation sucks
• Using the ConsoleOptionParser gives you
help for free
• Simple to use
• Two birds with one stone
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
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
- 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