1: <?php
2:
3: namespace PHPixie\HTTPProcessors;
4:
5: class Parsers
6: {
7: protected $contentTypeMap = array(
8: 'application/json' => 'json'
9: );
10:
11: protected $parsers = array();
12:
13: public function getForContentType($contentType)
14: {
15: $contentType = explode(';', $contentType, 2);
16: $contentType = $contentType[0];
17:
18: if(!array_key_exists($contentType, $this->contentTypeMap)) {
19: return null;
20: }
21:
22: $name = $this->contentTypeMap[$contentType];
23: return $this->parser($name);
24: }
25:
26: public function json()
27: {
28: return $this->parser('json');
29: }
30:
31: protected function parser($name)
32: {
33: if(!array_key_exists($name, $this->parsers)) {
34: $method = 'build'.ucfirst($name);
35: $this->parsers[$name] = $this->$method();
36: }
37:
38: return $this->parsers[$name];
39: }
40:
41: protected function buildJson()
42: {
43: return new Parsers\Parser\JSON();
44: }
45: }
46: