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

PHPのスカラー型をクラスでラップして便利に使えるようにするライブラリ「Stannum」を作った話

tumugin.myskng
April 11, 2022
1.2k

 PHPのスカラー型をクラスでラップして便利に使えるようにするライブラリ「Stannum」を作った話

tumugin.myskng

April 11, 2022
Tweet

Transcript

  1. Copyright© M&A 2 M&A Twitter: @myskng (Twitter ... ...) GitHub:

    @tumugin PHP(Laravel) JavaScript TypeScript(Vue) ( Ruby Kotlin ...)
  2. Copyright© M&A 5 ) , , , , , ,,

    ,,, ... string string
  3. Copyright© M&A Ruby 7 ....? ' , , , ,

    , ,, ,,,' .split(',') .filter { |s| !s.strip.empty? } .map { |s| s.strip } .uniq => [" ", " ", " ", " "] PHP ....( )
  4. Copyright© M&A PHP 8 PHP ... $inputTags = ' ,

    , , , , ,, ,,,'; $splitTags = explode(',', $inputTags); $splitTagsWithoutEmpty = []; foreach ($splitTags as $tag) { if (trim($tag) !== '') { $splitTagsWithoutEmpty[] = trim($tag); } } $splitTagsWithoutEmptyAndDuplicate = array_unique($splitTagsWithoutEmpty); ...? ....?
  5. Copyright© M&A PHP 9 array_unique( array_map( fn(string $s) => trim($s),

    array_filter( explode(',', ' , , , , , ,,, ,,'), fn(string $s) => trim($s) !== '' ) ) ); ...😇 😇 😇
  6. Copyright© M&A 15 RFCs PHP RFC: Autoboxing https://wiki.php.net/rfc/autoboxing PHP RFC:

    Class-like Primitive Types https://wiki.php.net/rfc/class-like_primitive_types ...
  7. Copyright© M&A 20 ... tumugin/stannum PHP 7 . 4 (

    array) float/double integer string Sn => Stannum( )
  8. Copyright© M&A 21 SnString::byString(' , , , , , ,,

    ,,,') ->split(',') ->filter(fn(SnString $s) => !$s->trim()->isEmpty()) ->map(fn(SnString $s) => $s->trim()) ->distinct() ->toSnStringList() ->toStringArray(); ... PHP
  9. Copyright© M&A ... foreach ...? 23 $sushiList = SnStringList::byStringArray([ '

    ', ' ', ' ', ' ', ' ', ]); foreach ($sushiList as $sushi) { // something... }