Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
11 / 11
Parsers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
11 / 11
 getForContentType
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 json
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 parser
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 buildJson
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
namespace PHPixie\HTTPProcessors;
class Parsers
{
    protected $contentTypeMap = array(
        'application/json' => 'json'
    );
    
    protected $parsers = array();
    
    public function getForContentType($contentType)
    {
        if(!array_key_exists($contentType, $this->contentTypeMap)) {
            return null;
        }
        
        $name = $this->contentTypeMap[$contentType];
        return $this->parser($name);
    }
    
    public function json()
    {
        return $this->parser('json');
    }
    
    protected function parser($name)
    {
        if(!array_key_exists($name, $this->parsers)) {
            $method = 'build'.ucfirst($name);
            $this->parsers[$name] = $this->$method();
        }
        
        return $this->parsers[$name];
    }
    
    protected function buildJson()
    {
        return new Parsers\Parser\JSON();
    }
}