Merge branch '2.7' into 2.8
* 2.7: [Serializer] optims and cleanup [Form] Add translations for Tagalog
This commit is contained in:
commit
80e63e4146
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||||
|
<file source-language="en" datatype="plaintext" original="file.ext">
|
||||||
|
<body>
|
||||||
|
<trans-unit id="28">
|
||||||
|
<source>This form should not contain extra fields.</source>
|
||||||
|
<target>Ang pormang itong ay hindi dapat magkarron ng dagdag na mga patlang.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="29">
|
||||||
|
<source>The uploaded file was too large. Please try to upload a smaller file.</source>
|
||||||
|
<target>Ang ini-upload na file ay masyadong malaki. Pakiulit muling mag-upload ng mas maliit na file.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="30">
|
||||||
|
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
|
||||||
|
<target>Hindi balido ang CSRF token. Maagpasa muli ng isang pang porma.</target>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
@ -34,16 +34,16 @@ class Groups
|
|||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['value']) || !$data['value']) {
|
if (!isset($data['value']) || !$data['value']) {
|
||||||
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', get_class($this)));
|
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', \get_class($this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($data['value'])) {
|
if (!\is_array($data['value'])) {
|
||||||
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this)));
|
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', \get_class($this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data['value'] as $group) {
|
foreach ($data['value'] as $group) {
|
||||||
if (!is_string($group)) {
|
if (!\is_string($group)) {
|
||||||
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this)));
|
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', \get_class($this)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
*/
|
*/
|
||||||
final protected function appendXMLString(\DOMNode $node, $val)
|
final protected function appendXMLString(\DOMNode $node, $val)
|
||||||
{
|
{
|
||||||
if (strlen($val) > 0) {
|
if (\strlen($val) > 0) {
|
||||||
$frag = $this->dom->createDocumentFragment();
|
$frag = $this->dom->createDocumentFragment();
|
||||||
$frag->appendXML($val);
|
$frag->appendXML($val);
|
||||||
$node->appendChild($frag);
|
$node->appendChild($frag);
|
||||||
@ -260,17 +260,17 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
|
|
||||||
$value = $this->parseXmlValue($node);
|
$value = $this->parseXmlValue($node);
|
||||||
|
|
||||||
if (!count($data)) {
|
if (!\count($data)) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($value)) {
|
if (!\is_array($value)) {
|
||||||
$data['#'] = $value;
|
$data['#'] = $value;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 === count($value) && key($value)) {
|
if (1 === \count($value) && key($value)) {
|
||||||
$data[key($value)] = current($value);
|
$data[key($value)] = current($value);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@ -326,7 +326,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
return $node->nodeValue;
|
return $node->nodeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
|
if (1 === $node->childNodes->length && \in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
|
||||||
return $node->firstChild->nodeValue;
|
return $node->firstChild->nodeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($value as $key => $val) {
|
foreach ($value as $key => $val) {
|
||||||
if (is_array($val) && 1 === count($val)) {
|
if (\is_array($val) && 1 === \count($val)) {
|
||||||
$value[$key] = current($val);
|
$value[$key] = current($val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -374,7 +374,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
{
|
{
|
||||||
$append = true;
|
$append = true;
|
||||||
|
|
||||||
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
|
if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
|
||||||
foreach ($data as $key => $data) {
|
foreach ($data as $key => $data) {
|
||||||
//Ah this is the magic @ attribute types.
|
//Ah this is the magic @ attribute types.
|
||||||
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
|
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
|
||||||
@ -384,7 +384,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
$parentNode->setAttribute($attributeName, $data);
|
$parentNode->setAttribute($attributeName, $data);
|
||||||
} elseif ('#' === $key) {
|
} elseif ('#' === $key) {
|
||||||
$append = $this->selectNodeType($parentNode, $data);
|
$append = $this->selectNodeType($parentNode, $data);
|
||||||
} elseif (is_array($data) && false === is_numeric($key)) {
|
} elseif (\is_array($data) && false === is_numeric($key)) {
|
||||||
// Is this array fully numeric keys?
|
// Is this array fully numeric keys?
|
||||||
if (ctype_digit(implode('', array_keys($data)))) {
|
if (ctype_digit(implode('', array_keys($data)))) {
|
||||||
/*
|
/*
|
||||||
@ -408,7 +408,7 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
return $append;
|
return $append;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($data)) {
|
if (\is_object($data)) {
|
||||||
$data = $this->serializer->normalize($data, $this->format, $this->context);
|
$data = $this->serializer->normalize($data, $this->format, $this->context);
|
||||||
if (null !== $data && !is_scalar($data)) {
|
if (null !== $data && !is_scalar($data)) {
|
||||||
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
|
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
|
||||||
@ -477,22 +477,22 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
|||||||
*/
|
*/
|
||||||
private function selectNodeType(\DOMNode $node, $val)
|
private function selectNodeType(\DOMNode $node, $val)
|
||||||
{
|
{
|
||||||
if (is_array($val)) {
|
if (\is_array($val)) {
|
||||||
return $this->buildXml($node, $val);
|
return $this->buildXml($node, $val);
|
||||||
} elseif ($val instanceof \SimpleXMLElement) {
|
} elseif ($val instanceof \SimpleXMLElement) {
|
||||||
$child = $this->dom->importNode(dom_import_simplexml($val), true);
|
$child = $this->dom->importNode(dom_import_simplexml($val), true);
|
||||||
$node->appendChild($child);
|
$node->appendChild($child);
|
||||||
} elseif ($val instanceof \Traversable) {
|
} elseif ($val instanceof \Traversable) {
|
||||||
$this->buildXml($node, $val);
|
$this->buildXml($node, $val);
|
||||||
} elseif (is_object($val)) {
|
} elseif (\is_object($val)) {
|
||||||
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
|
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
|
||||||
} elseif (is_numeric($val)) {
|
} elseif (is_numeric($val)) {
|
||||||
return $this->appendText($node, (string) $val);
|
return $this->appendText($node, (string) $val);
|
||||||
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
|
} elseif (\is_string($val) && $this->needsCdataWrapping($val)) {
|
||||||
return $this->appendCData($node, $val);
|
return $this->appendCData($node, $val);
|
||||||
} elseif (is_string($val)) {
|
} elseif (\is_string($val)) {
|
||||||
return $this->appendText($node, $val);
|
return $this->appendText($node, $val);
|
||||||
} elseif (is_bool($val)) {
|
} elseif (\is_bool($val)) {
|
||||||
return $this->appendText($node, (int) $val);
|
return $this->appendText($node, (int) $val);
|
||||||
} elseif ($val instanceof \DOMNode) {
|
} elseif ($val instanceof \DOMNode) {
|
||||||
$child = $this->dom->importNode($val, true);
|
$child = $this->dom->importNode($val, true);
|
||||||
|
@ -55,7 +55,7 @@ class AttributeMetadata implements AttributeMetadataInterface
|
|||||||
*/
|
*/
|
||||||
public function addGroup($group)
|
public function addGroup($group)
|
||||||
{
|
{
|
||||||
if (!in_array($group, $this->groups)) {
|
if (!\in_array($group, $this->groups)) {
|
||||||
$this->groups[] = $group;
|
$this->groups[] = $group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
{
|
{
|
||||||
$class = $this->getClass($value);
|
$class = $this->getClass($value);
|
||||||
if (!$class) {
|
if (!$class) {
|
||||||
throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($value)));
|
throw new InvalidArgumentException(sprintf('Cannot create metadata for non-objects. Got: "%s"', \gettype($value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->loadedClasses[$class])) {
|
if (isset($this->loadedClasses[$class])) {
|
||||||
@ -96,10 +96,10 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
*/
|
*/
|
||||||
private function getClass($value)
|
private function getClass($value)
|
||||||
{
|
{
|
||||||
if (!is_object($value) && !is_string($value)) {
|
if (!\is_object($value) && !\is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ltrim(is_object($value) ? get_class($value) : $value, '\\');
|
return ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class LoaderChain implements LoaderInterface
|
|||||||
{
|
{
|
||||||
foreach ($loaders as $loader) {
|
foreach ($loaders as $loader) {
|
||||||
if (!$loader instanceof LoaderInterface) {
|
if (!$loader instanceof LoaderInterface) {
|
||||||
throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
|
throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', \get_class($loader)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $classes = null;
|
private $classes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
@ -53,7 +53,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not an array
|
// not an array
|
||||||
if (!is_array($classes)) {
|
if (!\is_array($classes)) {
|
||||||
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
|
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ class YamlFileLoader extends FileLoader
|
|||||||
|
|
||||||
$yaml = $this->classes[$classMetadata->getName()];
|
$yaml = $this->classes[$classMetadata->getName()];
|
||||||
|
|
||||||
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
|
if (isset($yaml['attributes']) && \is_array($yaml['attributes'])) {
|
||||||
$attributesMetadata = $classMetadata->getAttributesMetadata();
|
$attributesMetadata = $classMetadata->getAttributesMetadata();
|
||||||
|
|
||||||
foreach ($yaml['attributes'] as $attribute => $data) {
|
foreach ($yaml['attributes'] as $attribute => $data) {
|
||||||
@ -78,12 +78,12 @@ class YamlFileLoader extends FileLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['groups'])) {
|
if (isset($data['groups'])) {
|
||||||
if (!is_array($data['groups'])) {
|
if (!\is_array($data['groups'])) {
|
||||||
throw new MappingException(sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
throw new MappingException(sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data['groups'] as $group) {
|
foreach ($data['groups'] as $group) {
|
||||||
if (!is_string($group)) {
|
if (!\is_string($group)) {
|
||||||
throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,11 +36,11 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function normalize($propertyName)
|
public function normalize($propertyName)
|
||||||
{
|
{
|
||||||
if (null === $this->attributes || in_array($propertyName, $this->attributes)) {
|
if (null === $this->attributes || \in_array($propertyName, $this->attributes)) {
|
||||||
$lcPropertyName = lcfirst($propertyName);
|
$lcPropertyName = lcfirst($propertyName);
|
||||||
$snakeCasedName = '';
|
$snakeCasedName = '';
|
||||||
|
|
||||||
$len = strlen($lcPropertyName);
|
$len = \strlen($lcPropertyName);
|
||||||
for ($i = 0; $i < $len; ++$i) {
|
for ($i = 0; $i < $len; ++$i) {
|
||||||
if (ctype_upper($lcPropertyName[$i])) {
|
if (ctype_upper($lcPropertyName[$i])) {
|
||||||
$snakeCasedName .= '_'.strtolower($lcPropertyName[$i]);
|
$snakeCasedName .= '_'.strtolower($lcPropertyName[$i]);
|
||||||
@ -68,7 +68,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
|
|||||||
$camelCasedName = lcfirst($camelCasedName);
|
$camelCasedName = lcfirst($camelCasedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $this->attributes || in_array($camelCasedName, $this->attributes)) {
|
if (null === $this->attributes || \in_array($camelCasedName, $this->attributes)) {
|
||||||
return $camelCasedName;
|
return $camelCasedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
*/
|
*/
|
||||||
public function setCircularReferenceHandler($circularReferenceHandler)
|
public function setCircularReferenceHandler($circularReferenceHandler)
|
||||||
{
|
{
|
||||||
if (!is_callable($circularReferenceHandler)) {
|
if (!\is_callable($circularReferenceHandler)) {
|
||||||
throw new InvalidArgumentException('The given circular reference handler is not callable.');
|
throw new InvalidArgumentException('The given circular reference handler is not callable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
public function setCallbacks(array $callbacks)
|
public function setCallbacks(array $callbacks)
|
||||||
{
|
{
|
||||||
foreach ($callbacks as $attribute => $callback) {
|
foreach ($callbacks as $attribute => $callback) {
|
||||||
if (!is_callable($callback)) {
|
if (!\is_callable($callback)) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'The given callback for attribute "%s" is not callable.',
|
'The given callback for attribute "%s" is not callable.',
|
||||||
$attribute
|
$attribute
|
||||||
@ -220,10 +220,10 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
protected function handleCircularReference($object)
|
protected function handleCircularReference($object)
|
||||||
{
|
{
|
||||||
if ($this->circularReferenceHandler) {
|
if ($this->circularReferenceHandler) {
|
||||||
return call_user_func($this->circularReferenceHandler, $object);
|
return \call_user_func($this->circularReferenceHandler, $object);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d)', get_class($object), $this->circularReferenceLimit));
|
throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d)', \get_class($object), $this->circularReferenceLimit));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -253,13 +253,13 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
*/
|
*/
|
||||||
protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
|
protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
|
||||||
{
|
{
|
||||||
if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !is_array($context[static::GROUPS])) {
|
if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !\is_array($context[static::GROUPS])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$allowedAttributes = array();
|
$allowedAttributes = array();
|
||||||
foreach ($this->classMetadataFactory->getMetadataFor($classOrObject)->getAttributesMetadata() as $attributeMetadata) {
|
foreach ($this->classMetadataFactory->getMetadataFor($classOrObject)->getAttributesMetadata() as $attributeMetadata) {
|
||||||
if (count(array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS]))) {
|
if (array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS])) {
|
||||||
$allowedAttributes[] = $attributesAsString ? $attributeMetadata->getName() : $attributeMetadata;
|
$allowedAttributes[] = $attributesAsString ? $attributeMetadata->getName() : $attributeMetadata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
isset($context[static::OBJECT_TO_POPULATE]) &&
|
isset($context[static::OBJECT_TO_POPULATE]) &&
|
||||||
is_object($context[static::OBJECT_TO_POPULATE]) &&
|
\is_object($context[static::OBJECT_TO_POPULATE]) &&
|
||||||
$context[static::OBJECT_TO_POPULATE] instanceof $class
|
$context[static::OBJECT_TO_POPULATE] instanceof $class
|
||||||
) {
|
) {
|
||||||
$object = $context[static::OBJECT_TO_POPULATE];
|
$object = $context[static::OBJECT_TO_POPULATE];
|
||||||
@ -320,11 +320,11 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
$paramName = $constructorParameter->name;
|
$paramName = $constructorParameter->name;
|
||||||
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName) : $paramName;
|
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName) : $paramName;
|
||||||
|
|
||||||
$allowed = false === $allowedAttributes || in_array($paramName, $allowedAttributes);
|
$allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes);
|
||||||
$ignored = in_array($paramName, $this->ignoredAttributes);
|
$ignored = \in_array($paramName, $this->ignoredAttributes);
|
||||||
if (method_exists($constructorParameter, 'isVariadic') && $constructorParameter->isVariadic()) {
|
if (method_exists($constructorParameter, 'isVariadic') && $constructorParameter->isVariadic()) {
|
||||||
if ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
|
if ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
|
||||||
if (!is_array($data[$paramName])) {
|
if (!\is_array($data[$paramName])) {
|
||||||
throw new RuntimeException(sprintf('Cannot create an instance of %s from serialized data because the variadic parameter %s can only accept an array.', $class, $constructorParameter->name));
|
throw new RuntimeException(sprintf('Cannot create an instance of %s from serialized data because the variadic parameter %s can only accept an array.', $class, $constructorParameter->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,17 +58,17 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
|||||||
foreach ($reflectionMethods as $method) {
|
foreach ($reflectionMethods as $method) {
|
||||||
if ($this->isGetMethod($method)) {
|
if ($this->isGetMethod($method)) {
|
||||||
$attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3));
|
$attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3));
|
||||||
if (in_array($attributeName, $this->ignoredAttributes)) {
|
if (\in_array($attributeName, $this->ignoredAttributes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false !== $allowedAttributes && !in_array($attributeName, $allowedAttributes)) {
|
if (false !== $allowedAttributes && !\in_array($attributeName, $allowedAttributes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attributeValue = $method->invoke($object);
|
$attributeValue = $method->invoke($object);
|
||||||
if (isset($this->callbacks[$attributeName])) {
|
if (isset($this->callbacks[$attributeName])) {
|
||||||
$attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue);
|
$attributeValue = \call_user_func($this->callbacks[$attributeName], $attributeValue);
|
||||||
}
|
}
|
||||||
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
||||||
if (!$this->serializer instanceof NormalizerInterface) {
|
if (!$this->serializer instanceof NormalizerInterface) {
|
||||||
@ -108,13 +108,13 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
|||||||
$attribute = $this->nameConverter->denormalize($attribute);
|
$attribute = $this->nameConverter->denormalize($attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
$allowed = false === $allowedAttributes || in_array($attribute, $allowedAttributes);
|
$allowed = false === $allowedAttributes || \in_array($attribute, $allowedAttributes);
|
||||||
$ignored = in_array($attribute, $this->ignoredAttributes);
|
$ignored = \in_array($attribute, $this->ignoredAttributes);
|
||||||
|
|
||||||
if ($allowed && !$ignored) {
|
if ($allowed && !$ignored) {
|
||||||
$setter = 'set'.ucfirst($attribute);
|
$setter = 'set'.ucfirst($attribute);
|
||||||
|
|
||||||
if (in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) {
|
if (\in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) {
|
||||||
$object->$setter($value);
|
$object->$setter($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
|||||||
*/
|
*/
|
||||||
public function supportsNormalization($data, $format = null)
|
public function supportsNormalization($data, $format = null)
|
||||||
{
|
{
|
||||||
return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data));
|
return \is_object($data) && !$data instanceof \Traversable && $this->supports(\get_class($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,7 +166,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer
|
|||||||
*/
|
*/
|
||||||
private function isGetMethod(\ReflectionMethod $method)
|
private function isGetMethod(\ReflectionMethod $method)
|
||||||
{
|
{
|
||||||
$methodLength = strlen($method->name);
|
$methodLength = \strlen($method->name);
|
||||||
|
|
||||||
return
|
return
|
||||||
!$method->isStatic() &&
|
!$method->isStatic() &&
|
||||||
|
@ -47,7 +47,7 @@ class ObjectNormalizer extends AbstractNormalizer
|
|||||||
*/
|
*/
|
||||||
public function supportsNormalization($data, $format = null)
|
public function supportsNormalization($data, $format = null)
|
||||||
{
|
{
|
||||||
return is_object($data) && !$data instanceof \Traversable;
|
return \is_object($data) && !$data instanceof \Traversable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,14 +68,14 @@ class ObjectNormalizer extends AbstractNormalizer
|
|||||||
$attributes = $this->getAttributes($object, $context);
|
$attributes = $this->getAttributes($object, $context);
|
||||||
|
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
if (in_array($attribute, $this->ignoredAttributes)) {
|
if (\in_array($attribute, $this->ignoredAttributes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attributeValue = $this->propertyAccessor->getValue($object, $attribute);
|
$attributeValue = $this->propertyAccessor->getValue($object, $attribute);
|
||||||
|
|
||||||
if (isset($this->callbacks[$attribute])) {
|
if (isset($this->callbacks[$attribute])) {
|
||||||
$attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue);
|
$attributeValue = \call_user_func($this->callbacks[$attribute], $attributeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
||||||
@ -123,8 +123,8 @@ class ObjectNormalizer extends AbstractNormalizer
|
|||||||
$attribute = $this->nameConverter->denormalize($attribute);
|
$attribute = $this->nameConverter->denormalize($attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
$allowed = false === $allowedAttributes || in_array($attribute, $allowedAttributes);
|
$allowed = false === $allowedAttributes || \in_array($attribute, $allowedAttributes);
|
||||||
$ignored = in_array($attribute, $this->ignoredAttributes);
|
$ignored = \in_array($attribute, $this->ignoredAttributes);
|
||||||
|
|
||||||
if ($allowed && !$ignored) {
|
if ($allowed && !$ignored) {
|
||||||
try {
|
try {
|
||||||
|
@ -50,11 +50,11 @@ class PropertyNormalizer extends AbstractNormalizer
|
|||||||
$allowedAttributes = $this->getAllowedAttributes($object, $context, true);
|
$allowedAttributes = $this->getAllowedAttributes($object, $context, true);
|
||||||
|
|
||||||
foreach ($reflectionObject->getProperties() as $property) {
|
foreach ($reflectionObject->getProperties() as $property) {
|
||||||
if (in_array($property->name, $this->ignoredAttributes) || $property->isStatic()) {
|
if (\in_array($property->name, $this->ignoredAttributes) || $property->isStatic()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false !== $allowedAttributes && !in_array($property->name, $allowedAttributes)) {
|
if (false !== $allowedAttributes && !\in_array($property->name, $allowedAttributes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ class PropertyNormalizer extends AbstractNormalizer
|
|||||||
$attributeValue = $property->getValue($object);
|
$attributeValue = $property->getValue($object);
|
||||||
|
|
||||||
if (isset($this->callbacks[$property->name])) {
|
if (isset($this->callbacks[$property->name])) {
|
||||||
$attributeValue = call_user_func($this->callbacks[$property->name], $attributeValue);
|
$attributeValue = \call_user_func($this->callbacks[$property->name], $attributeValue);
|
||||||
}
|
}
|
||||||
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
||||||
if (!$this->serializer instanceof NormalizerInterface) {
|
if (!$this->serializer instanceof NormalizerInterface) {
|
||||||
@ -105,8 +105,8 @@ class PropertyNormalizer extends AbstractNormalizer
|
|||||||
$propertyName = $this->nameConverter->denormalize($propertyName);
|
$propertyName = $this->nameConverter->denormalize($propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
$allowed = false === $allowedAttributes || in_array($propertyName, $allowedAttributes);
|
$allowed = false === $allowedAttributes || \in_array($propertyName, $allowedAttributes);
|
||||||
$ignored = in_array($propertyName, $this->ignoredAttributes);
|
$ignored = \in_array($propertyName, $this->ignoredAttributes);
|
||||||
if ($allowed && !$ignored && $reflectionClass->hasProperty($propertyName)) {
|
if ($allowed && !$ignored && $reflectionClass->hasProperty($propertyName)) {
|
||||||
$property = $reflectionClass->getProperty($propertyName);
|
$property = $reflectionClass->getProperty($propertyName);
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ class PropertyNormalizer extends AbstractNormalizer
|
|||||||
*/
|
*/
|
||||||
public function supportsNormalization($data, $format = null)
|
public function supportsNormalization($data, $format = null)
|
||||||
{
|
{
|
||||||
return is_object($data) && !$data instanceof \Traversable && $this->supports(get_class($data));
|
return \is_object($data) && !$data instanceof \Traversable && $this->supports(\get_class($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,7 +132,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($data) || $data instanceof \Traversable) {
|
if (\is_array($data) || $data instanceof \Traversable) {
|
||||||
$normalized = array();
|
$normalized = array();
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
$normalized[$key] = $this->normalize($val, $format, $context);
|
$normalized[$key] = $this->normalize($val, $format, $context);
|
||||||
@ -141,12 +141,12 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||||||
return $normalized;
|
return $normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($data)) {
|
if (\is_object($data)) {
|
||||||
if (!$this->normalizers) {
|
if (!$this->normalizers) {
|
||||||
throw new LogicException('You must register at least one normalizer to be able to normalize objects.');
|
throw new LogicException('You must register at least one normalizer to be able to normalize objects.');
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($data)));
|
throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', \get_class($data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new UnexpectedValueException(sprintf('An unexpected value could not be normalized: %s', var_export($data, true)));
|
throw new UnexpectedValueException(sprintf('An unexpected value could not be normalized: %s', var_export($data, true)));
|
||||||
|
Reference in New Issue
Block a user