Making the most of 2.2
-
Upload
markstory -
Category
Technology
-
view
2.884 -
download
5
description
Transcript of Making the most of 2.2
![Page 1: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/1.jpg)
MAKING THE MOST OF 2.2MARK STORY
@MARK_STORY
![Page 2: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/2.jpg)
PACKING IN THE GOOD2.0.0 was release October 18, 2011Since then 2.1, 2.2, and 2.3 have been released or started.Over 20 releases since 2.0.0.Highest release velocity ever for CakePHP.
![Page 3: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/3.jpg)
FOCUS ON PROBLEMSWe've tried to keep releases focused on solving real world problems
developers have everyday.
Make upgrading as easy as possible.
![Page 4: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/4.jpg)
VIEW BLOCKSPROBLEM
Multiple similar views would often contain repeated structuralHTML.Apps suffered from element-itis to keep HTML DRY.Piles of elements make code hard to follow and understand.
![Page 5: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/5.jpg)
Inspired by blocks in Jinja/Twig.Allows you to create slots/blocks in layouts or parent templates.Helps keep views/layouts more DRY by letting you createextensible HTML content.Replaces annoying magic variables like $scripts_for_layoutand $content_for_layout.
![Page 6: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/6.jpg)
EXAMPLEParent wrapper view with a child view
![Page 7: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/7.jpg)
PARENT VIEW<h1 class="content-title"><?= $this->fetch('title'); ?></h1><div class="content"><?= $this->fetch('content'); ?></div><div class="sidebar"><?= $this->fetch('sidebar'); ?></div><?php if ($this->fetch('pagination')): ?><div class="pagination"><?= $this->fetch('pagination'); ?></div><?php endif; ?>
![Page 8: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/8.jpg)
CHILD VIEW<?php $this->extend('../common/sidebar.ctp'); ?><?php $this->assign('title', 'Product list'); ?><?php $this->start('content'); ?><p>This is the content</p><?php $this->end(); ?>
<?php $this->start('sidebar'); ?><p>This is a sidebar</p><?php $this->end(); ?>
![Page 9: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/9.jpg)
JSON & XML VIEWSPROBLEM
Previously creating JSON and XML views that just serialized datawas a pain.Tons of repetitive views and layout files required.
![Page 10: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/10.jpg)
Two view classes that allow you to easily serialize data for simpleuses.Special _serialize view variable defines which view variablesshould be serialized.You can also use normal view files if you need to massage data first.Integrates well with existing features like exception handling andRequestHandlerComponent.
![Page 11: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/11.jpg)
EXAMPLE<?php// In a controller.function index() { $this->set('tasks', $this->paginate()); $this->set('_serialize', array('tasks'));}
![Page 12: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/12.jpg)
HASH CLASSPROBLEM
Set is full of inconsistencies. Both in the API and path selectorsyntax.Set::extract() while powerful, is slow and insane inside.xpath-ish syntax full of un-fixable bugs and not supported in mostmethods.
![Page 13: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/13.jpg)
Hash implements >90% of Set's API.All methods have a consistent signature.The same dot notation features are supported everywhere.Up to 1.6x faster on extract().Most methods are faster as well.
![Page 14: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/14.jpg)
PERFORMANCE COMPARISONSDo a similar operation 1000 times, on the same data.
![Page 15: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/15.jpg)
Hash::extract($d, '{n}.Article.id') 0.215131998Set::extract('/Article/id', $d) 0.237193821.1x improvement
![Page 16: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/16.jpg)
Hash::extract($d, '{n}.Comment.{n}.id') 0.173635005Set::extract('/Comment/id', $d) 0.2019209861.1x improvement
![Page 17: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/17.jpg)
Hash::maxDimensions($d) 0.075587987Set::countDim($d, true) 0.5755231387.6x improvement
![Page 18: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/18.jpg)
API CONSISTENCYEvery method takes an array of data as the first argument.Second argument is always one or more paths.A consistent API is easier to document, understand and remember.
![Page 19: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/19.jpg)
CAKETIME & CAKENUMBERPROBLEM
TimeHelper, NumberHelper and TextHelper have some veryuseful methods.But they are all trapped in a helper.
![Page 20: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/20.jpg)
Expose non HTML related features as a utility library.Greatly improve timezone handling.New features for testing & working with datetimes.
![Page 21: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/21.jpg)
EXAMPLE<?phpApp::uses('CakeTime', 'Utility');App::uses('CakeNumber', 'Utility');
$utc = CakeTime::toServer($datetime, 'America/Toronto');$today = CakeTime::isToday($timestamp);
$result = CakeNumber::toReadableSize($oneTerabyte);
![Page 22: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/22.jpg)
LOGGING++PROBLEM
Granular logging based on application section was impossible.Log messages were simply broadcast to every connected logger.
![Page 23: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/23.jpg)
Borrowed idea of logging 'scopes' from python's logging module.Log messages can be tagged with scopes.Only loggers interested in those scopes will get scoped messages.
![Page 24: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/24.jpg)
ATTACH A LOGGER WITH A SCOPE<?phpCakeLog::config('payments', array( 'engine' => 'Email' 'scopes' => array('payments', 'billing'), 'to' => '[email protected]'));
![Page 25: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/25.jpg)
LOG MESSAGES WITH A SCOPE<?phptry { $gateway->process($payment);} catch (PaymentException $e) { CakeLog::error( 'Transaction failed ' . $e->getMessage(), array('payments', 'billing') );}
![Page 26: Making the most of 2.2](https://reader033.fdocuments.net/reader033/viewer/2022052523/556699bed8b42a51558b5605/html5/thumbnails/26.jpg)
NOW TO JOSE