Slide 1

Slide 1 text

Steadily developing CakePHP 4.0 #phpstudy 第134回PHP勉強会@東京 Kazuki Higashiguchi (@hgsgtk) 1

Slide 2

Slide 2 text

CakePHP user? Question 2

Slide 3

Slide 3 text

CakePHP user? Question CakePHP 4.0 is developing steadily Learn PHP through CakePHP 4.0 3

Slide 4

Slide 4 text

@hgsgtk Kazuki Higashiguchi job is … Software Engineer lang is ... PHP, Go ...etc belongs to ... BASE BANK株式会社 (BASE株式会社の100%子会社) at #phpstudy talked about … terraform / ECS / Unit Testing 4

Slide 5

Slide 5 text

Relation between $me and CakePHP ● work with CakePHP2.x ○ 2014 CakePHP 2.3 ○ 2017~ CakePHP 2.3~2.10 @BASE ● private with CakePHP3.x ○ php sample code at talks ● a contributor to CakePHP ○ cakephp/cakephp 2.x ○ cakephp/docs 3.x ○ not a member 5

Slide 6

Slide 6 text

= 6 sample code with CakePHP 3.7 https://speakerdeck.com/hgsgtk/tesutokaxin-iwojie-jue-surutesutoqu-dong-kai-fa-falseahuroti-at-p hpkanhuarensuxian-tai-2019

Slide 7

Slide 7 text

= 7 translation of cakephp3.7 migration guide https://github.com/cakephp/docs/pull/5950 https://book.cakephp.org/3.0/ja/appendices/3 -7-migration-guide.html#

Slide 8

Slide 8 text

About CakePHP Web Application Framework follow MVC(MVC2) written in PHP 2005 first released major versions (1.x/2.x/3.x) https://cakephp.org/ 8

Slide 9

Slide 9 text

CakePHP 4.0 9

Slide 10

Slide 10 text

3.4 and Path to 4.0.0 talked by Mark Story at CakeFest 2017 10 https://www.slideshare.net/markstory/cakephp-the-road-ahead

Slide 11

Slide 11 text

Announcing CakePHP 4 Strawberry 11 https://twitter.com/cakephp/status/877888565442560000

Slide 12

Slide 12 text

Work on CakePHP 4 has started! 12 https://twitter.com/cakephp/status/1003609827631947777

Slide 13

Slide 13 text

= Outline CakePHP next major version 4.0 Roadmap (https://github.com/cakephp/cakephp/wiki/4.0-Roadmap) Timeline 2017/6/11 “3.4 and path to 4.0” talked by Mark Story https://www.slideshare.net/markstory/cakephp-the-road-ahead 2017/6/23 Announcing CakePHP 4 Strawberry https://bakery.cakephp.org/2017/06/23/upcoming-cakephp-roadmap.htm l 2018/6/4 Work on CakePHP 4 started 13 CakePHP 4

Slide 14

Slide 14 text

4.x https://github.com/cakephp/cakephp/tree/4.x 14

Slide 15

Slide 15 text

Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter Typing API improvements Deprecation Cleanup 15

Slide 16

Slide 16 text

Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter Typing API improvements Deprecation Cleanup 16

Slide 17

Slide 17 text

= ● primarily be a clean-up release ● focus on removing all the deprecated features ● not add significant new features ● “CakePHP 3.6 を使用していれば簡単に移行できるようにする方針” 17 Easy upgrade

Slide 18

Slide 18 text

Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter Typing API improvements Deprecation Cleanup 18

Slide 19

Slide 19 text

= ● CakePHP 4.0 require PHP 7.1+ ● Issue#9956 4.x RFC - PHP7 only? ○ https://github.com/cakephp/cakephp/issues/9956 ● active support for 7.0 ends in late 2017 => 7.1 19 Require PHP7.1+

Slide 20

Slide 20 text

= 20 Require PHP 7.1+ { "name": "cakephp/cakephp", (omit) "require": { "php": ">=7.1.0", (omit) }, } https://github.com/cakephp/cakephp/blob/d356d363a3fa60cafab45db4e7f2ffaec5a506e1/composer.js on#L31

Slide 21

Slide 21 text

= ● Null coalesce operator (Null合体演算子) ● nullable types 21 Use new features of PHP7.1+

Slide 22

Slide 22 text

= public static function getRequest(bool $current = false): ?ServerRequest { if ($current) { $request = end(static::$_requests); return $request ?: null; } return static::$_requests[0] ?? null; } 22 Null coalesce operator and nullable type https://github.com/cakephp/cakephp/blob/45becd398ac060c9d1f379c42627a6ba81158933/src/Routi ng/Router.php#L301

Slide 23

Slide 23 text

Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter Typing API improvements Deprecation Cleanup 23

Slide 24

Slide 24 text

= use scalar type hints, strict typing as much as possible The addition of type hints should not be added if they will cause significant backwards compatibility breaks. 24 Stricter Typing https://github.com/cakephp/cakephp/wiki/4.0-Roadmap

Slide 25

Slide 25 text

= 25 scalar type hinting and strict typing getSource(); } https://github.com/cakephp/cakephp/blob/c2995a9ffc5c7dd06f67b56153db7a6cd665c17e/src/ORM/ Association/HasMany.php#L98

Slide 26

Slide 26 text

Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter Typing API improvements Deprecation Cleanup 26

Slide 27

Slide 27 text

API Improvement Features Use null instead of false for `nullable` return Support for PSR 15 middleware Implement PSR 16 ...etc 27 https://github.com/cakephp/cakephp/wiki/4.0- Roadmap

Slide 28

Slide 28 text

API Improvement Features Use null instead of false for `nullable` return Support for PSR 15 middleware Implement PSR 16 ...etc 28 https://github.com/cakephp/cakephp/wiki/4.0- Roadmap

Slide 29

Slide 29 text

= (3.x) @return string|false => 4.x @return string|null 29 Use null instead of false for `nullable` return https://github.com/cakephp/cakephp/blob/5aa16f4464a062f197eb31ab32b3862be9958cf7/src/O RM/BehaviorRegistry.php#L88 public static function className(string $class): ?string { $result = App::className($class, 'Model/Behavior', 'Behavior'); if (!$result) { $result = App::className($class, 'ORM/Behavior', 'Behavior'); } return $result; }

Slide 30

Slide 30 text

API Improvement Features Use null instead of false for `nullable` return Support for PSR 15 middleware Implement PSR 16 ...etc 30 https://github.com/cakephp/cakephp/wiki/4.0- Roadmap

Slide 31

Slide 31 text

= “ミドルウェアオブジェクトは、再利用可能で構成可能なリクエスト処理、あるいはレス ポンス構築処理の層でアプリケーションを「ラップ」する機能を提供します。” (「CakePHP3.7 books ミドルウェア」) 31 About middleware https://book.cakephp.org/3.0/en/controllers/middleware.html

Slide 32

Slide 32 text

= ● BodyParserMiddleware ● CsrfProtectionMiddleware ● EncryptedCookieMiddleware ● SecurityHeadersMiddleware ● ErrorHandlerMiddleware ● AssetMiddleware ● RoutingMiddleware 32 CakePHP middlewares

Slide 33

Slide 33 text

ぺちこん仙台2019の山岡さんの発表がとてもわかり易い 33 https://speakerdeck.com/hiro_y/phpfalsemiddlewarewo-shi-ikonasutameni

Slide 34

Slide 34 text

= PHP Standards Recommendations https://www.php-fig.org/psr/ コミュニティにて影響が大きい勧告 (決定的な「標準」というわけではない) 34 About PSR

Slide 35

Slide 35 text

PSR-7とPSR-15 について山岡さん資料内のありがたい図 35 https://speakerdeck.com/hiro_y/phpfalsemiddlewarewo-shi-ikonasutameni?slide=28

Slide 36

Slide 36 text

= ● PSR-7: HTTP message interfaces ○ https://www.php-fig.org/psr/ ○ https://github.com/php-fig/http-message ● CakePHP では 3.4 にて対応 Interfaces ● Psr\Http\Message\RequestInterface ○ https://github.com/php-fig/http-message/blob/master/src/RequestInterface.php ● Psr\Http\Message\ResponseInterface ○ https://github.com/php-fig/http-message/blob/master/src/ResponseInterface.php 36 About PSR-7

Slide 37

Slide 37 text

= ● PSR-15: HTTP Server Request Handlers ○ https://www.php-fig.org/psr/psr-15/ Interfaces ● Psr\Http\Server\RequestHandlerInterface ● Psr\Http\Server\MiddlewareInterface 37 About PSR-15

Slide 38

Slide 38 text

RequestHandlerInterface 38

Slide 39

Slide 39 text

MiddlewareInterface 39

Slide 40

Slide 40 text

40 https://twitter.com/mark_story/status/1090084761433968640

Slide 41

Slide 41 text

41 https://github.com/cakephp/cakephp/pull/12907

Slide 42

Slide 42 text

= 42 Implementing PSR-15 { "name": "cakephp/cakephp", (omit) "require": { (omit) "psr/http-client": "^1.0", "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0", (omit) }, } https://github.com/cakephp/cakephp/blob/d356d363a3fa60cafab45db4e7f2ffaec5a506e1/composer.js on#L31

Slide 43

Slide 43 text

= PSR-15をサポートしたので、自前でmiddlewareを書く際の実装に変化 43 Changes For 一般PHPer

Slide 44

Slide 44 text

= 44 Middleware before CakePHP4.x getCookie('landing_page')) { $expiry = new Time('+ 1 year'); $response = $response->withCookie('landing_page', [ 'value' => $request->here(), 'expire' => $expiry->format('U'), ]); } return $response; } }

Slide 45

Slide 45 text

= 45 Middleware implemented PSR-15 handle($request); if (!$request->getCookie('landing_page')) { $expiry = new Time('+1 year'); $response = $response->withCookie('landing_page', [ 'value' => $request->here(), 'expire' => $expiry->format('U') ]); } return $response; } }

Slide 46

Slide 46 text

API Improvement Features Use null instead of false for `nullable` return Support for PSR 15 middleware Implement PSR 16 ...etc 46 https://github.com/cakephp/cakephp/wiki/4.0- Roadmap

Slide 47

Slide 47 text

= RFC - Implement PSR16 support in Cache https://github.com/cakephp/cakephp/issues/12483 “The PSR16 interfaces define a simpler Cache interface that would allow CakePHP to leverage solutions from outside of CakePHP in the longer term if we adopt the interfaces.” 47 Implement PSR-16

Slide 48

Slide 48 text

48 https://github.com/cakephp/cakephp/pull/12591

Slide 49

Slide 49 text

Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter Typing API improvements Deprecation Cleanup 49

Slide 50

Slide 50 text

= 4.0 以後にて非推奨メソッドを削除 CakePHP3.6まであげれたら非推奨箇所を書き換えて4.0へアップデート 3.6 にて非推奨になった機能郡 https://book.cakephp.org/3.0/ja/appendices/3-6-migration-guide.html#id2 3.7 にて非推奨になった機能郡 https://book.cakephp.org/3.0/ja/appendices/3-7-migration-guide.html#id2 50 Deprecation Creanup

Slide 51

Slide 51 text

Other Core Plugin Updates and tooling DebugKit Bake Migrations Authentication Authorization ElasticSearch 51

Slide 52

Slide 52 text

52 https://twitter.com/mark_story/status/1086827718367420416

Slide 53

Slide 53 text

= 53 cakephp/bake folder structure 3.x 4.x https://github.com/cakephp/bake/tree/4.x https://github.com/cakephp/bake/tree/3.next

Slide 54

Slide 54 text

=

Slide 55

Slide 55 text

Long term support for 3.x & 2.x CakePHP 3.x ● Bug fixes for 18 months after 4.0.0. ● Security fixes for 36 months after 4.0.0 is released. CakePHP 2.x ● Bug fixes for 12 months after the release of 4.0.0. ● Security fixes for 18 months after the release of 4.0.0. 55 https://bakery.cakephp.org/2017/06/23/upcoming -cakephp-roadmap.html

Slide 56

Slide 56 text

CakeFest 56

Slide 57

Slide 57 text

= ● 2008 Orlando, FL, USA ● 2008 Buenos Aires, Argentina ● 2009 Berlin, Germany ● 2010 Chicago, IL, USA ● 2011 Manchester, UK ● 2012 Manchester, UK ● 2013 San Francisco, CA, USA ● 2014 Madrid, Spain ● 2015 New York, NY, USA ● 2016 Amsterdam, Netherlands ● 2017 New York, NY, USA ● 2019 Tokyo, Japan 57 CakeFest’s venue

Slide 58

Slide 58 text

58

Slide 59

Slide 59 text

59 https://cakefest.org/

Slide 60

Slide 60 text

60 https://cakefest.org/

Slide 61

Slide 61 text

61 https://cakefest.org/

Slide 62

Slide 62 text

スタンプラリー行脚の予定空けておきましょう 62

Slide 63

Slide 63 text

= ● CakePHP 4.0 が開発進行中、随時実装完了している箇所もあり ● CakePHP 4.0 は、 PHP7.1以降の新機能を採用していい感じ ● メジャーバージョンアップのタイミングに、中でどういう実装をしているか見ると、 PHP自体の勉強になる ● CakeFest2019に参加しよう! 63 Summary