Skip to content

Instantly share code, notes, and snippets.

Avatar

Akihito Koriyama koriym

View GitHub Profile
@koriym
koriym / How I explained REST to my wife...
Created Jul 9, 2020
How I explained REST to my wife...
View How I explained REST to my wife...
Wife: Who is Roy Fielding?
Ryan: Some guy. He's smart.
Wife: Oh. What did he do?
Ryan: He helped write the first web servers and then did a ton of research explaining why the web works the way it does. Oh yea, his name is on the specification for the protocol that is used to get pages from servers to your browser.
Wife: How does it work?
@koriym
koriym / bearsunday-query-example.md
Last active May 31, 2020
(Ray.QueryModule) SQL実行入出力の連組配列をarray shapeでタイプする
View bearsunday-query-example.md
  • SQL実行の入出力の連想配列をarray shapeでタイプする例です
  • $ageで指定されたユーザーリストがusers_by_age.sqlのSQL実行され結果(array<array{id: string, name: string}>が返ります。
  • SQLへのリクエストと結果が補完できるようになります。(echo $user['name']name`は入力補完されます。)
  • 連想配列の使い方に間違いないかpsalmやphpstanで静的解析出来ます。
  • 入力補完にはdeep-assoc-completionが必要です。
  • array shapek記法については https://phpstan.org/writing-php-code/phpdoc-types#array-shapes を参照してください。
  • Ray.QueryModuleはSQLをSQL実行オブジェクトに変換します。@Queryはメソッドインターセプトしてidで指定したSQLを実行してメソッドの結果として返します。
  • メソッドは入出力のシグネチャーだけ利用し中身はなしでもOKです。SQL実行の結果を更新したい場合にはSQL実行結果がセットされた$bodyを変更しreturn $this;します。(BEAR.Sundayの場合)
  • psalmを使っている場合には@psalm-suppressでエラー抑制するか(メソッド内に記述がないため)、ダミーのデータを返却する必要があります。
  • Ray.Di + Ray.QueryModuleをインストールすればBEAR.Sundayでなくても使えます。
@koriym
koriym / phpstan-check-on-save.md
Created May 22, 2020 — forked from Piskvor/phpstan-check-on-save.md
Make PhpStorm check the current PHP file on save.
View phpstan-check-on-save.md

PhpStorm + PhpStan watcher

PhpStorm - Settings - Tools - File Watchers (create new)

  • File type: PHP
  • Scope: Project files
  • Program (wherever your phpstan is located, obvs.): $ContentRoot$/vendor/phpstan/phpstan/bin/phpstan
  • Arguments: analyse $FilePath$
  • Working directory (this is probably the directory with phpstan.neon): $ContentRoot$
  • Show console: on error
@koriym
koriym / example_binding_auth_intercepter.php
Last active Nov 28, 2019
公開領域だけ @publicdomain アノテーションをつけてその他は認証するための束縛
View example_binding_auth_intercepter.php
<?php
public function configure()
{
$this->bindInterceptor(
$this->matcher->logicalAnd(
$this->matcher->logicalAnd(
$this->matcher->logicalNot(
$this->matcher->annotatedWith(PublicDomain::class)
),
@koriym
koriym / SqlTest.php
Created May 16, 2019
SQLテストテンプレート
View SqlTest.php
<?php
use Aura\Sql\ExtendedPdoInterface;
use BEAR\Package\AppInjector;
use Koriym\QueryLocator\QueryLocatorInterface;
use PHPUnit\Framework\TestCase;
use Ray\Di\InjectorInterface;
use Ray\Query\RowInterface;
/**
@koriym
koriym / v8js_install_error.txt
Created Mar 15, 2019
v8js_install_error.txt
View v8js_install_error.txt
AkiBook2016:v8js akihito$ ./configure --with-php-config=/usr/local/php5/bin/php-config --with-v8js=/usr/local/opt/v8\@3.15
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
View v8js_compile_error.md
sudo pecl install v8js
downloading v8js-2.1.0.tgz ...
Starting to download v8js-2.1.0.tgz (101,553 bytes)
.......................done: 101,553 bytes
28 source files, building
running: phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
View file0.php
return function (
string $context,
string $name,
string $ip,
int $port,
int $mode = SWOOLE_BASE,
int $sockType = SWOOLE_SOCK_TCP,
array $settings = ['worker_num' => 4]
) : int {
$http = new Server($ip, $port, $mode, $sockType);
@koriym
koriym / file0.txt
Created Dec 17, 2018
macOS MojaveでLiip PHPのインストール ref: https://qiita.com/koriym/items/7c1b42338586c495089f
View file0.txt
sudo apachectl stop`
sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null`
You can’t perform that action at this time.