Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo.

Post on 19-Dec-2015

214 views 0 download

Transcript of Story of CakePHP 2.0 2011.1.17 The New Year CakePHP Study in Tokyo.

Story of CakePHP 2.0

2011.1.17

The New Year CakePHP Study in TokyoThe New Year CakePHP Study in Tokyo

About Me

Name : Shimizu Hiroki(hiromi2424)

Job : Web Developer(Freelance)

Libraries : github(Transition, ModularAuth)

Work : Translation

Hobby : Singing, Beer!!!

IntroductionIntroduction

CakePHP 2.0 has large number of enhancements

It is no longer same thing compared with 1.x

But there are many compatible stuff

Most of libraries and applications also can be migrated easily

Introduction

Summary Decoupling & Delegeting

Request & Response Auth Loading Object On The Fly Others

Various Problems Resolved Security Component Pagination More Flexible Routes Lazy Loading

Conclusion

Decoupling & DelegetingDecoupling & Delegeting

Decoupling & Delegeting

Current Requst handling

Request & Response

Lose ConsistencyHard to TestUgly WorkaroundImpossible to Inherit

Decoupling & Delegeting

Requst handling in CakePHP 2.0

Request & Response

Same ObjectCommon APIParse RequestConvenient Method

Decoupling & Delegeting

Request & Response

In Your Controller or so $this->request->here

$this->params['prefix'] // also accesible but deprecated

$this->request->data('User.name'); // returns name

$this->request->data('User.ip_address',$this->request->clientIp()

);

Decoupling & Delegeting

Response Handling in CakePHP 2.0

Request & Response

All of handling HTTP response would be done through Response object

Helps Media Rendering Download HTTP Systems

Decoupling & Delegeting

Auth's Responsibility was too heavy

Auth

Validating Post LoginLogin/Logout HandlingLoading Current UserVarious Autorization Pattern

DarkAuthOpenID and OAuth

Decoupling & Delegeting

Auth will be separated

Auth

Authentication and AuthorizationBasic, Digest Authentication is

already availableCore Team giving a try to support OpenID

Decoupling & Delegeting

ObjectCollection is available

Loading Object On The Fly

In the past, there were similar patterns to

load kinds of ObjectComponents, helpers and tasks could not be

loaded dynamically

Now Collection pattern is gathered atObjectCollection

Decoupling & Delegeting

Common API for Collections

Loading Object On The Fly

ObjectCollection load() attached() trigger() other methods

Compatible methods like attach() is alsoavailable

Decoupling & Delegeting

Loading Object On The Fly

In Your Controller $this->Components->load('Cookie', array('name' => 'MyCookie'))

In Your Component $this->Auth = $this->_Collection->load('Auth');

In You View $this->Time = $this->loadHelper('Time'); // convenient alias $this->Time = $this->Helpers->load('Time');

In your Model $this->Behaviors->load('Containable'); $this->Behaviors->attach('Containable'); // compatible

Decoupling & Delegeting

Number of classes deletege

Others

Session Handler is now objectConfigure Reader is available You can load configurations as formated you prefer,

like YAML, XML, JSON

Error Handler and Exception Renderer cakeError() was used for simulation of Exception You can specify what handler is used in core config

Custom Object allows you to develop

advanced and freely

Various Problems ResolvedVarious Problems Resolved

Various Problems Resolved

CSRF Protection enhancements

Securty Component

It was coupled with CSRF protection andform tampering safe-guards

Disabling CSRF protection meant disablingform tampering safe-guards also

It prevented generating dynamic form

These are now standalone

Various Problems Resolved

Multi-time token is available

Securty Component

There was only one-time tokenSometimes it was not useful

Now Security Component can beused practically

Various Problems Resolved

Pagination supports GET method

Pagination

Only parsing query string was supportedGenerating query string was not supported

Now GET method pagination is fully supported

Various Problems Resolved

New Paginator Options

Pagination

$maxLimit Prevent $limit being too high value

$paramType 'querystring' can be used for GET method

'convertKeys' for PaginatorHelper::options() Allows other parameters to be included

Various Problems Resolved

Behavior can have pagination methods

Pagination

There was no way to make sure what

method is available through Behaviors

on your model Model::hasMethod() is implemented

Mostly same to model methods paginate() paginateCount()

Various Problems Resolved

Array can be used as a named arguments

More Flexible Routes

Router could not handle array as named

arguments Router::url(array('named' => array()));=> named:Array /named[hoge][piyo]:fuga=> array('named[hoge][piyo]' => 'fuga')

Now deep array can be used

Various Problems Resolved

Full url can be generated

More Flexible Routes

1.3's custom routes handle only relative urlfunction match($url) {

return '/users/login';}

2.x's custom routes can handle absolute urlfunction match($url) {

return 'https://auth.example.com/users/login';}

Various Problems Resolved

Lazy Loading in sundry of places

Lazy Loading

Loading model costs too expensiveLazyModelCore supports lazy loading now Components Helpers Tasks Associated Models

Loading controller's component is not lazy

ConclusionConclusion

There are many and many other changes PHPUnit DataSource enahancements

Nesting Transaction Postgress support improved

Standardization for directory structure Static Session ... And so

Core team works hard to make compatible ways Why do you not use 2.0?