Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/TypesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class TypesGenerator
*/
private const SCHEMA_ORG_RANGE = 'schema:rangeIncludes';

/**
* @var string
*/
private const SCHEMA_ORG_SUPERSEDED_BY = 'schema:supersededBy';

/**
* @var \Twig_Environment
*/
Expand Down Expand Up @@ -232,7 +237,12 @@ public function generate(array $config): void
} else {
// All properties
foreach ($propertiesMap[$type->getUri()] as $property) {
$class = $this->generateField($config, $class, $type, $typeName, $property->localName(), $property);
if ($property->hasProperty(self::SCHEMA_ORG_SUPERSEDED_BY)) {
$supersededBy = $property->get('schema:supersededBy');
$this->logger->warning(sprintf('The property "%s" is superseded by "%s". Using the superseding property.', $property->localName(), $supersededBy->localName()));
} else {
$class = $this->generateField($config, $class, $type, $typeName, $property->localName(), $property);
}
}
}

Expand Down
34 changes: 34 additions & 0 deletions tests/Command/GenerateTypesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,38 @@ public function testGeneratedEnum()

$this->assertNotContains('function setId(', $gender);
}

public function testSupersededProperties()
{
$outputDir = __DIR__.'/../../build/superseded-properties';
$config = __DIR__.'/../config/superseded-properties.yaml';

$this->fs->mkdir($outputDir);

$commandTester = new CommandTester(new GenerateTypesCommand());
$this->assertEquals(0, $commandTester->execute(['output' => $outputDir, 'config' => $config]));

$creativeWork = file_get_contents("$outputDir/AppBundle/Entity/CreativeWork.php");

$this->assertContains(<<<'PHP'
/**
* @var string|null an award won by or for this item
*
* @ORM\Column(type="text", nullable=true)
* @ApiProperty(iri="http://schema.org/award")
*/
private $award;
PHP
, $creativeWork);

$this->assertNotContains(<<<'PHP'
/**
* @var string|null awards won by or for this item
*
* @ORM\Column(type="text", nullable=true)
*/
protected $award;
PHP
, $creativeWork);
}
}
3 changes: 3 additions & 0 deletions tests/config/superseded-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
types:
CreativeWork:
allProperties: true