AbstractTypeGuesser.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\DoctrineORMAdminBundle\Guesser;
  11. use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
  12. use Doctrine\ORM\Mapping\MappingException;
  13. use Sonata\AdminBundle\Model\ModelManagerInterface;
  14. abstract class AbstractTypeGuesser implements TypeGuesserInterface
  15. {
  16. /**
  17. * @param string $class
  18. * @param string $property
  19. * @return TypeGuess
  20. */
  21. abstract public function guessType($class, $property, ModelManagerInterface $modelManager);
  22. protected function getParentMetadataForProperty($baseClass, $propertyFullName, $modelManager)
  23. {
  24. try {
  25. return $modelManager->getParentMetadataForProperty($baseClass, $propertyFullName);
  26. } catch (MappingException $e) {
  27. // no metadata not found.
  28. return null;
  29. }
  30. }
  31. }