php-annotated-monthly-october-2019

Php_annotated_monthly 이미지

Roman Pronskiy가 쓰고 JetBrains에서 제공하는 월간 PHP Annotated Monthly 2019년 10월호의 번역본입니다.

이 중에서 몇 가지 제 취향껏 골라 그 안의 내용도 좀 뒤져보고 개발새발 번역해서 소개합니다.


⚡️ News & Releases

GitHub announced Dependency graph support for PHP repositories with Composer dependencies

https://github.blog/2019-09-18-dependency-graph-supports-php-repos-with-composer-dependencies/

Github에서 PHP repository를 위한 Dependency graph를 지원하기로 했습니다. composer.json과 composer.lock 안의 프로젝트에서 취약성이 발견되면, 보안 경고를 받을 수 있게 됐습니다.

public 저장소는 자동으로 알람을 받게 되고, private은 설정을 통해 가능합니다. 이를 자동으로 수정해주는 PR을 받을 수도 있습니다(베타).

Upgrading PSR interface. PHP-FIG wants your help to modernize PSRs!

https://www.php-fig.org/blog/2019/10/upgrading-psr-interfaces/

PHP에 새로운 타입이 계속 추가되지만(PHP 8에는 union type까지!) PSR은 계속 작성 당시의 PHP 버전을 기준으로 남아있습니다. 의미상 큰 변화가 없는 PSR 스펙이라면 새로 만들지 않고 기존 스펙을 최신화하려는 논의가 되고 있는데, 최신 PHP 스펙을 기준으로 PSR을 업그레이드 지원하자니 이를 지원하지 않는 라이브러리의 호환성 때문에 여러가지 방안을 고민했다고 합니다.

현재의 안은 PSR에 버전을 붙이고(v2, v3..) 여러 단계로 릴리즈 하는 것입니다. 새로운 타입을 도입할 경우 기존 PSR을 따르던 라이브러리들이 하위 호환을 해칠 수 있기 때문에(여기서는 PHP 7.2에 소개된 ‘제한적인’ 공변/반공변을 예로 듭니다), 하위 호환을 해치지 않는 수준의 PSR v2를 발표하고 라이브러리들이 v1과 v2를 모두 만족하게 반영할 시간을 줍니다. 그 뒤에 PSR v2와 호환되는 v3를 발표하고 라이브러리들이 v2와 v3에 호환되도록 시간을 줍니다. 이때 v1에는 하위호환이 깨질 수 있습니다만, 이 논의가 시작된 원인이었던 (PSR v1의 breaking change를 걱정해야할) PHP 7.2는 이미 레거시 릴리즈에 돌입했으므로 큰 문제는 되지 않을 것이라는 내용입니다.

이 방향이 맞을지 커뮤니티에 설문을 돌리고 있습니다.

PHP 7.4.0 RC3

https://externals.io/message/107366

일정에 따라 새로운 PHP 7.4 RC가 나왔습니다. 이제 PHP 7.4까지 3개의 RC만을 남겨놓고 있습니다!

security updates

변경 사항은 여기서 확인하세요.

🐘 PHP Internals

[RFC] Object Initializer

https://wiki.php.net/rfc/object-initializer

새로운 객체 초기화 문법 제안이 올라왔습니다! (targets PHP 8.0)

저자의 블로그 포스트에서 간단한 설명과 예시를 확인하실 수 있습니다.

기존의 장황한 객체 초기화 문법을

$customer = new Customer();
$customer->firstname = "John";
$customer->surname = "Doe";
$customer->phoneNo = "+1 (555) 333 222";
$customer->emailAddress = "john.doe@example.com";
$customer->dateOfBirth = DateTimeImmutable::createFromFormat("Y-m-d", "1983-01-01");

몇몇 언어에서 제공하는 것처럼 깔끔하게 정리할 수 있습니다.

$customer = new Customer {
firstname = "John",
surname = "Doe",
phoneNo = "+1 (555) 333 222",
emailAddress = "john.doe@example.com",
dateOfBirth = DateTimeImmutable::createFromFormat("Y-m-d", "1983-01-01")
};

PHP Internals News #30. 팟캐스트에서 더 자세한 이야기를 들으실 수 있습니다.

꽤나 매력적이지만, (10/9 현재 voting 단계) 찬성3에 반대18로 분위기는… 물건너 갔습니다.

[RFC] Reclassifying engine warnings

https://wiki.php.net/rfc/engine_warnings

지난 달 9월호에서 소개했던 RFC의 투표 결과에 따라 PHP 8.0에선 다음과 같은 변화가 있을 것입니다.

  • Undefined variables: Warning
  • Undefined array index: Warning
  • Division by zero: Exception. 추가로 0으로 나누는 것을 허용하는 fdiv() 함수가 추가됩니다
  • Invalid argument supplied for foreach(): Warning
  • 기타 투표를 통과한 다른 변경 사항

Nikita Popov와의 podcast 🔈에서 더 자세히 들어보실 수 있습니다. PHP Internals News #29

PHP project coordination

https://blog.jetbrains.com/phpstorm/2019/10/php-annotated-october-2019/

Internals가 또 한번 혼란스러웠지만, 좋은 일도 있었습니다. Dan Ackroyd가 현재 진행중인 논쟁과 작업을 정리하고 있습니다.

🛠 Tools

cycle/orm

https://github.com/cycle/orm

훌륭한 PHP DataMapper ORM이자 Data Modelling Engine이라고 합니다. 고전적인 PHP 어플리케이션에도, ActiveRecord 방식으로도 사용할 수 있다고 합니다. documentation도 좋습니다.

ssx/skrub

https://github.com/ssx/skrub

필요없는 파일을 삭제해서 Docker image를 작게 만드는 등 공간을 절약해주는 composer 플러그인

squizlabs/PHP_CodeSniffer 3.5.0

https://github.com/squizlabs/PHP_CodeSniffer

이제 PSR-12 스펙을 완전히 지원합니다.

voku/portable-ascii

https://github.com/voku/portable-ascii

ASCII 문자열로 변환해주는 성능 좋은 라이브러리

infection/infection 0.14.0

https://github.com/infection/infection

A framework for mutation testing in PHP. The new version adds 3 mutators, and has better performance, decreased memory consumption, and other improvements.

solodkiy/mysql-error-parser

https://github.com/solodkiy/mysql-error-parser

alecrabbit/php-console-spinner

https://github.com/alecrabbit/php-console-spinner

훌륭한 CLI spinner입니다.

php-console-spinner example

Symfony

API Platform 2.5

https://dunglas.fr/2019/09/api-platform-2-5-revamped-admin-new-api-testing-tool-next-js-and-quasar-app-generators-patch-and-json-schema-support-improved-openapi-and-graphql-support/

Revamped Admin, new API testing tool, Next.js, and Quasar app generators, PATCH and JSON Schema support, and improved support for OpenAPI and GraphQL.

shopsys/http-smoke-testing

https://github.com/shopsys/http-smoke-testing

Simple HTTP smoke-testing for your Symfony application.

The Symfony Framework Best Practices

https://symfony.com/doc/current/best_practices.html

The Symfony Framework의 Best Practice를 한곳에 모아두었습니다.

Symfony adds a String component

https://github.com/symfony/symfony/pull/33553

an OO way of dealing with strings.

Laravel

spatie/laravel-model-states

https://github.com/spatie/laravel-model-states

The package adds state support to models. It combines concepts from the state pattern and state machines.

Hunternnm/laravel-roadrunner

https://github.com/Hunternnm/laravel-roadrunner

RoadRunner에서 Laravel을 실행하기 위한 간단한 bridge입니다.

RoadRunner는 an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager라고 소개하고 있네요.

envant/fireable

https://github.com/envant/fireable

Laravel에서 attribute 변경을 우아하게 처리하는 방법. “dirty” 속성을 활용해서 직접 이벤트를 발생시키지 않고 선언적으로 구현합니다.

다음은 status가 appoved 혹은 rejected로 변함에 따라 이벤트를 발생시키는 예제.

class User extends Authenticatable
{
use FireableAttributes;

protected $fireableAttributes = [
'status' => [
'approved' => UserApproved::class,
'rejected' => UserRejected::class,
],
];
}

Laravel with docker-compose

https://medium.com/swlh/laravel-with-docker-compose-de2190569084

Laravel을 docker-compose로 구성하는 과정을 상세하게 정리했습니다.

Introducing “ddd” – a new global helper in Laravel 6

https://flareapp.io/blog/1-introducing-ddd-a-new-global-helper-for-laravel

Laravel 6를 설치하면 Ignition 1.9 이상을 사용할 수 있으므로, 기존의 dd() 헬퍼 함수와 Ignition 라이브러리를 조합하여, ddd()라는 더 편리한 헬퍼 함수를 만들었습니다.

Inertia.js and Livewire: a high-level comparison

https://sebastiandedeyne.com/inertia-js-and-livewire-a-high-level-comparison/

React나 Vue.js와는 다르게 서버 프레임웍 플러그인으로써 UI를 손쉽게 구성할 수 있게 도와주는 두 라이브러리를 비교합니다.

🎥 WRITING A GAME IN LARAVEL AND REACT – STREAM ROUNDUP WEEK 1

https://blog.hock.in/2019/09/04/writing-a-game-in-laravel-and-react-stream-roundup-week-1/

Laravel과 React.js로 deck-building 게임(뭔지 몰라서 찾아보니 이런 것이군요)을 만들어가는 과정을 유투브 스트리밍합니다. 설계하고 테스트를 작성하고 진행하는 과정이 꽤나 흥미롭네요. 스트리밍 과정에서 나온 설계 결정이나 고민을 블로그에 옮겨놓고 있습니다.

🎥 Testing Laravel

https://www.youtube.com/playlist?list=PLmwAMIdrAmK7SHlZRwc73GGjQ9AEFGu7g

Jason McCreary의 Laravel에서의 테스트 시리즈입니다.

🎥 Laracasts: Laravel 6 From Scratch.

https://laracasts.com/series/laravel-6-from-scratch

🌀 Async PHP

seregazhuk/php-watcher

https://github.com/seregazhuk/php-watcher

소스가 변경되면 PHP 어플리케이션을 재시작 해주는 패키지입니다.

🎥 Creating a RESTful API with ReactPHP

clue/reactphp-docker

https://github.com/clue/reactphp-docker

Async client for the Docker Engine API. 소개글도 읽어보세요.

💡 기타 읽을 만한 글

Matthias Noback: Using phploc for a quick code quality estimation

https://matthiasnoback.nl/2019/09/using-phploc-for-quick-code-quality-estimation-part-1/
https://matthiasnoback.nl/2019/09/using-phploc-for-quick-code-quality-estimation-part-2/

(PHPUnit도 만든) Sebastian Bergmann의 phploc은 PHP 어플리케이션의 구조와 크기를 분석하는 도구입니다. 이 툴이 보여주는 결과를 어떻게 해석할지 설명합니다.

doganoo/PHPAlgorithms

https://github.com/doganoo/PHPAlgorithms

“Cracking the Coding Interview” 시리즈의 PHP 버전입니다.

https://www.exakat.io/most-popular-php-magic-methods/

1705개의 오픈소스에서 magic method가 얼마나 쓰였는지 조사한 결과입니다. 한번이라도 프로젝트에서 선언되었다면 카운트되었습니다.

PHP most popular magic methods

여기서 알게된 사실 몇가지도 나와있는데요.

  • 모든 magic method가 꽤 많이 사용됩니다
  • 가장 많이 쓰이는 건 __construct()인데, 클래스에서 거의 의무적으로 쓰이는 것에 비해 63%밖에 쓰이지 않았다는 것은 놀랍습니다
  • __toString()가 의외로 많이 사용됩니다
  • __debugInfo()는 PHP 5.6에서 소개됐습니다
  • __get()__set()보다, __sleep()__wakeup()보다 많이 쓰입니다
  • __destruct()__construct()의 반 밖에 쓰이지 않습니다
  • __serialize()__unserialize()는 7.4에서만 사용 가능합니다. 이런 프로젝트들은 이미 호환 가능하거나 리팩토링이 필요해 보입니다.

A Detailed Explanation of Abstraction in Software Development

https://thevaluable.dev/abstraction_software_development/

추상화에 관해 심층적인 접근을 합니다.

  • 예제와 함께 추상화가 무엇인지 정의합니다
  • 소프트웨어 개발에서 찾을 수있는 다양한 종류의 추상화를 다룹니다
  • 추상화 사용의 장점과 단점을 분석합니다
  • 종종 서로 연결되어 있지만 상호 호환되지 않는, 추상화와 간접 참조의 차이점을 이해합니다

꽤 긴 글이지만 구글 번역기로 돌려봐도 어렵지 않게 이해할 수 있습니다.

Bootstrapping a CLI PHP application in Vanilla PHP

https://dev.to/erikaheidi/bootstrapping-a-cli-php-application-in-vanilla-php-4ee

순수하게 PHP 만으로 CLI 어플리케이션을 만드는 과정입니다.

gabrielrcouto/awesome-php-ffi

https://github.com/gabrielrcouto/awesome-php-ffi

PHP 7.4에 적용되는 FFI의 다양한 예제를 모아둔 사이트입니다.

Examples in this repository:

  • Game Boy Emulator
  • Game Boy Emulator with SDL2 rendering
  • GTK3 window with a button
  • Calling a function from .class Java file
  • Modifying the PHP Core to auto inject PHP Open Tag
  • Simple printf example
  • Creating window and rendering pixels with SDL2
  • SNES Emulator
  • SNES Emulator with SDL2 rendering
  • text-to-speech using Mac library
  • Other repositories about PHP FFI:

DBus access via FFI and PHP 7.4 POC

  • Driving webview using PHP 7.4 FFI
  • PHP wrapper for libsass using FFI
  • PHP TensorFlow Binding
  • FFIMe
  • A compiler. For PHP

More than RCE

https://medium.com/swlh/diving-into-unserialize-more-than-rce-d48d371db7da

RCE(Remote Code Execution) 권한을 얻는 방법에 관한 포스트 Diving into unserialize()에 이어 unserialize()의 취약점을 이용해서 인증을 피하고 SQL injection을 시도하는 방법을 소개합니다.

🔈 Podcasts

🎥 Derick Rethans streams Hacking on Xdebug – If you use Xdebug, consider supporting Derick on Patreon. If you are not using Xdebug… well, you are probably working way too hard.

  • Xdebug를 사용한다면 Derick을 후원해주세요

🔈 PHP Internals News #28 – With Andreas Heigl on moving PHP documentation from SVN to Git.

🔈 PHP Internals News #27 – With Nikita Popov оn the help request for adding type declaration to builtin functions.

🔈 Voices of the ElePHPant: It’s the Booze Talking: PHP, the next 25.

💬 Community

ElePHPant.me

https://elephpant.me/

PHP의 마스코트인 ElePHPants 인형을 많이 수집한 사람의 랭킹을 보여주고 트레이드도 할 수 있는 사이트입니다. 한국에선 아직 등록한 사람이 없네요.