Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Devlamynck committed Feb 28, 2024
1 parent 8528e11 commit 8ee5a7c
Show file tree
Hide file tree
Showing 13 changed files with 1,150 additions and 1,529 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php declare(strict_types=1);

namespace RichId\CsvGeneratorBundle\Annotation;
namespace RichId\CsvGeneratorBundle\Attribute;

/**
* Class CsvContentTranslationPrefix.
*
* @package RichId\CsvGeneratorBundle\Annotation
* @author Hugo Dumazeau <[email protected]>
* @copyright 2014 - 2021 RichId (https://www.rich-id.fr)
*
* @Annotation
* @Target({"PROPERTY"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class CsvContentTranslationPrefix
{
/** @var string */
public $translationPrefix;
public function __construct(
public string $translationPrefix
) {}
}

1 change: 1 addition & 0 deletions Generator/CsvGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ protected function getRowContent($object, AbstractCsvGeneratorConfiguration $con
}

$context = empty($configuration->getSerializationGroups()) ? [] : [AbstractNormalizer::GROUPS => $configuration->getSerializationGroups()];
$context[AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES] = false;
$encodedObject = $this->normalizer->normalize($object, null, $context);

foreach ($contentTranslationPrefixes as $propertyName => $contentTranslationPrefix) {
Expand Down
4 changes: 3 additions & 1 deletion Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<service id="RichId\CsvGeneratorBundle\Generator\CsvGenerator" />
<service id="RichId\CsvGeneratorBundle\Generator\CsvGeneratorInterface" alias="RichId\CsvGeneratorBundle\Generator\CsvGenerator" />

<service id="RichId\CsvGeneratorBundle\Utility\PropertiesUtility" />
<service id="RichId\CsvGeneratorBundle\Utility\PropertiesUtility">
<argument key="$extractor" type="service" id="property_info.serializer_extractor" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestSuite\TestCase\TestCase;
use RichId\CsvGeneratorBundle\Configuration\AbstractCsvGeneratorConfiguration;
use RichId\CsvGeneratorBundle\Configuration\CsvQueryBuilderGeneratorConfiguration;
Expand All @@ -19,9 +19,8 @@
*
* @covers \RichId\CsvGeneratorBundle\Configuration\AbstractCsvGeneratorConfiguration
* @covers \RichId\CsvGeneratorBundle\Configuration\CsvQueryBuilderGeneratorConfiguration
*
* @TestConfig("fixtures")
*/
#[TestConfig('fixtures')]
class CsvQueryBuilderGeneratorConfigurationTest extends TestCase
{
/** @var EntityManagerInterface */
Expand Down
5 changes: 2 additions & 3 deletions Tests/Generator/CsvGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestSuite\TestCase\TestCase;
use RichId\CsvGeneratorBundle\Configuration\CsvGeneratorConfiguration;
use RichId\CsvGeneratorBundle\Configuration\CsvQueryBuilderGeneratorConfiguration;
Expand All @@ -22,9 +22,8 @@
* @copyright 2014 - 2021 RichId (https://www.rich-id.fr)
*
* @covers \RichId\CsvGeneratorBundle\Generator\CsvGenerator
*
* @TestConfig("fixtures")
*/
#[TestConfig('fixtures')]
class CsvGeneratorTest extends TestCase
{
protected const RESOURCES_DIR = __DIR__ . '/../Resources/files/';
Expand Down
66 changes: 20 additions & 46 deletions Tests/Resources/Entity/DummyEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,34 @@
namespace RichId\CsvGeneratorBundle\Tests\Resources\Entity;

use Doctrine\ORM\Mapping as ORM;
use RichId\CsvGeneratorBundle\Annotation\CsvContentTranslationPrefix;
use RichId\CsvGeneratorBundle\Attribute\CsvContentTranslationPrefix;
use Symfony\Component\Serializer\Annotation\Groups;

/**
* @ORM\Table("dummy_entity")
* @ORM\Entity
*/
#[ORM\Table('dummy_entity')]
#[ORM\Entity]
class DummyEntity
{
/**
* @var int
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @Groups("my_serialization_group")
*/
private $id;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[Groups('my_serialization_group')]
private int $id;

/**
* @var string
*
* @ORM\Column(type="string", length=250, nullable=false, name="name")
*
* @Groups("my_serialization_group")
*/
private $name;
#[ORM\Column(name: 'name', type: 'string', length: 250, nullable: false)]
#[Groups("my_serialization_group")]
private string $name;

/**
* @var string
*
* @ORM\Column(type="string", length=250, nullable=false, name="other")
*
* @Groups("my_serialization_group")
* @CsvContentTranslationPrefix("my_content_translation_prefix.")
*/
private $other;
#[ORM\Column(name: 'title', type: 'string', length: 250, nullable: false)]
private string $title;

/**
* @var string
*
* @ORM\Column(type="string", length=250, nullable=false, name="title")
*/
private $title;
#[ORM\Column(name: 'other', type: 'string', length: 250, nullable: false)]
#[Groups('my_serialization_group')]
#[CsvContentTranslationPrefix('my_content_translation_prefix.')]
private string $other;

/**
* @var string
*
* @ORM\Column(type="string", length=250, nullable=true, name="other_title")
*
* @CsvContentTranslationPrefix("my_content_translation_prefix.")
*/
public $otherTitle;
#[ORM\Column(name: 'other_title', type: 'string', length: 250, nullable: true)]
#[CsvContentTranslationPrefix("my_content_translation_prefix.")]
public ?string $otherTitle;

public static function build(int $id, string $name, string $other): DummyEntity
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ doctrine:
mappings:
Test:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/Tests/Resources/Entity'
prefix: 'RichId\CsvGeneratorBundle\Tests\Resources\Entity'
alias: Test
Expand Down
4 changes: 2 additions & 2 deletions Tests/Resources/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ framework:
cache:
app: cache.adapter.array
session:
handler_id: session.handler.native_file
storage_id: session.storage.mock_file
handler_id: ~
storage_factory_id: session.storage.factory.mock_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
5 changes: 2 additions & 3 deletions Tests/Utility/PropertiesUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RichId\CsvGeneratorBundle\Tests\Utility;

use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig;
use RichCongress\TestFramework\TestConfiguration\Attribute\TestConfig;
use RichCongress\TestSuite\TestCase\TestCase;
use RichId\CsvGeneratorBundle\Configuration\CsvGeneratorConfiguration;
use RichId\CsvGeneratorBundle\Data\Property;
Expand All @@ -17,9 +17,8 @@
* @copyright 2014 - 2021 RichId (https://www.rich-id.fr)
*
* @covers \RichId\CsvGeneratorBundle\Utility\PropertiesUtility
*
* @TestConfig("kernel")
*/
#[TestConfig('kernel')]
class PropertiesUtilityTest extends TestCase
{
/** @var PropertiesUtility */
Expand Down
35 changes: 17 additions & 18 deletions Utility/PropertiesUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

namespace RichId\CsvGeneratorBundle\Utility;

use Doctrine\Common\Annotations\AnnotationReader;
use RichId\CsvGeneratorBundle\Annotation\CsvContentTranslationPrefix;
use RichId\CsvGeneratorBundle\Attribute\CsvContentTranslationPrefix;
use RichId\CsvGeneratorBundle\Configuration\AbstractCsvGeneratorConfiguration;
use RichId\CsvGeneratorBundle\Data\Property;
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

Expand All @@ -18,14 +22,6 @@
*/
final class PropertiesUtility
{
/** @var NormalizerInterface */
protected $normalizer;

public function __construct(NormalizerInterface $normalizer)
{
$this->normalizer = $normalizer;
}

public function getPropertiesNamesForConfig(AbstractCsvGeneratorConfiguration $configuration): array
{
$class = new \ReflectionClass($configuration->getClass());
Expand Down Expand Up @@ -55,27 +51,30 @@ public function getPropertiesForConfig(AbstractCsvGeneratorConfiguration $config

public function getPropertiesWithContentTranslationPrefix(AbstractCsvGeneratorConfiguration $configuration): array
{
$propertiesWithAnnotation = [];
$annotationReader = new AnnotationReader();
$propertiesWithAttribute = [];
$properties = $this->getPropertiesForConfig($configuration);

foreach ($properties as $property) {
$annotation = $annotationReader->getPropertyAnnotation($property->getReflectionProperty(), CsvContentTranslationPrefix::class);
$attribute = $property->getReflectionProperty()->getAttributes(CsvContentTranslationPrefix::class, \ReflectionAttribute::IS_INSTANCEOF)[0] ?? null;
$attribute = $attribute?->newInstance();

if (!$annotation instanceof CsvContentTranslationPrefix) {
if (!$attribute instanceof CsvContentTranslationPrefix) {
continue;
}

$propertiesWithAnnotation[$property->getName()] = $annotation->translationPrefix;
$propertiesWithAttribute[$property->getName()] = $attribute->translationPrefix;
}

return $propertiesWithAnnotation;
return $propertiesWithAttribute;
}

private function getPropertiesName(AbstractCsvGeneratorConfiguration $configuration, $object): array
{
$context = empty($configuration->getSerializationGroups()) ? [] : [AbstractNormalizer::GROUPS => $configuration->getSerializationGroups()];
$groups = empty($configuration->getSerializationGroups()) ? null : $configuration->getSerializationGroups();
$context = ['serializer_groups' => $groups];

$extractor = new SerializerExtractor(new ClassMetadataFactory(new AttributeLoader()));

return array_keys($this->normalizer->normalize($object, null, $context));
return $extractor->getProperties($object::class, $context);
}
}
19 changes: 12 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"description": "A csv bundle for Symfony 5.4",
"type": "symfony-bundle",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "RichId",
Expand All @@ -16,15 +18,15 @@
"issues": "https://github.com/rich-id/csv-generator-bundle/issues"
},
"require": {
"php": "^8.0",
"doctrine/orm": "^2.7",
"php": "^8.1",
"doctrine/orm": "^2.7 || ^3.0",
"richcongress/bundle-toolbox": "*",
"symfony/http-foundation": "^5.4",
"symfony/serializer": "^5.4",
"symfony/translation": "^5.4"
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
"symfony/serializer": "^5.4 || ^6.0 || ^7.0",
"symfony/translation": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"richcongress/test-suite": "^0.1",
"richcongress/test-suite": "v0.2.x-dev",
"infection/infection": "^0.20.2"
},
"autoload": {
Expand All @@ -40,6 +42,9 @@
"config": {
"bin-dir": "bin",
"discard-changes": true,
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true
}
}
}
Loading

0 comments on commit 8ee5a7c

Please sign in to comment.