Rework export#143
Conversation
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function normalize($object, $format = null, array $context = []): array |
There was a problem hiding this comment.
I would have help to rework this part. Let me know what seems the better for you
There was a problem hiding this comment.
Do you mean you would need help?
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
| */ | ||
| class ClassMetadataRegistry |
There was a problem hiding this comment.
Need help to find better naming, better namespace
There was a problem hiding this comment.
Could you please add a description of this class. This will probably help with the naming 😉
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
| */ | ||
| class ReflectionClassRegistry |
There was a problem hiding this comment.
Need help to find better naming and better namespace
There was a problem hiding this comment.
Same comment than previous class
There was a problem hiding this comment.
ClassMetadataRegistry
jmleroux
left a comment
There was a problem hiding this comment.
Could you please add a description on this PR to help the review. And if you want, we can do a mob review IRL
|
|
||
| /** | ||
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) |
There was a problem hiding this comment.
Please add a short description of this class features
| /** @var NormalizerInterface */ | ||
| protected $transNormalizer; | ||
|
|
||
| /** @var array */ |
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function normalize($object, $format = null, array $context = []): array |
There was a problem hiding this comment.
Do you mean you would need help?
| { | ||
| $this->skippedFields = $skippedFields; | ||
| } | ||
| } No newline at end of file |
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
| */ | ||
| class ClassMetadataRegistry |
There was a problem hiding this comment.
Could you please add a description of this class. This will probably help with the naming 😉
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
| */ | ||
| class ReflectionClassRegistry |
There was a problem hiding this comment.
Same comment than previous class
| protected $classes = []; | ||
|
|
||
| /** @var array */ | ||
| protected $properties = []; |
|
|
||
| $propertyValue = $this->propertyAccessor->getValue($object, $property); | ||
|
|
||
| if (is_object($propertyValue)) { |
There was a problem hiding this comment.
Extract in a submethod
| } | ||
|
|
||
| $csvData[$property] = implode(',', $values); | ||
| } elseif ($targetReflectionClass->implementsInterface(TranslationInterface::class)) { |
There was a problem hiding this comment.
Extract in dedicated ref data translation normalizer
| @@ -0,0 +1,71 @@ | |||
| <?php | |||
|
|
|||
| namespace Pim\Bundle\CustomEntityBundle\Reflection; | |||
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
| */ | ||
| class ClassMetadataRegistry |
| foreach ($properties as $property) { | ||
| if (in_array($property, $this->skippedFields)) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Array_diff needs to be done before loop
690df83 to
fb5c7bd
Compare
| } | ||
| } | ||
|
|
||
| $this->properties[$className] = $readableProperties; |
There was a problem hiding this comment.
$this->readableProperties[]
| $this->properties[$className] = $readableProperties; | ||
| } | ||
|
|
||
| return $this->properties[$className]; |
There was a problem hiding this comment.
return $this->readableProperties[$className];
| } | ||
|
|
||
| /** | ||
| * @param mixed $object |
There was a problem hiding this comment.
Why mixed and not object?
| * @param mixed $object | ||
| * @param string $property | ||
| * | ||
| * @return string |
| /** | ||
| * Normalized linked object property | ||
| * | ||
| * @param mixed $object |
| protected function normalizeLinkedObject($object, $property, $propertyValue, $format, $context) | ||
| { | ||
| $targetEntityClass = $this->targetEntityResolver->getTargetEntityClass($object, $property); | ||
| $targetReflectionClass = $this->classMetadataRegistry->get($targetEntityClass); |
There was a problem hiding this comment.
you should check if $targetEntityClass is null before doing that
There was a problem hiding this comment.
Yep good catch. Done on the resolver side, it throws an exception if nothing found
| } | ||
|
|
||
| /** | ||
| * Normalized linked object property |
|
|
||
| /** | ||
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) |
There was a problem hiding this comment.
Please add a short description of this class features
| * @author Romain Monceau <romain@akeneo.com> | ||
| * @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
| */ | ||
| class ClassMetadataRegistry |
| /** @var PropertyAccessorInterface */ | ||
| protected $propertyAccessor; | ||
|
|
||
| /** @var array */ |
There was a problem hiding this comment.
@var array cache for performance
| /** @var array */ | ||
| protected $classes = []; | ||
|
|
||
| /** @var array */ |
There was a problem hiding this comment.
@var array cache for performance
|
|
||
| $properties = $this->reflectionClassRegistry->getReadableProperties($object); | ||
| foreach ($properties as $property) { | ||
| if (in_array($property, $this->skippedFields)) { |
There was a problem hiding this comment.
use a filtered array instead of continue
Rework on the reference data export to handle linked objects