cakephp 3.0: embracing the future
DESCRIPTION
Talk presented during PHP Matsuri 2012 in Fukuoka, Japan about the planned features and changes for CakePHP 3.0TRANSCRIPT
![Page 1: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/1.jpg)
CakePHP 3.0Embracing the future
![Page 2: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/2.jpg)
About me@jose_zap
![Page 3: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/3.jpg)
I love scuba diving
![Page 4: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/4.jpg)
And enjoy all sorts of extreme
Like rock climbing
![Page 5: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/5.jpg)
or rafting
![Page 6: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/6.jpg)
and Sky diving
![Page 7: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/7.jpg)
7 years ago...
PHP 4.3 was king
PHP 5.1 was about to be released
There was no PDO, no json extension by default, no unicode and no SPL
Object orientation was very immature and buggy in PHP
No actual frameworks on the market, there was xoops and mojavi (?)
![Page 8: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/8.jpg)
7 years ago...
CakePHP is released to the public to fix ALL THE THINGS
![Page 9: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/9.jpg)
A pioneer in PHP land
MVC
Convention over configuration
Object oriented
Active record like database abstraction
Secure by default
![Page 10: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/10.jpg)
Always innovating...
Unit testing
PHP implementation of multibyte extension
Command line php shells
Plugins!
Reverse routing
Behaviors, Form helper, pagination, caching, i18n and much more
2008
![Page 11: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/11.jpg)
We made it flexible
Pluggable logging system
Caching, session and javascript engines
Localized validation
Routing with custom classes
Configurable paths
2010
![Page 12: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/12.jpg)
Even more flexible and reliable!
PHP 5.2
Customizable error handlers
Pluggable Auth component and email system
PHPUnit
PDO
Request and Response objects
2011
![Page 13: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/13.jpg)
Even more feature rich yet faster
View blocks
Content-type aware view classes
Easier HTTP caching
Configuration engines
Middleware (Dispatcher filters)
Generic events system
2012
![Page 14: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/14.jpg)
Coming soon..
CakePHP 2.3
PHP 5.4 local server
Better encryption strategies for authentication
Tons of small fixes that will just make you happier
2012
![Page 15: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/15.jpg)
An increasing debt...
Model layer is basically the same since PHP 4
No namespace support
Inflexible in some parts due to original PHP object restrictions
It could be faster
Sometimes encourages bad coding practices
![Page 16: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/16.jpg)
Time to go back to the future
![Page 17: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/17.jpg)
Who needs PHP 5.3?
Let’s go with 5.4 all the way!
![Page 18: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/18.jpg)
PHP 5.4, what we’re after
Traits, they seem like a good way of implementing behaviors
Closure binding, an alternative way of injecting finders or more behaviors
JsonSerializable interface, easier web services
It’s faster!
![Page 19: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/19.jpg)
Adopt namespaces
![Page 20: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/20.jpg)
We will keep as much as possible our current way of addressing to class names (using conventions and dot notation)
Already prepared for this moment in 2.0, we are just replacing App::uses() with native “use” statements
Classes will keep their suffixes, for instances PostsController will still be named the same instead of just “Posts”
We hate the wrong slash (\)
![Page 21: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/21.jpg)
Configuration Changes
![Page 22: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/22.jpg)
More freedom and clarity for you
Unified configuration: No more Cache::config(), everything is setup in the Configure class now
Remove obscurity and still use conventions. Each step of the bootstrapping process will be handled in a separate file
![Page 23: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/23.jpg)
Example bootstrap.php file
![Page 24: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/24.jpg)
Example cache.php file
![Page 25: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/25.jpg)
Improved and faster routing
![Page 26: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/26.jpg)
Time to cut the fat
Named params are going to be removed (no more /var:value/)
Ability to set ssl, scheme, host and port in router calls
Named routes for faster lookups
Prefix routing to map subclasses
Constant reverse routing time
![Page 27: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/27.jpg)
Prefixed actions
No more mixing admin and non admin actions in the same class
Prefixed routing will map to classes inside a namespace
Instead of UsersController::admin_index() you will have App\Controller\Admin\UsersController::index()
![Page 28: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/28.jpg)
Routing example
![Page 29: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/29.jpg)
New database layer
![Page 30: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/30.jpg)
Current problems...
Frankenstein models. Is it a record or a table?
Inconsistent API. Model::read() vs. Model::find()
No Query object, only arrays
No Record object
Recursive and Containable should be kissed good bye
DboSource is dependent on the models and viceversa
![Page 31: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/31.jpg)
A shiny new database layer
Clean separation of concerns: database layer should be usable on its own
Create a rich query builder
Intelligent data types. Cross database support for database data types (bigint, uuid, datetime, array, etc.)
Pluggable. Most aspect of this layer should swappable with custom classes
![Page 32: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/32.jpg)
Usable connection object
![Page 33: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/33.jpg)
Custom data types
![Page 34: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/34.jpg)
Query Object
![Page 35: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/35.jpg)
Table Objects
Will represent the database table/collection
Responsible for actually persisting, finding, deleting records
Schema can be declared and managed here
Can be optionally created (a default object is used instead)
Will be very similar to what current CakePHP models are now
![Page 36: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/36.jpg)
Record objects
Access record data
Provide getters and setters
Access associated model data
Save, delete and update themselves
Validation
![Page 37: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/37.jpg)
Putting it all together
![Page 38: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/38.jpg)
Using records
![Page 39: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/39.jpg)
Model behaviors will be traits
Callbacks, some are table level others record level
Saving on associated objects
Undecided...
![Page 40: CakePHP 3.0: Embracing the future](https://reader033.vdocuments.mx/reader033/viewer/2022060109/55582558d8b42a5e468b519f/html5/thumbnails/40.jpg)
We need your helpto deliver faster