Skip to content

Commit

Permalink
Merge pull request #52 from JonathanO/master
Browse files Browse the repository at this point in the history
Avoid reparsing types repeatedly.
  • Loading branch information
JonathanO committed May 1, 2014
2 parents d2c2a6e + 53ef9ba commit 98a5e5f
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 99 deletions.
11 changes: 6 additions & 5 deletions lib/Weasel/JsonMarshaller/Config/ClassAnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Weasel\JsonMarshaller\Config\IAnnotations\IJsonAnyGetter;
use Weasel\JsonMarshaller\Config\IAnnotations\IJsonAnySetter;
use Weasel\JsonMarshaller\Config\IAnnotations\IJsonTypeInfo;
use Weasel\JsonMarshaller\Utils\TypeParser;

/**
* Load the configuration for a given class from annotations
Expand Down Expand Up @@ -137,7 +138,7 @@ protected function _configureGetter(\ReflectionMethod $method, IJsonProperty $pr
throw new \Exception("Serialization for property of name $property has already been configured.");
}
$getterConfig->method = $name;
$getterConfig->type = $propertyConfig->getType();
$getterConfig->type = TypeParser::parseType($propertyConfig->getType(), true);

$this->config->serialization->properties[$property] = $getterConfig;
}
Expand Down Expand Up @@ -169,7 +170,7 @@ protected function _configureSetter(\ReflectionMethod $method, IJsonProperty $pr
}
$setterConfig = new Deserialization\SetterDeserialization();
$setterConfig->method = $name;
$setterConfig->type = $propertyConfig->getType();
$setterConfig->type = TypeParser::parseType($propertyConfig->getType(), true);
$setterConfig->typeInfo = $this->_getDeserializationTypeInfo($typeInfo, $subTypes);
$setterConfig->strict = $propertyConfig->getStrict();

Expand Down Expand Up @@ -213,7 +214,7 @@ protected function _configureCreator(\ReflectionMethod $method, IJsonCreator $cr
foreach ($creatorConfig->getParams() as $paramConfig) {
$param = new Deserialization\Param();
$param->name = $paramConfig->getName();
$param->type = $paramConfig->getType();
$param->type = TypeParser::parseType($paramConfig->getType(), true);
$param->strict = $paramConfig->getStrict();
if (!isset($param->name)) {
if (!isset($paramNames[$i])) {
Expand Down Expand Up @@ -284,7 +285,7 @@ protected function _configureProperty(\ReflectionProperty $property)
if (!isset($this->config->deserialization->properties[$propertyName])) {
$setterConfig = new Deserialization\DirectDeserialization();
$setterConfig->property = $name;
$setterConfig->type = $propertyConfig->getType();
$setterConfig->type = TypeParser::parseType($propertyConfig->getType(), true);
$setterConfig->typeInfo = $this->_getDeserializationTypeInfo($typeInfo, $subTypes);

$this->config->deserialization->properties[$propertyName] = $setterConfig;
Expand All @@ -294,7 +295,7 @@ protected function _configureProperty(\ReflectionProperty $property)
if (!isset($this->config->serialization->properties[$propertyName])) {
$getterConfig = new Serialization\DirectSerialization();
$getterConfig->property = $name;
$getterConfig->type = $propertyConfig->getType();
$getterConfig->type = TypeParser::parseType($propertyConfig->getType(), true);

/**
* @var Annotations\JsonInclude $includer
Expand Down
19 changes: 19 additions & 0 deletions lib/Weasel/JsonMarshaller/Config/Type/ListType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Weasel\JsonMarshaller\Config\Type;

use Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonProperty;

class ListType extends Type {

/**
* @var Type
* @JsonProperty(type="\Weasel\JsonMarshaller\Config\Type\Type")
*/
public $valueType;

function __construct($valueType = null)
{
$this->valueType = $valueType;
}

}
20 changes: 20 additions & 0 deletions lib/Weasel/JsonMarshaller/Config/Type/MapType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Weasel\JsonMarshaller\Config\Type;

use Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonProperty;

class MapType extends ListType {

/**
* @var Type
* @JsonProperty(type="\Weasel\JsonMarshaller\Config\Type\Type")
*/
public $keyType;

function __construct($keyType = null, $valueType = null)
{
$this->keyType = $keyType;
parent::__construct($valueType);
}

}
19 changes: 19 additions & 0 deletions lib/Weasel/JsonMarshaller/Config/Type/ObjectType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Weasel\JsonMarshaller\Config\Type;

use Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonProperty;

class ObjectType extends Type {

/**
* @var string
* @JsonProperty(type="string")
*/
public $class;

function __construct($class = null)
{
$this->class = $class;
}

}
25 changes: 25 additions & 0 deletions lib/Weasel/JsonMarshaller/Config/Type/ScalarType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Weasel\JsonMarshaller\Config\Type;

use Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonProperty;
use Weasel\JsonMarshaller\Types\JsonType;

class ScalarType extends Type {

public function __construct($typeName = null) {
$this->typeName = $typeName;
}

/**
* @var string
* @JsonProperty(type="string")
*/
public $typeName;

/**
* This is a bit of a dirty hack...
* @var JsonType
*/
public $jsonType;

}
20 changes: 20 additions & 0 deletions lib/Weasel/JsonMarshaller/Config/Type/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Weasel\JsonMarshaller\Config\Type;

use Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonSubTypes;
use Weasel\JsonMarshaller\Config\DoctrineAnnotations\JsonTypeInfo;


/**
* Class Type
* @package Weasel\JsonMarshaller\Config\Type
* @JsonSubTypes({
* @JsonSubTypes\Type("\Weasel\JsonMarshaller\Config\Type\ListType"),
* @JsonSubTypes\Type("\Weasel\JsonMarshaller\Config\Type\MapType"),
* @JsonSubTypes\Type("\Weasel\JsonMarshaller\Config\Type\ScalarType"),
* })
* @JsonTypeInfo(use=JsonTypeInfo::ID_NAME, include=JsonTypeInfo::AS_PROPERTY, property="type")
*/
abstract class Type {

}
Loading

0 comments on commit 98a5e5f

Please sign in to comment.