AbstractDoctrineDecorator.php 1.12 KiB
<?php declare(strict_types=1);
/*
 * Copyright (C) 2016-2018 IRSTEA
 * All rights reserved.
 */
namespace Irstea\PlantUmlBundle\Doctrine;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Irstea\PlantUmlBundle\Model\DecoratorInterface;
use ReflectionClass;
/**
 * Description of AbstractDoctrineDecorator.
abstract class AbstractDoctrineDecorator implements DecoratorInterface
    /**
     * @var ClassMetadataFactory
    protected $metadataFactory;
    public function __construct(EntityManagerInterface $manager)
        $this->metadataFactory = $manager->getMetadataFactory();
    /**
     * @param callable        $callback
     * @param ReflectionClass $class
     * @return mixed
    protected function withMetadata($callback, ReflectionClass $class = null)
        if (!$class) {
            return null;
        $className = $class->getName();
        if (!$this->metadataFactory->hasMetadataFor($className)) {
            return null;
        return $callback($this->metadataFactory->getMetadataFor($className));