Skip to content

Commit

Permalink
chore: deprecations (#6563)
Browse files Browse the repository at this point in the history
* chore: deprecations

* chore: deprecations
  • Loading branch information
soyuka authored Aug 30, 2024
1 parent 8a6965c commit b23bba8
Show file tree
Hide file tree
Showing 15 changed files with 1,845 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.gitignore export-ignore
/Tests export-ignore
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.lock
/vendor
/.phpunit.result.cache
20 changes: 20 additions & 0 deletions Tests/Fixtures/CircularReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\JsonApi\Tests\Fixtures;

class CircularReference
{
public $id;
public CircularReference $parent;
}
42 changes: 42 additions & 0 deletions Tests/Fixtures/CustomConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\JsonApi\Tests\Fixtures;

use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;

/**
* Custom converter that will only convert a property named "nameConverted"
* with the same logic as Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter.
*/
class CustomConverter implements AdvancedNameConverterInterface
{
private NameConverterInterface $nameConverter;

public function __construct()
{
$this->nameConverter = new CamelCaseToSnakeCaseNameConverter();
}

public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
{
return 'nameConverted' === $propertyName ? $this->nameConverter->normalize($propertyName) : $propertyName;
}

public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
{
return 'name_converted' === $propertyName ? $this->nameConverter->denormalize($propertyName) : $propertyName;
}
}
206 changes: 206 additions & 0 deletions Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\JsonApi\Tests\Fixtures;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;

/**
* Dummy.
*
* @author Kévin Dunglas <[email protected]>
*/
#[ApiResource(filters: ['my_dummy.boolean', 'my_dummy.date', 'my_dummy.exists', 'my_dummy.numeric', 'my_dummy.order', 'my_dummy.range', 'my_dummy.search', 'my_dummy.property'], extraProperties: ['standard_put' => false])]
class Dummy
{
/**
* @var int|null The id
*/
private $id;

/**
* @var string The dummy name
*/
#[ApiProperty(iris: ['https://schema.org/name'])]
#[Assert\NotBlank]
private string $name;

/**
* @var string|null The dummy name alias
*/
#[ApiProperty(iris: ['https://schema.org/alternateName'])]
private $alias;

/**
* @var array foo
*/
private ?array $foo = null;

/**
* @var string|null A short description of the item
*/
#[ApiProperty(iris: ['https://schema.org/description'])]
public $description;

/**
* @var string|null A dummy
*/
public $dummy;

/**
* @var bool|null A dummy boolean
*/
public ?bool $dummyBoolean = null;
/**
* @var \DateTime|null A dummy date
*/
#[ApiProperty(iris: ['https://schema.org/DateTime'])]
public $dummyDate;

/**
* @var float|null A dummy float
*/
public $dummyFloat;

/**
* @var string|null A dummy price
*/
public $dummyPrice;

/**
* @var array|null serialize data
*/
public $jsonData = [];

/**
* @var array|null
*/
public $arrayData = [];

/**
* @var string|null
*/
public $nameConverted;

public static function staticMethod(): void
{
}

public function getId()
{
return $this->id;
}

public function setId($id): void
{
$this->id = $id;
}

public function setName(string $name): void
{
$this->name = $name;
}

public function getName(): string
{
return $this->name;
}

public function setAlias($alias): void
{
$this->alias = $alias;
}

public function getAlias()
{
return $this->alias;
}

public function setDescription($description): void
{
$this->description = $description;
}

public function getDescription()
{
return $this->description;
}

public function fooBar($baz): void
{
}

public function getFoo(): ?array
{
return $this->foo;
}

public function setFoo(?array $foo = null): void
{
$this->foo = $foo;
}

public function setDummyDate(?\DateTime $dummyDate = null): void
{
$this->dummyDate = $dummyDate;
}

public function getDummyDate()
{
return $this->dummyDate;
}

public function setDummyPrice($dummyPrice)
{
$this->dummyPrice = $dummyPrice;

return $this;
}

public function getDummyPrice()
{
return $this->dummyPrice;
}

public function setJsonData($jsonData): void
{
$this->jsonData = $jsonData;
}

public function getJsonData()
{
return $this->jsonData;
}

public function setArrayData($arrayData): void
{
$this->arrayData = $arrayData;
}

public function getArrayData()
{
return $this->arrayData;
}

public function setDummy($dummy = null): void
{
$this->dummy = $dummy;
}

public function getDummy()
{
return $this->dummy;
}
}
116 changes: 116 additions & 0 deletions Tests/Fixtures/RelatedDummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\JsonApi\Tests\Fixtures;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;

/**
* Related Dummy.
*
* @author Kévin Dunglas <[email protected]>
*/
#[ApiResource]
class RelatedDummy implements \Stringable
{
#[ApiProperty(writable: false)]
#[Groups(['chicago', 'friends'])]
private $id;

/**
* @var string|null A name
*/
#[ApiProperty(iris: ['RelatedDummy.name'])]
#[Groups(['friends'])]
public $name;

#[ApiProperty(deprecationReason: 'This property is deprecated for upgrade test')]
#[Groups(['barcelona', 'chicago', 'friends'])]
protected $symfony = 'symfony';

/**
* @var \DateTime|null A dummy date
*/
#[Groups(['friends'])]
public $dummyDate;

/**
* @var bool|null A dummy bool
*/
#[Groups(['friends'])]
public ?bool $dummyBoolean = null;

public function __construct()
{
}

public function getId()
{
return $this->id;
}

public function setId($id): void
{
$this->id = $id;
}

public function setName($name): void
{
$this->name = $name;
}

public function getName()
{
return $this->name;
}

public function getSymfony()
{
return $this->symfony;
}

public function setSymfony($symfony): void
{
$this->symfony = $symfony;
}

public function setDummyDate(\DateTime $dummyDate): void
{
$this->dummyDate = $dummyDate;
}

public function getDummyDate()
{
return $this->dummyDate;
}

public function isDummyBoolean(): ?bool
{
return $this->dummyBoolean;
}

/**
* @param bool $dummyBoolean
*/
public function setDummyBoolean($dummyBoolean): void
{
$this->dummyBoolean = $dummyBoolean;
}

public function __toString(): string
{
return (string) $this->getId();
}
}
Loading

0 comments on commit b23bba8

Please sign in to comment.