for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Perry;
class Tool
{
/**
* Parse a content-type header to a representation name
*
* @param string $contentType
* @return bool
*/
public static function parseContentTypeToRepresentation($contentType)
$matches = array();
preg_match('/^application\/(.*)\+json; charset=utf-8$/im', $contentType, $matches);
if (count($matches) == 2) {
return $matches[1];
}
return false;
* convert a representation name including version to the
* corresponding class
* @param string $inputRepresentation
* @return string
* @throws \Exception
public static function parseRepresentationToClass($inputRepresentation)
$version = substr($inputRepresentation, -2);
$representation = substr($inputRepresentation, 0, -3);
switch (substr($representation, 0, 7)) {
case "vnd.ccp": // EVE
$data = explode(".", $representation);
array_shift($data);
$classname = '\Perry\Representation\Eve\\'.$version.'\\'.$data[0];
break;
case "net.3rd": // OldApi
$classname = '\Perry\Representation\OldApi\\'.$version.'\\'.$data[0];
if (count($data) > 1) {
$classname .= '\\'.$data[1];
default:
throw new \Exception("wtf, what representation is this? ".$inputRepresentation);
return $classname;