\Google\AdsApi\AdWordsAdWordsNormalizer

Provides recursive normalization and denormalization for AdWords objects for non-SOAP services like BatchJobService and reporting, using getters and setters in a similar manner to `GetSetMethodNormalizer`. Note that, however, this normalizer doesn't support attribute groups or specifying attributes to ignore and doesn't support handling of circular references because AdWords objects don't have any such references.

Normalization normalizes objects recursively and adds the xsi:type attribute for the objects whose class is a subclass of another.

Denormalization uses type hint from the xsi:type attribute and PHP DocBlock @return to instantiate objects recursively.

AdWordsNormalizer can be used as an normalizer of Symfony's serializer:

$this->serializer = new Serializer(
    [new AdWordsNormalizer(), new ArrayDenormalizer()]);

This normalizer accepts two named callbacks that can be used to help customize how objects are normalized and denormalized - one called "normalize" and one called "denormalize".

The callbacks can be set via setCallbacks:

$adWordsNormalizer->setCallbacks([
    'normalize' => $normalizeCallback,
    'denormalize' => $denormalizeCallback
]);

The respective callback will be applied to each attribute during normalization and denormalization.

The expected callback signature is as follows:

// @param mixed $value the value to be normalized. For denormalized, the
//     type of $value is string
// @param string $type the type of $value, which can be a PHPDoc recognized
//     primitive (e.g., string, int, etc.) or the FQCN for objects
function transform($value, $type);

Summary

Methods
Properties
Constants
__construct()
normalize()
denormalize()
isOneOrMany()
setCallbacks()
No public properties found
No constants found
No protected methods found
$callbacks
N/A
getReturnType()
getAdWordsNamespacePrefix()
needsRecursiveDenormalization()
$docBlockFactory
N/A

Properties

$callbacks

$callbacks :

Type

$docBlockFactory

$docBlockFactory :

Type

Methods

__construct()

__construct(\Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface  $classMetadataFactory = null,\Symfony\Component\Serializer\NameConverter\NameConverterInterface  $nameConverter = null)

Parameters

\Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface $classMetadataFactory
\Symfony\Component\Serializer\NameConverter\NameConverterInterface $nameConverter

normalize()

normalize(  $object,  $format = null,array  $context = array())

Parameters

$object
$format
array $context

denormalize()

denormalize(  $data,  $class,  $format = null,array  $context = array())

Parameters

$data
$class
$format
array $context

Throws

\UnexpectedValueException

if the getter of an attribute is not found

isOneOrMany()

isOneOrMany(array  $array): boolean

Whether the specified array represents one object or contains a list of objects. This is used after deserialization as XML lists repeat elements so when there is only one element in a list, deserialization doesn't understand that it's a list of objects. If we know something is supposed to be a list this is used to tell us that a single object needs to be wrapped in an array.

We do this by checking to see whether the specified array has only sequential numeric keys. If not, then it's an object.

Parameters

array $array

Returns

boolean —

true if this array represents one object, false if it's a list of objects or empty

setCallbacks()

setCallbacks(array  $callbacks)

Parameters

array $callbacks

getReturnType()

getReturnType(\phpDocumentor\Reflection\DocBlock  $docBlock): string|null

Gets type from the PHP document block's `@return` tag.

Parameters

\phpDocumentor\Reflection\DocBlock $docBlock

the document block to get its @return type

Returns

string|null —

the class name of the attribute or null if there exists no @return tag in the document block

getAdWordsNamespacePrefix()

getAdWordsNamespacePrefix(string  $class): string

Gets the AdWords namespace prefix of the given FQCN.

Parameters

string $class

the FQCN of class to get its namespace prefix

Returns

string —

the namespace prefix of $class

needsRecursiveDenormalization()

needsRecursiveDenormalization(  $value)

Parameters

$value