Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Steadily developing CakePHP 4.0 #phpstudy

Steadily developing CakePHP 4.0 #phpstudy

presentation slide for #phpstudy vol.134

original google slide document url is here.
https://docs.google.com/presentation/d/1Ad-1MngmavQq3ebN9fP4TfKmBUgUptqplUJobJeBaAc/edit?usp=sharing

Kazuki Higashiguchi

January 30, 2019
Tweet

More Decks by Kazuki Higashiguchi

Other Decks in Technology

Transcript

  1. @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
  2. 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
  3. 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
  4. 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
  5. = 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
  6. Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter

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

    Typing API improvements Deprecation Cleanup 16
  8. = • primarily be a clean-up release • focus on

    removing all the deprecated features • not add significant new features • “CakePHP 3.6 を使用していれば簡単に移行できるようにする方針” 17 Easy upgrade
  9. Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter

    Typing API improvements Deprecation Cleanup 18
  10. = • 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+
  11. = 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
  12. = 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
  13. Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter

    Typing API improvements Deprecation Cleanup 23
  14. = 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
  15. = 25 scalar type hinting and strict typing <?php declare(strict_types=1);

    namespace Cake\ORM\Association; class HasMany extends Association { public function isOwningSide(Table $side): bool { return $side === $this->getSource(); } https://github.com/cakephp/cakephp/blob/c2995a9ffc5c7dd06f67b56153db7a6cd665c17e/src/ORM/ Association/HasMany.php#L98
  16. Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter

    Typing API improvements Deprecation Cleanup 26
  17. 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
  18. 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
  19. = (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; }
  20. 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
  21. = • BodyParserMiddleware • CsrfProtectionMiddleware • EncryptedCookieMiddleware • SecurityHeadersMiddleware •

    ErrorHandlerMiddleware • AssetMiddleware • RoutingMiddleware 32 CakePHP middlewares
  22. = • 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
  23. = • 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
  24. RequestHandlerInterface 38 <?php namespace Psr\Http\Server; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; interface

    RequestHandlerInterface { public function handle(ServerRequestInterface $request): ResponseInterface; } https://github.com/php-fig/http-server-handler/blob/a557d72810470f7cf1bf5aa83523097c5c566e02/sr c/RequestHandlerInterface.php#L3
  25. MiddlewareInterface 39 <?php namespace Psr\Http\Server; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; interface

    MiddlewareInterface { public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface; } https://github.com/php-fig/http-server-middleware/blob/9aad1c57354a158e3582560cf304bcae216d87 4b/src/MiddlewareInterface.php#L15
  26. = 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
  27. = 44 Middleware before CakePHP4.x <?php namespace App\Middleware; use Cake\I18n\Time;

    use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; final class TrackingCookieMiddleware { public function __invoke( ServerRequestInterface $request, ResponseInterface $response, $next): ResponseInterface { // pass the control to next middleware $response = $next($request, $response); if (!$request->getCookie('landing_page')) { $expiry = new Time('+ 1 year'); $response = $response->withCookie('landing_page', [ 'value' => $request->here(), 'expire' => $expiry->format('U'), ]); } return $response; } }
  28. = 45 Middleware implemented PSR-15 <?php namespace App\Middleware; use Cake\I18n\Time;

    use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\MiddlewareInterface; final class TrackingCookie4xMiddleware implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { $response = $handler->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; } }
  29. 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
  30. = 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
  31. Features The CakePHP4 features Easy upgrade Require PHP 7.1+ Stricter

    Typing API improvements Deprecation Cleanup 49
  32. = <?php declare(strict_types=1); class AllCommand extends BakeCommand { public function

    execute(Arguments $args, ConsoleIo $io): ?int { } } 54 Stricter Typing https://github.com/cakephp/bake/blob/38b68f1daaeb94e3e2856d91bc3037250538f640/src/Command/Al lCommand.php#L2
  33. 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
  34. = • 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
  35. 58

  36. = • CakePHP 4.0 が開発進行中、随時実装完了している箇所もあり • CakePHP 4.0 は、 PHP7.1以降の新機能を採用していい感じ

    • メジャーバージョンアップのタイミングに、中でどういう実装をしているか見ると、 PHP自体の勉強になる • CakeFest2019に参加しよう! 63 Summary