Skip to content

Instantly share code, notes, and snippets.

View MugeSo's full-sized avatar

TANAKA Koichi MugeSo

View GitHub Profile
@MugeSo
MugeSo / gist:1626063
Created January 17, 2012 10:06
$hoge.foo(); on php without any errors.
error_reporting(E_ALL);
function foo(){}
class Hoge{ public function __toString(){return "a";}}
$hoge = new Hoge();
$hoge.foo();// Success!
# language: ja
フィーチャ: 検索機能
欲しい商品を見つけるために
会員または非会員として
商品を検索できる
シナリオ: カメラを検索する
前提 "ショッピングトップ" を表示している
もし "検索窓" に "カメラ" と入力する
かつ "検索" ボタンをクリックする
$ behat
フィーチャ: 検索機能
欲しい商品を見つけるために
会員または非会員として
商品を検索できる
シナリオ: カメラを検索する # features/search.feature:7
前提 "ショッピングトップ" を表示している
もし "検索窓" に "カメラ" と入力する
かつ "検索" ボタンをクリックする
@MugeSo
MugeSo / gist:3148548
Created July 20, 2012 03:58
Render a view without asking.
<?php
interface HearerInterface
{
public function retain($key, $value);
}
interface SelfExpressableInteface
{
public function expressSelf(HearerInteface $hearer);
}
@MugeSo
MugeSo / FeatureContext.php
Created October 29, 2012 02:41
How to use "Diggin - Guzzle AutoCharsetEncoding plugin" with Behat MinkExtension
use Behat\MinkExtension\Context\MinkContext;
use Diggin\Bridge\Guzzle\AutoCharsetEncodingPlugin\AutoCharsetEncodingPlugin;
class FeatureContext extends MinkContext
{
/* ommitted */
/**
* @BeforeScenario
@MugeSo
MugeSo / gist:4221423
Created December 6, 2012 02:45
TemporaryInternalEncoding
<?php
class TemporaryInternalEncoding
{
private $_originalEncoding;
public function __construct($encoding)
{
$this->_originalEncoding = mb_internal_encoding();
mb_internal_encoding($encoding);
}
@MugeSo
MugeSo / ReadableCodeExample.php
Last active December 10, 2015 02:58
Readable code example.
<?php
class Person
{
/** @var Person */
private $_partner;
/** @var Culture */
private $_culture;
@MugeSo
MugeSo / JSONPointer.js
Last active December 28, 2015 11:39
JSON Pointer [RFC6901](http://tools.ietf.org/html/rfc6901) sample implementation.
function parseJSONPointer(string) {
if (string.length < 1) {
return []; // root
}
if (string[0] !== '/') {
throw new Error('Invalid JSON Pointer syntax');
}
return string.split('/').map(function(referenceToken){
@MugeSo
MugeSo / gist:7552072
Last active December 28, 2015 19:39
今、BEAR.Sundayについて思ってることメモ

issueにするかどうか迷うレベルのことをとりあえずメモって置く場所

設計に関する疑問点

  • BEAR\Resource\ResourceInterfaceがヘッダとペイロードを持たないのはなぜだろう。 このためHTTPより語彙が少なくなり、HTTPスキームのリソースへのアクセスを$this->resourceから行おうとしたとき不都合になることも。pageスキームのリソースでもHTTPヘッダやペイロードにアクセスするのにWebContextProviderのお世話になったりしないといけない。
  • アプリケーションがルーティングを持っていて起動スクリプトで実行しているけど、なぜBEAR/Resource/Adapter/Pageに持たせていないのだろう。 page://self/hogehogeからクラス名に変換するところでもできるよね。 取りだしたクエリの処理ができないのか。でも、位置的にはこのあたりがいいと思うのだけれど。
  • 前項にも関わるけれど、uriのパス部分からクラス名に変換・逆変換を行う処理はクラスを独立させた方が良いと思う。セキュリティ設定やらなんやらでも使うと思うので。
@MugeSo
MugeSo / LocationHeaderFixer.php
Last active December 29, 2015 03:09
Locationヘッダを修正するインターセプター。 Resource\Page\から始まるクラスのonメソッドにインターセプト。 本当は、HTTPレスポンスを送信する直前でやりたいことだけど、その周辺がDIとかAOPとかできなさげだったのであきらめました。
<?php
/**
* Lisenced under MIT license
*
* Auther: MugeSo
*/
namespace Mugeso\BEAR\Sample\Interceptor;
use Ray\Aop\MethodInterceptor;
use Ray\Aop\MethodInvocation;