Skip to content

Instantly share code, notes, and snippets.

View koriym's full-sized avatar

Akihito Koriyama koriym

View GitHub Profile
@koriym
koriym / ruleset_xml_schema.xsd
Created May 5, 2021 02:06 — forked from addiks/ruleset_xml_schema.xsd
New ruleset_xml_schema.xsd
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
targetNamespace="http://pmd.sf.net/ruleset/1.0.0"
elementFormDefault="qualified">
<xs:element name="ruleset">
<xs:complexType>
<xs:sequence>
@koriym
koriym / NotPreladerdFinder.php
Created March 10, 2021 06:27
Loader to find classes that have not been preloaded
<?php
// preloadされていないクラスを見つけるローダー
$notPreloaded = new ArrayObject();
spl_autoload_register(function (string $class) use ($notPreloaded) {
$notPreloaded[] = $class;
},
true,
true
);
@koriym
koriym / pcre2.h_not_found.md
Last active February 10, 2021 02:52
'pcre2.h' file not found on Mac Big Sur with PHP 8?
/opt/homebrew/Cellar/php/8.0.2/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 
      'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~
1 error generated.

To fix this issue, Symlink pcre2.h manually.

@koriym
koriym / meida_query.php
Last active January 31, 2021 04:28
Minimum repository pattern with AOP
<?php
// The next Rqy.Query
namespace Ray\Query\Fake\Media;
use Ray\Query\Annotation\Sql;
interface RegisterUserInterface
{
@koriym
koriym / install_arm_php.log.md
Last active November 21, 2020 10:50
Brew install log on arm Mac

php

akihito@kumaair(arm64) ~ % /opt/homebrew/bin/brew install php
Warning: You are running macOS on a arm64 CPU architecture.
We do not provide support for this (yet).
Reinstall Homebrew under Rosetta 2 until we support it.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
@koriym
koriym / php_spaceship.md
Last active November 4, 2020 10:51
PHP spaceship operator example
usort($descriptors, function (AbstractDescriptor $a, AbstractDescriptor $b): int {
    $order = ['semantic' => 0, 'safe' => 1, 'unsafe' => 2, 'idempotent' => 3];
    
    return $order[$a->type] <=> $order[$b->type]; // sort by type
});
@koriym
koriym / How I explained REST to my wife...
Created July 9, 2020 18:41
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 11:44
(Ray.QueryModule) SQL実行入出力の連組配列をarray shapeでタイプする
  • 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 05:53 — forked from Piskvor/phpstan-check-on-save.md
Make PhpStorm check the current PHP file on save.

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 November 28, 2019 00:55
公開領域だけ @publicdomain アノテーションをつけてその他は認証するための束縛
<?php
public function configure()
{
$this->bindInterceptor(
$this->matcher->logicalAnd(
$this->matcher->logicalAnd(
$this->matcher->logicalNot(
$this->matcher->annotatedWith(PublicDomain::class)
),