Skip to content

Rework export#143

Merged
fitn merged 1 commit into
masterfrom
export_refacto
Feb 2, 2018
Merged

Rework export#143
fitn merged 1 commit into
masterfrom
export_refacto

Conversation

@fitn

@fitn fitn commented Jan 23, 2018

Copy link
Copy Markdown
Contributor

Rework on the reference data export to handle linked objects

/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = []): array

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have help to rework this part. Let me know what seems the better for you

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean you would need help?

Comment thread Reflection/ClassMetadataRegistry.php Outdated
* @author Romain Monceau <romain@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class ClassMetadataRegistry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help to find better naming, better namespace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a description of this class. This will probably help with the naming 😉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target entity resolver

Comment thread Reflection/ReflectionClassRegistry.php Outdated
* @author Romain Monceau <romain@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class ReflectionClassRegistry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need help to find better naming and better namespace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment than previous class

@fitn fitn Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClassMetadataRegistry

@jmleroux jmleroux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short description of this class features

/** @var NormalizerInterface */
protected $transNormalizer;

/** @var array */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@var string[]

/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = []): array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean you would need help?

{
$this->skippedFields = $skippedFields;
}
} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Comment thread Reflection/ClassMetadataRegistry.php Outdated
* @author Romain Monceau <romain@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class ClassMetadataRegistry

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a description of this class. This will probably help with the naming 😉

Comment thread Reflection/ReflectionClassRegistry.php Outdated
* @author Romain Monceau <romain@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class ReflectionClassRegistry

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment than previous class

Comment thread Reflection/ReflectionClassRegistry.php Outdated
protected $classes = [];

/** @var array */
protected $properties = [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readableProperties


$propertyValue = $this->propertyAccessor->getValue($object, $property);

if (is_object($propertyValue)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract in a submethod

}

$csvData[$property] = implode(',', $values);
} elseif ($targetReflectionClass->implementsInterface(TranslationInterface::class)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract in dedicated ref data translation normalizer

Comment thread Reflection/ReflectionClassRegistry.php Outdated
@@ -0,0 +1,71 @@
<?php

namespace Pim\Bundle\CustomEntityBundle\Reflection;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metadata

Comment thread Reflection/ClassMetadataRegistry.php Outdated
* @author Romain Monceau <romain@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class ClassMetadataRegistry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TargetEntityResolver

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace Metadata

foreach ($properties as $property) {
if (in_array($property, $this->skippedFields)) {
continue;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array_diff needs to be done before loop

@fitn fitn force-pushed the export_refacto branch 2 times, most recently from 690df83 to fb5c7bd Compare January 30, 2018 13:08
Comment thread Metadata/ClassMetadataRegistry.php Outdated
}
}

$this->properties[$className] = $readableProperties;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->readableProperties[]

Comment thread Metadata/ClassMetadataRegistry.php Outdated
$this->properties[$className] = $readableProperties;
}

return $this->properties[$className];

@mmetayer mmetayer Jan 30, 2018

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return $this->readableProperties[$className];

Comment thread Metadata/TargetEntityResolver.php Outdated
}

/**
* @param mixed $object

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mixed and not object?

* @param mixed $object
* @param string $property
*
* @return string

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return string|null

/**
* Normalized linked object property
*
* @param mixed $object

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param object $object ?

protected function normalizeLinkedObject($object, $property, $propertyValue, $format, $context)
{
$targetEntityClass = $this->targetEntityResolver->getTargetEntityClass($object, $property);
$targetReflectionClass = $this->classMetadataRegistry->get($targetEntityClass);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should check if $targetEntityClass is null before doing that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep good catch. Done on the resolver side, it throws an exception if nothing found

}

/**
* Normalized linked object property

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalize or Normalizes


/**
* @author Romain Monceau <romain@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short description of this class features

Comment thread Reflection/ClassMetadataRegistry.php Outdated
* @author Romain Monceau <romain@akeneo.com>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
class ClassMetadataRegistry

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target entity resolver

/** @var PropertyAccessorInterface */
protected $propertyAccessor;

/** @var array */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@var array cache for performance

/** @var array */
protected $classes = [];

/** @var array */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@var array cache for performance


$properties = $this->reflectionClassRegistry->getReadableProperties($object);
foreach ($properties as $property) {
if (in_array($property, $this->skippedFields)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a filtered array instead of continue

@fitn fitn merged commit ee814bd into master Feb 2, 2018
@fitn fitn deleted the export_refacto branch February 2, 2018 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants