-
-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6adb383
commit 4b2af33
Showing
7 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\Common\Persistence\Mapping\MappingException; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; | ||
use Doctrine\ODM\MongoDB\Types\Type as MongoDbType; | ||
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; | ||
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; | ||
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
@@ -29,7 +31,7 @@ | |
* @author Kévin Dunglas <[email protected]> | ||
* @author Alan Poulain <[email protected]> | ||
*/ | ||
final class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeExtractorInterface | ||
final class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface | ||
{ | ||
private $objectManager; | ||
|
||
|
@@ -43,9 +45,7 @@ public function __construct(ObjectManager $objectManager) | |
*/ | ||
public function getProperties($class, array $context = []) | ||
{ | ||
try { | ||
$metadata = $this->objectManager->getClassMetadata($class); | ||
} catch (MappingException $exception) { | ||
if (null === $metadata = $this->getMetadata($class)) { | ||
return null; | ||
} | ||
|
||
|
@@ -57,9 +57,7 @@ public function getProperties($class, array $context = []) | |
*/ | ||
public function getTypes($class, $property, array $context = []) | ||
{ | ||
try { | ||
$metadata = $this->objectManager->getClassMetadata($class); | ||
} catch (MappingException $exception) { | ||
if (null === $metadata = $this->getMetadata($class)) { | ||
return null; | ||
} | ||
|
||
|
@@ -111,6 +109,39 @@ public function getTypes($class, $property, array $context = []) | |
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isReadable($class, $property, array $context = []): ?bool | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isWritable($class, $property, array $context = []): ?bool | ||
{ | ||
if ( | ||
null === ($metadata = $this->getMetadata($class)) | ||
|| ClassMetadata::GENERATOR_TYPE_NONE === $metadata->generatorType | ||
|| !\in_array($property, $metadata->getIdentifierFieldNames(), true) | ||
) { | ||
return null; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private function getMetadata(string $class): ?ClassMetadata | ||
{ | ||
try { | ||
return $this->objectManager->getClassMetadata($class); | ||
} catch (MappingException $exception) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the corresponding built-in PHP type. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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\Core\Tests\Bridge\Doctrine\MongoDbOdm\PropertyInfo\Fixtures; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations\Field; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id; | ||
|
||
/** | ||
* @Document | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
* @author Alan Poulain <[email protected]> | ||
*/ | ||
class DoctrineGeneratedValue | ||
{ | ||
/** | ||
* @Id(strategy="INCREMENT", type="integer") | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @Field | ||
*/ | ||
public $foo; | ||
} |