Symfony 2.2が出たので、LTSV encoderを対応してみた
Symfony 2.2 released!
Symfony 2.2が3/1本日リリースされた。このリリースに伴い、LTSV encoderで使用しているSymfony Serializer Componentも2.2となり、Symfony\Component\Serializer\Encoder\DecoderInterface、 Symfony\Component\Serializer\Encoder\EncoderInterface等が変更となっている。Symfony 2.1で利用可能なバージョンはLTSV encoder 0.1.0とし、Symfony 2.2で利用可能なバージョンはLTSV encoder 0.2.0とした。
What's new in Symfony Serializer 2.2 Component?
Serializer 2.2のCHANGELOGを見ると、BC BREAKとなっているのは一つで、PR #6797の変更だ。
- [BC BREAK] All Serializer, Normalizer and Encoder interfaces have been modified to include an optional
$contextarray parameter. - The XML Root name can now be configured with the
xml_root_nameparameter in the context option to theXmlEncoder. - Options to
json_encodeandjson_decodecan be passed through the context options ofJsonEncodeandJsonDecodeencoder/decoders.
encode()やdecode()などのメソッドの最後の引数にarray $context = array()が追加されている。この追加によって、コンストラクタオプションでしか渡せなかったencoderオプションをencode()、decode()等のメソッド実行時に渡せるようになった。
影響のあるInterfaceやclassはこのコミットを見るといいかもしれない。
当然のことながら、これらのinterfaceを実装しているクラスは対応する必要がある。
Updated LTSV encoder
LTSV encoderで使用していたのがDecoderInterfaceとEncoderInterfaceだったので、$contextオプションへの対応を行った。
しかし、行指向のファイルフォーマットの場合、データサイズが大きいと、行数分、あるいはレコード数分だけdecode()/encode()が実行されることになる。$contextオプションに変更がない場合に、何度もresolveContext()が実行されるとパフォーマンスに悪影響が出そうだったので(まだ比較してないが)、store_context=trueの場合は一度だけresolveContext()を実行するようにした。
What does LTSV mean?
Described at http://ltsv.org/ in English.