CakePHP 3 Cheatsheet – a handy collection of code snippets for anyone new to CakePHP 3 framework and all the changes that went into this version.
CakeFest 2015 Presentations – a convenient list of all CakeFest 2015 presentations in one place. Not sure how permanent the site is (I have a feeling this is a quick CakePHP coding experiment during the event), so hurry up and grab the links just in case, until something better comes out. There were some really good talks by the looks of it. Too bad I didn’t make it this year.
My largest claim to fame in the Open Source software just got merged in – a pull request to the phinx project, adding support for MySQL’s LONGBLOB (as well as TINYBLOB and MEDIUMBLOB). Phinx is the PHP tool for database migrations. It’s used, among others, by the CakePHP 3 framework.
The patch itself was rather simple and I was surprised that it hasn’t been done by someone else earlier (there was an open issue requesting this for more than a year). Phinx already had support for BLOB, and for TINYTEXT, MEDIUMTEXT, TEXT, and LONGTEXT. So practically all I had to do was a bit of copy-paste and find-replace. Gladly, there were some unit tests in place already, preventing me from breaking a thing or two.
What I found interesting though, wasn’t the patch itself, but the support of the CakePHP community (thank you guys!). Every few days someone (even core CakePHP developers) would “thumbs up” the pull request to draw the attention of the maintainer to it. Some people pulled the branch and tested it. Some wrote comments. That was awesome and quite inspiring!
CandyCane – Redmine ticketing system port to CakePHP
Disclaimer: I’ve written this post a few days after I came back from CakeFest 2014. Unfortunately, it is unfinished, and by now I have completely lost hope of ever finishing it. My main excuse is that the first day after CakeFest was my first working day at my new job, which completely and totally consumed me for a few months. And now, it seems like CakeFest 2014 was a few decades ago. Mostly I wanted to do two things here: list all the talks with videos and slides, which has probably been done by other people by now, and tell everyone that this was one of the best events I’ve ever attended. For those who haven’t been to one, I strongly recommend getting a ticket to CakeFest 2015, which will take place end of May in New York, USA. End of Disclaimer.
It’s been a week since I came from Madrid, where I’ve attended CakeFest 2014, a conference dedicated to CakePHP framework. Now that I’ve caught up on sleep, calmed down, and cleared out my mailbox, I have a few minutes to look back at the event and share my thoughts and impressions.
For those of you who are too busy to read the whole thing, here’s the executive summary. I had very high expectations of the conference way before I went. I knew there will be one or two core developers. I knew that there were previous events before. And I do usually expect high quality stuff from the CakePHP community. But as I high as my expectations were, the event went through the roof! It was an absolutely amazing couple of days, where I met a lot of cool people, learned a lot, and had plenty of fun! If you missed this year’s conference and you are involved in any shape or form with CakePHP, make sure you attend the next year one. Start making your arrangements now. You can thank me later.
Now for the long story…
For those of us who have been using PHP since the early version 3 days and such, here is a modern day refresher for PHP tags:
If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.
And from the comment on the same page:
Since PHP 5.4 the inline echo <?= ?> short tags are always enabled regardless of the short_open_tag (php.ini) setting.
For me personally, closing PHP tags are a part of muscle memory. I’ll have to unlearn that, I guess. And in regards to the inline echo tags, I was under the impression that they are being phased out together with the other short tags (<? … ?>). Apparently, I was wrong. They are here to stay. Which explains why there are in PSR-1, PSR-2, and in CakePHP 3 (which requires PHP 5.4.16 and fully adopts PSR-2) in particular.
Mark Story goes over a few reasons of why CakePHP 3.0 breaks compatibility in this blog post. If you are working with CakePHP or involved in any large system that lives forever, you should read those in detail. Otherwise, here is an overview:
- PHP has changed
- Ideas that didn’t work out so well
- Outdated implementations
- Improve consistency
Also, if you are working with CakePHP, you should attend the CakeFest 2014 event next week in Madrid, Spain.
I am seriously considering going to CakeFest this year. Madrid is not too far away to fly to. The event takes place over the weekend, so work stuff can be easily arranged. And it doesn’t cost too much – a 2-day conference with the 4-star hotel is only $480 USD (early bird prices until July 15th). That alone is a good deal.
But looking at the schedule, it’s even more tempting. The upcoming CakePHP v3 coverage, advances queries, testing, debugging, profiling and optimization, using CakePHP with Composer, Twitter Bootstrap, Travis CI, Selenium, AngularJS and more – these are just some of the subjects that will be covered. And the speakers are on par including core developers, community leaders, and otherwise interesting people.
As some of you might know, I’m a big fan of CakePHP framework. I’ve used it on numerous projects since the beginning of times. I’ve built projects small and large, migrated existing native PHP codebases to CakePHP and even survived a few major CakePHP upgrades – 1.2 to 2.0 comes to mind.
Currently, I am at the start of a couple of projects, which require a bit of the future support. CakePHP 2.x can handle the job now, but I’m looking more into the next 3-5 years. And that’s why I’m looking at CakePHP 3, which is still in the early development stage, with an alpha release coming not too long from now (have a look at the CakePHP 3 roadmap document). Let’s have a look at the high level goals for CakePHP 3:
CakePHP 3.0 represents a significant break in backwards compatibility. One of the largest the project has ever had. We are trying to modify existing methods and classes only where it is required. However, modernizing the ORM has caused a significant ripple effect in other parts of the framework. When making changes we are working towards a few goals:
- Adopt broader PHP community standards. Tools like composer, and PSR-0, PSR-1 have proven to be useful tools for improving interoperability. CakePHP should embrace these community standards where possible.
- Increase modularity. CakePHP has had history of being tightly coupled. We’re trying to reduce coupling and make more standalone libraries. For example the new Collections library, and Events system have no dependencies on the rest of the framework.
- Use PHP 5.4. When we started on CakePHP 3.0, this seemed ambitious. However, with the release of PHP 5.5, and impending release of PHP 5.6, it feels right on target now.
- Modernize and simplify the framework. CakePHP has accumulated numerous features over the years. By removing some features that are better implemented as plugins we make CakePHP simpler and smaller for everyone. Separating features into plugins allows greater community involvement and more rapid iteration on features.
That sounds like a lot. In times like these, migration guides are useful. With no code to migrate, such documents help migrate the knowledge. They usually answer the questions of what changed, what new stuff was added, what was removed, and where, in general, this whole thing is heading. Reading through the migration guide, here’s what I picked up for myself:
- CakePHP 3 supports Composer. This is a very welcome change!
- All of the source code has been reorganized to support PSR-4 autoloading specification. Yes, that means changes namespaces, lots and lots of backslashes, and moving files around.
- ORM has been completely rewritten. I didn’t have much trouble with the old ORM, but I guess there are better ways of doing things. Now, the Model is gone and it has been replaced with Table objects and Entities. These are somewhat logical. Table objects provide access to collections of records, while Entities provide access to individual records. More or less. It’s more flexible than that.
- Immutable configurations for logs and caching. Again, logical. Instead of changing things on the fly, unload one configuration and load another one.
- Named parameters in routing are gone now. Apparently, it was a very complicated piece of code which caused a lot of headaches. I somewhat enjoyed them in a few projects though, but can live without. Not a biggy. Furthermore, all of the routing has been reworked and will be much faster, using scoped routes, which I need to learn more about myself.
- Asset.filter is gone now. This should be handled via a plugin. Have a look at Mark Story’s Asset Compress, for example.
- Scaffolding is removed also.
That’s a pity, actually, as I used it for quick prototyping a lot. There is a possibility of a standalone plugin to provide this functionality.There will be a much more powerful Crud plugin instead.
- A few changes around encryption things. It looks like anyone brave enough to migrate an application from CakePHP 2 to CakePHP 3 will also have to decrypt/encrypt some data as well. Gladly, this is not my case currently.
- FormHelper and HtmlHelper are now much flexible with the HTML that they produce. These are great news indeed, as I’ve been a few times through pulling a CSS framework (like Twitter Bootstrap) over the CakePHP, and while it’s very possible, I had no fun at all.
- I18n is possibly being pushed more towards better support of PHP’s intl extension. (It’s still a maybe, particularly due to intl extension not being installed universally.)
- Tests are pushed more towards PHPUnit compliance.
Overall, that’s a monster of a change and it will take some reading and playing around to get used to the new ways. The earlier, the better, I guess.