Skip to content

Commit

Permalink
Merge pull request #42 from RobinDvorak/rd-fix-symfony-5-deprecations
Browse files Browse the repository at this point in the history
fix serialization of TranslatableMetadata and TranslationMetadata
  • Loading branch information
sandermarechal authored Aug 2, 2022
2 parents 22c1fdb + 33a8869 commit 96b3749
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 55 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/run-checks-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and tests
on:
push:
branches:
- 'master'
- '[1-9].[0-9]'
tags:
- '**'
pull_request:
branches:
- '**'
jobs:
cancel:
name: Cancel previous workflow runs
runs-on: ubuntu-latest
steps:
- name: Cancelling
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
run-tests:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '7.4', '8.0', '8.1' ]
needs: cancel
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Clone repository
uses: actions/checkout@v3
- name: Install composer dependencies
run: composer install --no-interaction --optimize-autoloader
- name: Run Unit tests
run: vendor/bin/phpunit
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"translatable",
"i18n"
],
"homepage": "http://www.prezent.nl",
"homepage": "https://www.prezent.nl",
"authors": [{
"name": "Prezent Internet B.V.",
"email": "[email protected]"
Expand All @@ -20,7 +20,7 @@
"source": "https://github.com/prezent/doctrine-translatable"
},
"require": {
"php": ">=7.1.0",
"php": ">=7.4.0",
"doctrine/common": "^2.3|^3.0",
"doctrine/orm": ">=2.12.0",
"jms/metadata": "^1.1|^2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/TranslatableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function getMetadataFactory()
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents(): array
{
return array(
Events::loadClassMetadata,
Expand Down
48 changes: 21 additions & 27 deletions src/Mapping/TranslatableMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,42 +84,36 @@ public function merge(MergeableInterface $object): void
}

/**
* {@inheritdoc}
* @return array{targetEntity: string, currentLocale: ?string, fallbackLocale: ?string, translations: ?string, parent: mixed[]}
*/
public function serialize()
public function __serialize(): array
{
return serialize(array(
$this->targetEntity,
$this->currentLocale ? $this->currentLocale->name : null,
$this->fallbackLocale ? $this->fallbackLocale->name : null,
$this->translations ? $this->translations->name : null,
parent::serialize(),
));
return [
'targetEntity' => $this->targetEntity,
'currentLocale' => $this->currentLocale->name ?? null,
'fallbackLocale' => $this->fallbackLocale->name ?? null,
'translations' => $this->translations->name ?? null,
'parent' => $this->serializeToArray(),
];
}

/**
* {@inheritdoc}
* @param array{targetEntity: string, currentLocale: ?string, fallbackLocale: ?string, translations: ?string, parent: mixed[]} $data
*/
public function unserialize($str)
public function __unserialize(array $data): void
{
list (
$this->targetEntity,
$currentLocale,
$fallbackLocale,
$translations,
$parent
) = unserialize($str);

parent::unserialize($parent);

if ($currentLocale) {
$this->currentLocale = $this->propertyMetadata[$currentLocale];
$this->targetEntity = $data['targetEntity'];

$this->unserializeFromArray($data['parent']);

if ($data['currentLocale']) {
$this->currentLocale = $this->propertyMetadata[$data['currentLocale']];
}
if ($fallbackLocale) {
$this->fallbackLocale = $this->propertyMetadata[$fallbackLocale];
if ($data['fallbackLocale']) {
$this->fallbackLocale = $this->propertyMetadata[$data['fallbackLocale']];
}
if ($translations) {
$this->translations = $this->propertyMetadata[$translations];
if ($data['translations']) {
$this->translations = $this->propertyMetadata[$data['translations']];
}
}
}
45 changes: 20 additions & 25 deletions src/Mapping/TranslationMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,39 +92,34 @@ public function merge(MergeableInterface $object): void
}

/**
* {@inheritdoc}
* @return array{targetEntity: string, referencedColumnName: string, translatable: ?string, locale: ?string, parent: mixed[]}
*/
public function serialize()
public function __serialize(): array
{
return serialize(array(
$this->targetEntity,
$this->referencedColumnName,
$this->translatable ? $this->translatable->name : null,
$this->locale ? $this->locale->name : null,
parent::serialize(),
));
return [
'targetEntity' => $this->targetEntity,
'referencedColumnName' => $this->referencedColumnName,
'translatable' => $this->translatable->name ?? null,
'locale' => $this->locale->name ?? null,
'parent' => $this->serializeToArray(),
];
}

/**
* {@inheritdoc}
* @param array{targetEntity: string, referencedColumnName: string, translatable: ?string, locale: ?string, parent: mixed[]} $data
*/
public function unserialize($str)
public function __unserialize(array $data): void
{
list (
$this->targetEntity,
$this->referencedColumnName,
$translatable,
$locale,
$parent
) = unserialize($str);

parent::unserialize($parent);

if ($translatable) {
$this->translatable = $this->propertyMetadata[$translatable];
$this->targetEntity = $data['targetEntity'];
$this->referencedColumnName = $data['referencedColumnName'];

$this->unserializeFromArray($data['parent']);

if ($data['translatable']) {
$this->translatable = $this->propertyMetadata[$data['translatable']];
}
if ($locale) {
$this->locale = $this->propertyMetadata[$locale];
if ($data['locale']) {
$this->locale = $this->propertyMetadata[$data['locale']];
}
}
}

0 comments on commit 96b3749

Please sign in to comment.