/**
  * {@inheritdoc}
  */
 public function supports(PuliResource $resource)
 {
     if (false === $resource instanceof CmfResource) {
         return false;
     }
     return $this->metadataFactory->hasMetadataFor(ClassUtils::getRealClass($resource->getPayloadType()));
 }
 /**
  * {@inheritDoc}
  */
 public function boot()
 {
     // Register an autoloader for proxies to avoid issues when unserializing them
     // when the ORM is used.
     if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) {
         $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace');
         $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
         $proxyGenerator = null;
         if ($this->container->getParameter('doctrine.orm.auto_generate_proxy_classes')) {
             // See https://github.com/symfony/symfony/pull/3419 for usage of references
             $container =& $this->container;
             $proxyGenerator = function ($proxyDir, $proxyNamespace, $class) use(&$container) {
                 $originalClassName = ClassUtils::getRealClass($class);
                 /** @var $registry Registry */
                 $registry = $container->get('doctrine');
                 // Tries to auto-generate the proxy file
                 /** @var $em \Doctrine\ORM\EntityManager */
                 foreach ($registry->getManagers() as $em) {
                     if (!$em->getConfiguration()->getAutoGenerateProxyClasses()) {
                         continue;
                     }
                     $metadataFactory = $em->getMetadataFactory();
                     if ($metadataFactory->isTransient($originalClassName)) {
                         continue;
                     }
                     $classMetadata = $metadataFactory->getMetadataFor($originalClassName);
                     $em->getProxyFactory()->generateProxyClasses(array($classMetadata));
                     clearstatcache(true, Autoloader::resolveFile($proxyDir, $proxyNamespace, $class));
                     break;
                 }
             };
         }
         $this->autoloader = Autoloader::register($dir, $namespace, $proxyGenerator);
     }
 }
Exemple #3
0
 public static function getRealClass($class)
 {
     if (class_exists('Doctrine\\Common\\Util\\ClassUtils')) {
         $class = DoctrineClassUtils::getRealClass($class);
     }
     return $class;
 }
 public function resultatsLinkTerritoire($territoire)
 {
     switch (ClassUtils::getRealClass(get_class($territoire))) {
         case 'AppBundle\\Domain\\Territoire\\Entity\\Territoire\\CirconscriptionEuropeenne':
             $route = 'resultat_circo_europeenne';
             $parameters = array('code' => $territoire->getCode(), 'nom' => $this->slugify->slugify($territoire->getNom()));
             break;
         case 'AppBundle\\Domain\\Territoire\\Entity\\Territoire\\Commune':
             $route = 'resultat_commune';
             $parameters = array('departement' => $territoire->getDepartement()->getCode(), 'code' => $territoire->getCode(), 'nom' => $this->slugify->slugify($territoire->getNom()));
             break;
         case 'AppBundle\\Domain\\Territoire\\Entity\\Territoire\\Departement':
             $route = 'resultat_departement';
             $parameters = array('code' => $territoire->getCode(), 'nom' => $this->slugify->slugify($territoire->getNom()));
             break;
         case 'AppBundle\\Domain\\Territoire\\Entity\\Territoire\\Pays':
             $route = 'resultat_france';
             $parameters = array();
             break;
         case 'AppBundle\\Domain\\Territoire\\Entity\\Territoire\\Region':
             $route = 'resultat_region';
             $parameters = array('code' => $territoire->getCode(), 'nom' => $this->slugify->slugify($territoire->getNom()));
             break;
     }
     if (isset($route, $parameters)) {
         return $this->router->generate($route, $parameters);
     }
     return '';
 }
 /**
  * {@inheritDoc}
  *
  * use getRealClass if className names a doctrine proxy class.
  */
 public function canonicalName($className)
 {
     $refl = new \ReflectionClass($className);
     if (in_array('Doctrine\\Common\\Persistence\\Proxy', $refl->getInterfaceNames())) {
         $className = \Doctrine\Common\Util\ClassUtils::getRealClass($className);
     }
     return $className;
 }
 /**
  * @param $entity
  * @return string
  */
 public function getOwnerType($entity)
 {
     $ownerClassName = ClassUtils::getRealClass(get_class($entity));
     if (!$this->configProvider->hasConfig($ownerClassName)) {
         return;
     }
     $config = $this->configProvider->getConfig($ownerClassName)->all();
     return $config['owner_type'];
 }
 /**
  * Get real class name of a reference that could be a proxy
  *
  * @param string $className Class name of reference object
  *
  * @return string
  */
 protected function getRealClass($className)
 {
     if (Version::compare('2.2.0') <= 0) {
         return ClassUtils::getRealClass($className);
     }
     if (substr($className, -5) === 'Proxy') {
         return substr($className, 0, -5);
     }
     return $className;
 }
 /**
  *
  * @param type $translatableClass
  * @return type
  */
 private function getGedmoConfig($translatableClass)
 {
     if (isset($this->gedmoConfig[$translatableClass])) {
         return $this->gedmoConfig[$translatableClass];
     }
     $translatableClass = \Doctrine\Common\Util\ClassUtils::getRealClass($translatableClass);
     $manager = $this->getManagerRegistry()->getManagerForClass($translatableClass);
     $this->gedmoConfig[$translatableClass] = $this->gedmoTranslatableListener->getConfiguration($manager, $translatableClass);
     return $this->gedmoConfig[$translatableClass];
 }
Exemple #9
0
 /**
  * Gets a real class name for an entity.
  *
  * @param object|string $entityOrClass An entity object, entity class name or entity proxy class name
  *
  * @return string
  */
 public function getEntityClass($entityOrClass)
 {
     if (is_object($entityOrClass)) {
         return ClassUtils::getClass($entityOrClass);
     }
     if (strpos($entityOrClass, ':') !== false) {
         list($namespaceAlias, $simpleClassName) = explode(':', $entityOrClass, 2);
         return $this->registry->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
     }
     return ClassUtils::getRealClass($entityOrClass);
 }
 protected function markDirty(Identified $entity, array $data = [])
 {
     if (empty($entity->getId())) {
         throw new InvalidArgumentException('Entity has no identifier');
     }
     $class = ClassUtils::getRealClass(get_class($entity));
     $this->dirtyEntities[$class][$entity->getId()] = $data;
     if ($this->autoFlush) {
         $this->flushSync();
     }
 }
 public function createClassIdentity($className)
 {
     $className = ClassUtils::getRealClass($className);
     if (isset($this->classCache[$className])) {
         return $this->classCache[$className];
     }
     if (null !== ($this->classCache[$className] = $this->classRepository->findOneByName($className))) {
         return $this->classCache[$className];
     }
     $classClass = $this->classRepository->getClassName();
     return $this->classCache[$className] = new $classClass($className);
 }
Exemple #12
0
 /**
  * Gets the real class name of a class name that could be a proxy.
  *
  * @param string|object $object
  *
  * @return string
  */
 public static function getRealClass($object)
 {
     $class = is_object($object) ? get_class($object) : $object;
     if (class_exists('Doctrine\\Common\\Util\\ClassUtils')) {
         return DoctrineClassUtils::getRealClass($class);
     }
     // fallback in case doctrine common  is not installed
     if (false === ($pos = strrpos($class, '\\' . self::MARKER . '\\'))) {
         return $class;
     }
     return substr($class, $pos + self::MARKER_LENGTH + 2);
 }
 /**
  * Create new
  *
  * @return Response
  */
 public function handleCreateRequest()
 {
     $entity = $this->getManager()->createEntity();
     $isProcessed = $this->processForm($entity);
     if ($isProcessed) {
         $entityClass = ClassUtils::getRealClass(get_class($entity));
         $classMetadata = $this->getManager()->getObjectManager()->getClassMetadata($entityClass);
         $view = $this->view($classMetadata->getIdentifierValues($entity), Codes::HTTP_CREATED);
     } else {
         $view = $this->view($this->getForm(), Codes::HTTP_BAD_REQUEST);
     }
     return $this->handleView($view);
 }
 /**
  *
  * @param type $translationClass
  * @return type
  */
 protected function getTranslatableFields($translationClass)
 {
     $translationClass = \Doctrine\Common\Util\ClassUtils::getRealClass($translationClass);
     $manager = $this->getManagerRegistry()->getManagerForClass($translationClass);
     $metadataClass = $manager->getMetadataFactory()->getMetadataFor($translationClass);
     $fields = array();
     foreach ($metadataClass->fieldMappings as $fieldMapping) {
         if (!in_array($fieldMapping['fieldName'], array('id', 'locale'))) {
             $fields[] = $fieldMapping['fieldName'];
         }
     }
     return $fields;
 }
Exemple #15
0
 /**
  * @param EntityManagerInterface|EntityManager $entityManager
  * @param string $entityName
  * @return EntityRepository
  */
 public function getRepository(EntityManagerInterface $entityManager, $entityName)
 {
     if (is_object($entityName)) {
         $entityName = Doctrine\Common\Util\ClassUtils::getRealClass(get_class($entityName));
     }
     $entityName = ltrim($entityName, '\\');
     if (isset($this->repositoryList[$emId = spl_object_hash($entityManager)][$entityName])) {
         return $this->repositoryList[$emId][$entityName];
     }
     /** @var Doctrine\ORM\Mapping\ClassMetadata $metadata */
     $metadata = $entityManager->getClassMetadata($entityName);
     $repository = $this->createRepository($entityManager, $metadata);
     return $this->repositoryList[$emId][$entityName] = $repository;
 }
 /**
  *
  * @param string $translationClass
  * @param array  $exclude
  * @return array
  */
 protected function getTranslationFields($translationClass, array $exclude = array())
 {
     $fields = array();
     $translationClass = ClassUtils::getRealClass($translationClass);
     if ($manager = $this->managerRegistry->getManagerForClass($translationClass)) {
         $metadataClass = $manager->getMetadataFactory()->getMetadataFor($translationClass);
         foreach ($metadataClass->fieldMappings as $fieldMapping) {
             if (!in_array($fieldMapping['fieldName'], array('id', 'locale')) && !in_array($fieldMapping['fieldName'], $exclude)) {
                 $fields[] = $fieldMapping['fieldName'];
             }
         }
     }
     return $fields;
 }
 /**
  * {@inheritdoc}
  */
 public function guessValues(UrlInformation $urlInformation, $object, $sitemap)
 {
     if (null !== $urlInformation->getDepth()) {
         return;
     }
     $manager = $this->managerRegistry->getManagerForClass(ClassUtils::getRealClass(get_class($object)));
     if (!$manager instanceof DocumentManager) {
         return;
     }
     $node = $manager->getNodeForDocument($object);
     if (null === $node) {
         return;
     }
     $urlInformation->setDepth($node->getDepth() - $this->offset);
 }
 /**
  * @param FormInterface $form
  *
  * @return string
  */
 private function getDataClass(FormInterface $form)
 {
     // Simple case, data_class from current form
     if ($dataClass = $form->getConfig()->getDataClass()) {
         return ClassUtils::getRealClass($dataClass);
     }
     // Advanced case, loop parent form to get closest fill data_class
     while ($formParent = $form->getParent()) {
         if (!($dataClass = $formParent->getConfig()->getDataClass())) {
             $form = $formParent;
             continue;
         }
         return $this->objectInfo->getAssociationTargetClass($dataClass, $form->getName());
     }
 }
 /**
  * @return TranslationInterface
  */
 public function getTranslation()
 {
     $locale = null === $this->locale ? \Locale::getDefault() : $this->locale;
     $translations = $this->translatable->getTranslations();
     if (isset($translations[$locale])) {
         return $translations[$locale];
     } elseif (isset($translations[substr($locale, 0, strpos($locale, '_'))])) {
         return $translations[substr($locale, 0, strpos($locale, '_'))];
     }
     $class = get_class($this->translatable);
     if ($this->translatable instanceof \Doctrine\Common\Persistence\Proxy) {
         $class = \Doctrine\Common\Util\ClassUtils::getRealClass($class);
     }
     $translationClass = $this->getTranslationClassName($class);
     return $this->createTranslation($translationClass, $locale);
 }
 /**
  * Return a HAL entity with just a self link
  */
 public function extract($value)
 {
     if (is_null($value)) {
         return $value;
     }
     $entityValues = $this->getHydratorForEntity($value)->extract($value);
     $entityMetadata = $this->getMetadataMap()[ClassUtils::getRealClass(get_class($value))];
     $link = new Link('self');
     $link->setRoute($entityMetadata['route_name']);
     $link->setRouteParams(array($entityMetadata['route_identifier_name'] => $entityValues[$entityMetadata['entity_identifier_name']]));
     $linkCollection = new LinkCollection();
     $linkCollection->add($link);
     $halEntity = new HalEntity(new stdClass());
     $halEntity->setLinks($linkCollection);
     return $halEntity;
 }
 /**
  * {@inheritdoc}
  */
 public function resolveComponentData(ResolveComponentModelIdentifier $resolve)
 {
     $model = $resolve->getModel();
     $identifier = $resolve->getIdentifier();
     $data = null;
     if (is_object($model)) {
         $data = $model;
         $modelClass = get_class($model);
         if (!method_exists($model, 'getId')) {
             throw new ResolveComponentDataException('Model must have a getId method');
         }
         $identifier = $model->getId();
         $model = $modelClass;
     }
     $model = ClassUtils::getRealClass($model);
     return new ResolvedComponentData($model, $identifier, $data);
 }
 public function boot()
 {
     // force Doctrine annotations to be loaded
     // should be removed when a better solution is found in Doctrine
     class_exists('Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver');
     // Register an autoloader for proxies to avoid issues when unserializing them
     // when the ORM is used.
     if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) {
         $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace');
         $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
         $container =& $this->container;
         $this->autoloader = function ($class) use($namespace, $dir, &$container) {
             if (0 === strpos($class, $namespace)) {
                 $className = substr($class, strlen($namespace) + 1);
                 $file = $dir . DIRECTORY_SEPARATOR . str_replace('\\', '', $className) . '.php';
                 if (!file_exists($file) && $container->getParameter('kernel.debug')) {
                     $registry = $container->get('doctrine');
                     if (1 === Version::compare('2.2.0')) {
                         $originalClassName = substr($className, 0, -5);
                     } else {
                         $originalClassName = ClassUtils::getRealClass($className);
                         $originalClassName = str_replace('\\', '', $originalClassName);
                     }
                     // Tries to auto-generate the proxy file
                     foreach ($registry->getEntityManagers() as $em) {
                         if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
                             $classes = $em->getMetadataFactory()->getAllMetadata();
                             foreach ($classes as $class) {
                                 $name = str_replace('\\', '', $class->name);
                                 if ($name == $originalClassName) {
                                     $em->getProxyFactory()->generateProxyClasses(array($class));
                                 }
                             }
                         }
                     }
                     clearstatcache($file);
                     if (!file_exists($file)) {
                         throw new \RuntimeException(sprintf('The proxy file "%s" does not exist. If you still have objects serialized in the session, you need to clear the session manually.', $file));
                     }
                 }
                 require $file;
             }
         };
         spl_autoload_register($this->autoloader);
     }
 }
 private function doUpdate(ClassMetadataFactory $metadataFactory, PhpcrMetadata $odmMetadata, CtMetadata $ctMetadata, $document)
 {
     $documentId = $odmMetadata->getIdentifierValue($document);
     foreach ($odmMetadata->childrenMappings as $childrenField) {
         // if the children field is not managed by the CT component,
         // continue
         if (!isset($ctMetadata->propertyMetadata[$childrenField])) {
             continue;
         }
         $children = $odmMetadata->getFieldValue($document, $childrenField);
         // note that we do not preserve array keys. PHPCR ODM will return a
         // children collection using the PHPCR property names as keys, so
         // we currently have no control over how these keys populated.
         $index = 0;
         foreach ($children as $child) {
             $childMetadata = $metadataFactory->getMetadataFor(ClassUtils::getRealClass(get_class($child)));
             $newId = sprintf('%s/%s', $documentId, $this->encoder->encode($childrenField, $index++));
             $childMetadata->setIdentifierValue($child, $newId);
         }
     }
 }
Exemple #24
0
 /**
  * {@inheritDoc}
  */
 public function boot()
 {
     // Register an autoloader for proxies to avoid issues when unserializing them
     // when the ORM is used.
     if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) {
         $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace');
         $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
         // See https://github.com/symfony/symfony/pull/3419 for usage of
         // references
         $container =& $this->container;
         $this->autoloader = function ($class) use($namespace, $dir, &$container) {
             if (0 === strpos($class, $namespace)) {
                 $fileName = str_replace('\\', '', substr($class, strlen($namespace) + 1));
                 $file = $dir . DIRECTORY_SEPARATOR . $fileName . '.php';
                 if (!is_file($file) && $container->getParameter('kernel.debug')) {
                     $originalClassName = ClassUtils::getRealClass($class);
                     /** @var $registry Registry */
                     $registry = $container->get('doctrine');
                     // Tries to auto-generate the proxy file
                     /** @var $em \Doctrine\ORM\EntityManager */
                     foreach ($registry->getManagers() as $em) {
                         if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
                             $classes = $em->getMetadataFactory()->getAllMetadata();
                             foreach ($classes as $classMetadata) {
                                 if ($classMetadata->name == $originalClassName) {
                                     $em->getProxyFactory()->generateProxyClasses(array($classMetadata));
                                 }
                             }
                         }
                     }
                     clearstatcache($file);
                 }
                 if (file_exists($file)) {
                     require $file;
                 }
             }
         };
         spl_autoload_register($this->autoloader);
     }
 }
 public function prePersist(LifecycleEventArgs $args)
 {
     $document = $args->getObject();
     $metadataFactory = $args->getObjectManager()->getMetadataFactory();
     $odmMetadata = $metadataFactory->getMetadataFor(ClassUtils::getRealClass(get_class($document)));
     if (null === ($ctMetadata = $this->metadataFactory->getMetadataForClass($odmMetadata->getName()))) {
         return;
     }
     foreach ($odmMetadata->childrenMappings as $childrenField) {
         // if the children field is not managed by the CT component,
         // continue
         if (!isset($ctMetadata->propertyMetadata[$childrenField])) {
             continue;
         }
         $childCtMetadata = $ctMetadata->propertyMetadata[$childrenField];
         $children = $odmMetadata->getFieldValue($document, $childrenField);
         if (!$children) {
             continue;
         }
         $this->stack[] = ['children' => $children, 'ct_metadata' => $childCtMetadata, 'field' => $childrenField];
     }
 }
 /**
  * Updates UrlInformation with new values if they are not already set.
  *
  * @param UrlInformation $urlInformation The value object to update.
  * @param object         $object         The sitemap element to get values from.
  * @param string         $sitemap        Name of the sitemap being built.
  */
 public function guessValues(UrlInformation $urlInformation, $object, $sitemap)
 {
     if (null !== $urlInformation->getLastModification()) {
         return;
     }
     $className = ClassUtils::getRealClass(get_class($object));
     $manager = $this->managerRegistry->getManagerForClass($className);
     if (!$manager instanceof DocumentManager) {
         return;
     }
     /** @var ClassMetadata $metadata */
     $metadata = $manager->getClassMetadata($className);
     $mixins = $metadata->getMixins();
     if (!in_array('mix:lastModified', $mixins)) {
         return;
     }
     $fieldName = $this->getFieldName($metadata);
     if (null === $fieldName) {
         return;
     }
     $urlInformation->setLastModification($metadata->getFieldValue($object, $fieldName));
 }
 /**
  * @param mixed $data
  * @param bool  $includeCollectionTag
  * @param bool  $processNestedData
  *
  * @return array
  */
 protected function getTags($data, $includeCollectionTag, $processNestedData)
 {
     $tags = [];
     if (is_object($data)) {
         $class = ClassUtils::getClass($data);
         /** @var EntityManager $em */
         $em = $this->doctrine->getManagerForClass($class);
         $uow = $em->getUnitOfWork();
         // tag only in case if it's not a new object
         if ($this->isNewEntity($data, $uow)) {
             $tags[] = implode('_', array_merge([$this->convertToTag($class)], $uow->getEntityIdentifier($data)));
             if ($processNestedData) {
                 $tags = array_merge($tags, $this->collectNestedDataTags($data, $em->getClassMetadata($class)));
             }
         }
     } else {
         $class = ClassUtils::getRealClass($data);
     }
     if ($includeCollectionTag) {
         $tags[] = $this->convertToTag($class) . self::COLLECTION_SUFFIX;
     }
     return $tags;
 }
 /**
  * @param string $entityClass
  *
  * @return array
  */
 protected function getEntityVariableGetters($entityClass)
 {
     $entityClass = ClassUtils::getRealClass($entityClass);
     if (!$this->emailConfigProvider->hasConfig($entityClass)) {
         return [];
     }
     $result = [];
     $reflClass = new \ReflectionClass($entityClass);
     $fieldConfigs = $this->emailConfigProvider->getConfigs($entityClass);
     foreach ($fieldConfigs as $fieldConfig) {
         if (!$fieldConfig->is('available_in_template')) {
             continue;
         }
         /** @var FieldConfigId $fieldId */
         $fieldId = $fieldConfig->getId();
         list($varName, $getter) = $this->getFieldAccessInfo($reflClass, $fieldId->getFieldName());
         if (!$varName) {
             continue;
         }
         $resultGetter = $getter;
         $formatters = $this->formatterManager->guessFormatters($fieldId);
         if ($formatters && count($formatters)) {
             $resultGetter = array_merge(['property_path' => $getter], $formatters);
         }
         $result[$varName] = $resultGetter;
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function hasClassMetadataForEntity($object)
 {
     $className = ClassUtils::getRealClass(get_class($object));
     return $this->getMetadataFactory()->hasMetadataFor($className);
 }
 /**
  * Gets the class metadata descriptor for a class.
  *
  * @param string $className The name of the class.
  *
  * @return ClassMetadata
  *
  * @throws ReflectionException
  * @throws MappingException
  */
 public function getMetadataFor($className)
 {
     if (isset($this->loadedMetadata[$className])) {
         return $this->loadedMetadata[$className];
     }
     // Check for namespace alias
     if (strpos($className, ':') !== false) {
         list($namespaceAlias, $simpleClassName) = explode(':', $className, 2);
         $realClassName = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
     } else {
         $realClassName = ClassUtils::getRealClass($className);
     }
     if (isset($this->loadedMetadata[$realClassName])) {
         // We do not have the alias name in the map, include it
         return $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
     }
     $loadingException = null;
     try {
         if ($this->cacheDriver) {
             if (($cached = $this->cacheDriver->fetch($realClassName . $this->cacheSalt)) !== false) {
                 $this->loadedMetadata[$realClassName] = $cached;
                 $this->wakeupReflection($cached, $this->getReflectionService());
             } else {
                 foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
                     $this->cacheDriver->save($loadedClassName . $this->cacheSalt, $this->loadedMetadata[$loadedClassName], null);
                 }
             }
         } else {
             $this->loadMetadata($realClassName);
         }
     } catch (MappingException $loadingException) {
         if (!($fallbackMetadataResponse = $this->onNotFoundMetadata($realClassName))) {
             throw $loadingException;
         }
         $this->loadedMetadata[$realClassName] = $fallbackMetadataResponse;
     }
     if ($className !== $realClassName) {
         // We do not have the alias name in the map, include it
         $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
     }
     return $this->loadedMetadata[$className];
 }