当前位置: 首页>>代码示例>>PHP>>正文


PHP Util\ClassUtils类代码示例

本文整理汇总了PHP中Doctrine\Common\Util\ClassUtils的典型用法代码示例。如果您正苦于以下问题:PHP ClassUtils类的具体用法?PHP ClassUtils怎么用?PHP ClassUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClassUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: transform

 /**
  * {@inheritdoc}
  */
 public function transform($value)
 {
     if (!$value) {
         return '';
     }
     if (is_array($value)) {
         $result = [];
         $user = $this->securityFacade->getToken()->getUser();
         foreach ($value as $target) {
             if (ClassUtils::getClass($user) === ClassUtils::getClass($target) && $user->getId() === $target->getId()) {
                 continue;
             }
             if ($fields = $this->mapper->getEntityMapParameter(ClassUtils::getClass($target), 'title_fields')) {
                 $text = [];
                 foreach ($fields as $field) {
                     $text[] = $this->mapper->getFieldValue($target, $field);
                 }
             } else {
                 $text = [(string) $target];
             }
             $text = implode(' ', $text);
             if ($label = $this->getClassLabel(ClassUtils::getClass($target))) {
                 $text .= ' (' . $label . ')';
             }
             $result[] = json_encode(['text' => $text, 'id' => json_encode(['entityClass' => ClassUtils::getClass($target), 'entityId' => $target->getId()])]);
         }
         $value = implode(';', $result);
     }
     return $value;
 }
开发者ID:northdakota,项目名称:platform,代码行数:33,代码来源:ContextsToViewTransformer.php

示例2: postSetData

 /**
  * @param FormEvent $event
  */
 public function postSetData(FormEvent $event)
 {
     $form = $event->getForm();
     if ($form->getParent()) {
         return;
     }
     if (!$form->has($this->fieldName)) {
         return;
     }
     $isEntityExists = false;
     $entity = $event->getData();
     if ($entity) {
         if (!is_object($entity)) {
             return;
         }
         $entityClass = ClassUtils::getClass($entity);
         $entityManager = $this->managerRegistry->getManagerForClass($entityClass);
         if (!$entityManager) {
             return;
         }
         $entityIdentifier = $entityManager->getClassMetadata($entityClass)->getIdentifierValues($entity);
         $isEntityExists = !empty($entityIdentifier);
     }
     // if entity exists and assign is not granted - replace field with disabled text field,
     // otherwise - set default owner value
     if ($isEntityExists) {
         $this->replaceOwnerField($form);
     } else {
         $this->setPredefinedOwner($form);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:34,代码来源:OwnerFormSubscriber.php

示例3: getActivityContext

 /**
  * Returns the context for the given activity class and id
  *
  * @param string $class The FQCN of the activity entity
  * @param        $id
  *
  * @return array
  */
 public function getActivityContext($class, $id)
 {
     $currentUser = $this->securityTokenStorage->getToken()->getUser();
     $userClass = ClassUtils::getClass($currentUser);
     $entity = $this->doctrineHelper->getEntity($class, $id);
     $result = [];
     if (!$entity || !$entity instanceof ActivityInterface) {
         return $result;
     }
     $targets = $entity->getActivityTargetEntities();
     $entityProvider = $this->configManager->getProvider('entity');
     foreach ($targets as $target) {
         $targetClass = ClassUtils::getClass($target);
         $targetId = $target->getId();
         if ($userClass === $targetClass && $currentUser->getId() === $targetId) {
             continue;
         }
         $item = [];
         $config = $entityProvider->getConfig($targetClass);
         $safeClassName = $this->entityClassNameHelper->getUrlSafeClassName($targetClass);
         $item = $this->prepareItemTitle($item, $targetClass, $target, $targetId);
         $item['activityClassAlias'] = $this->entityAliasResolver->getPluralAlias($class);
         $item['entityId'] = $id;
         $item['targetId'] = $targetId;
         $item['targetClassName'] = $safeClassName;
         $item['icon'] = $config->get('icon');
         $item['link'] = $this->getContextLink($targetClass, $targetId);
         $item = $this->dispatchContextTitle($item, $targetClass);
         $result[] = $item;
     }
     return $result;
 }
开发者ID:woei66,项目名称:platform,代码行数:40,代码来源:ActivityContextApiEntityManager.php

示例4: handleOnFlush

 /**
  * Handle onFlush event
  *
  * @param OnFlushEventArgs $event
  */
 public function handleOnFlush(OnFlushEventArgs $event)
 {
     $em = $event->getEntityManager();
     $uow = $em->getUnitOfWork();
     $newEntities = $uow->getScheduledEntityInsertions();
     foreach ($newEntities as $entity) {
         if ($entity instanceof Call) {
             $hasChanges = $this->activityManager->addActivityTarget($entity, $entity->getOwner());
             // recompute change set if needed
             if ($hasChanges) {
                 $uow->computeChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity);
             }
         }
     }
     $changedEntities = $uow->getScheduledEntityUpdates();
     foreach ($changedEntities as $entity) {
         if ($entity instanceof Call) {
             $hasChanges = false;
             $changeSet = $uow->getEntityChangeSet($entity);
             foreach ($changeSet as $field => $values) {
                 if ($field === 'owner') {
                     list($oldValue, $newValue) = $values;
                     if ($oldValue !== $newValue) {
                         $hasChanges |= $this->activityManager->replaceActivityTarget($entity, $oldValue, $newValue);
                     }
                     break;
                 }
             }
             // recompute change set if needed
             if ($hasChanges) {
                 $uow->computeChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity);
             }
         }
     }
 }
开发者ID:antrampa,项目名称:crm,代码行数:40,代码来源:CallActivityManager.php

示例5: isEntity

 /**
  * Check object status is enity
  *
  * @param object|string $entity
  * @return bool
  */
 protected function isEntity($entity)
 {
     if (is_object($entity)) {
         $entity = ClassUtils::getClass($entity);
     }
     return !$this->entityManager->getMetadataFactory()->isTransient($entity);
 }
开发者ID:pecinaon,项目名称:doctrine-mapper,代码行数:13,代码来源:BaseMapper.php

示例6: addOwnerField

 /**
  * Add owner field to forms
  *
  * @param BeforeFormRenderEvent $event
  */
 public function addOwnerField(BeforeFormRenderEvent $event)
 {
     $environment = $event->getTwigEnvironment();
     $data = $event->getFormData();
     $form = $event->getForm();
     $label = false;
     $entityProvider = $this->configManager->getProvider('entity');
     if (is_object($form->vars['value'])) {
         $className = ClassUtils::getClass($form->vars['value']);
         if (class_exists($className) && $entityProvider->hasConfig($className, 'owner')) {
             $config = $entityProvider->getConfig($className, 'owner');
             $label = $config->get('label');
         }
     }
     $ownerField = $environment->render("OroOrganizationBundle::owner.html.twig", array('form' => $form, 'label' => $label));
     /**
      * Setting owner field as first field in first data block
      */
     if (!empty($data['dataBlocks'])) {
         if (isset($data['dataBlocks'][0]['subblocks'])) {
             if (!isset($data['dataBlocks'][0]['subblocks'][0])) {
                 $data['dataBlocks'][0]['subblocks'][0] = ['data' => []];
             }
             array_unshift($data['dataBlocks'][0]['subblocks'][0]['data'], $ownerField);
         }
     }
     $event->setFormData($data);
 }
开发者ID:Maksold,项目名称:platform,代码行数:33,代码来源:FormListener.php

示例7: onFlush

 /**
  * @param OnFlushEventArgs $args
  */
 public function onFlush(OnFlushEventArgs $args)
 {
     $this->initializeFromEventArgs($args);
     $entities = array_merge($this->uow->getScheduledEntityInsertions(), $this->uow->getScheduledEntityDeletions(), $this->uow->getScheduledEntityUpdates());
     /** @var Opportunity[] $entities */
     $entities = array_filter($entities, function ($entity) {
         return 'OroCRM\\Bundle\\SalesBundle\\Entity\\Opportunity' === ClassUtils::getClass($entity);
     });
     foreach ($entities as $entity) {
         if (!$entity->getId() && $this->isValuable($entity)) {
             // handle creation, just add to prev lifetime value and recalculate change set
             $b2bCustomer = $entity->getCustomer();
             $b2bCustomer->setLifetime($b2bCustomer->getLifetime() + $entity->getCloseRevenue());
             $this->scheduleUpdate($b2bCustomer);
             $this->uow->computeChangeSet($this->em->getClassMetadata(ClassUtils::getClass($b2bCustomer)), $b2bCustomer);
         } elseif ($this->uow->isScheduledForDelete($entity) && $this->isValuable($entity)) {
             $this->scheduleUpdate($entity->getCustomer());
         } elseif ($this->uow->isScheduledForUpdate($entity)) {
             // handle update
             $changeSet = $this->uow->getEntityChangeSet($entity);
             if ($this->isChangeSetValuable($changeSet)) {
                 if (!empty($changeSet['customer']) && $changeSet['customer'][0] instanceof B2bCustomer && B2bCustomerRepository::VALUABLE_STATUS === $this->getOldStatus($entity, $changeSet)) {
                     // handle change of b2b customer
                     $this->scheduleUpdate($changeSet['customer'][0]);
                 }
                 if ($this->isValuable($entity, isset($changeSet['closeRevenue'])) || B2bCustomerRepository::VALUABLE_STATUS === $this->getOldStatus($entity, $changeSet) && $entity->getCustomer()) {
                     $this->scheduleUpdate($entity->getCustomer());
                 }
             }
         }
     }
 }
开发者ID:antrampa,项目名称:crm,代码行数:35,代码来源:B2bCustomerLifetimeListener.php

示例8: invalidateProcess

 /**
  * @param $entity
  */
 public function invalidateProcess($entity)
 {
     $handler = $this->getHandlerByClass(ClassUtils::getClass($entity));
     if ($handler) {
         $handler->invalidateProcess($entity);
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:EntityApiHandlerProcessor.php

示例9: name

 /**
  * {@inheritdoc}
  */
 public function name($objectOrClass)
 {
     $class = is_object($objectOrClass) ? ClassUtils::getClass($objectOrClass) : $objectOrClass;
     if (!isset($this->names[$class])) {
         $nsParts = array_map(function ($nsPart) {
             return explode('_', StringsUtil::toUnderscore($nsPart));
         }, explode('\\', $class));
         $offset = array_search(['entity'], $nsParts);
         if ($offset) {
             $nsParts = array_slice($nsParts, $offset + 1);
         }
         $nsPartsCount = count($nsParts);
         for ($i = 0; $i < $nsPartsCount - 1; $i++) {
             if (array_intersect($nsParts[$i], $nsParts[$i + 1]) === $nsParts[$i]) {
                 unset($nsParts[$i]);
             }
         }
         $parts = [];
         foreach ($nsParts as $nsPart) {
             $parts = array_merge($parts, $nsPart);
         }
         $this->names[$class] = implode('_', $parts);
     }
     return $this->names[$class];
 }
开发者ID:darvinstudio,项目名称:darvin-utils,代码行数:28,代码来源:ObjectNamer.php

示例10: onFlush

 /**
  * Collect changes that were done
  * Generates tags and store in protected variable
  *
  * @param OnFlushEventArgs $event
  */
 public function onFlush(OnFlushEventArgs $event)
 {
     if (!$this->isApplicationInstalled) {
         return;
     }
     $em = $event->getEntityManager();
     $uow = $em->getUnitOfWork();
     $entities = array_merge($uow->getScheduledEntityDeletions(), $uow->getScheduledEntityInsertions(), $uow->getScheduledEntityUpdates());
     $collections = array_merge($uow->getScheduledCollectionUpdates(), $uow->getScheduledCollectionDeletions());
     foreach ($collections as $collection) {
         $owner = $collection->getOwner();
         if (!in_array($owner, $entities, true)) {
             $entities[] = $owner;
         }
     }
     $generator = $this->sender->getGenerator();
     foreach ($entities as $entity) {
         if (!in_array(ClassUtils::getClass($entity), $this->skipTrackingFor)) {
             // invalidate collection view pages only when entity has been added or removed
             $includeCollectionTag = $uow->isScheduledForInsert($entity) || $uow->isScheduledForDelete($entity);
             $this->collectedTags = array_merge($this->collectedTags, $generator->generate($entity, $includeCollectionTag));
         }
     }
     $this->collectedTags = array_unique($this->collectedTags);
 }
开发者ID:xamin123,项目名称:platform,代码行数:31,代码来源:DoctrineTagEventListener.php

示例11: isApplicable

 /**
  * Checks if the entity can have comments
  *
  * @param object|null $entity
  *
  * @return bool
  */
 public function isApplicable($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || !$this->securityFacade->isGranted('oro_comment_view')) {
         return false;
     }
     return $this->commentAssociationHelper->isCommentAssociationEnabled(ClassUtils::getClass($entity));
 }
开发者ID:olegpopadko,项目名称:platform,代码行数:14,代码来源:CommentPlaceholderFilter.php

示例12: getSnapshotDeleteQueryBuilderByEntities

 /**
  * Returns DELETE query builder with conditions for deleting from snapshot table by entity
  *
  * @param array $entities
  * @throws \InvalidArgumentException
  * @return QueryBuilder|null
  */
 protected function getSnapshotDeleteQueryBuilderByEntities(array $entities)
 {
     if (empty($entities)) {
         throw new \InvalidArgumentException('List of entity can not be empty');
     }
     $deleteParams = array();
     $entityManager = $this->getEntityManager();
     $segmentQB = $entityManager->createQueryBuilder();
     $segmentQB->select('s.id, s.entity')->from('OroSegmentBundle:Segment', 's');
     foreach ($entities as $key => $entity) {
         if (is_array($entity) && array_key_exists('id', $entity)) {
             $entityId = $entity['id'];
             $className = ClassUtils::getClass($entity['entity']);
         } else {
             /** @var object $entity */
             $className = ClassUtils::getClass($entity);
             $metadata = $entityManager->getClassMetadata($className);
             $entityIds = $metadata->getIdentifierValues($entity);
             $entityId = reset($entityIds);
         }
         if (!$entityId) {
             continue;
         }
         if (!isset($deleteParams[$className])) {
             $segmentQB->orWhere('s.entity = :className' . $key)->setParameter('className' . $key, $className);
         }
         $deleteParams[$className]['entityIds'][] = (string) $entityId;
     }
     $segments = $segmentQB->getQuery()->getResult();
     foreach ($segments as $segment) {
         $deleteParams[$segment['entity']]['segmentIds'][] = (string) $segment['id'];
     }
     return $this->getDeleteQueryBuilderByParameters($deleteParams);
 }
开发者ID:xamin123,项目名称:platform,代码行数:41,代码来源:SegmentSnapshotRepository.php

示例13: buildCacheEntry

 /**
  * {@inheritdoc}
  */
 public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $entity)
 {
     $data = $this->uow->getOriginalEntityData($entity);
     $data = array_merge($data, $key->identifier);
     // why update has no identifier values ?
     foreach ($metadata->associationMappings as $name => $assoc) {
         if (!isset($data[$name])) {
             continue;
         }
         if (!isset($assoc['cache']) || !($assoc['type'] & ClassMetadata::TO_ONE)) {
             unset($data[$name]);
             continue;
         }
         if (!isset($assoc['id'])) {
             $targetClass = ClassUtils::getClass($data[$name]);
             $targetId = $this->uow->getEntityIdentifier($data[$name]);
             $data[$name] = new AssociationCacheEntry($targetClass, $targetId);
             continue;
         }
         // handle association identifier
         $targetId = is_object($data[$name]) && $this->uow->isInIdentityMap($data[$name]) ? $this->uow->getEntityIdentifier($data[$name]) : $data[$name];
         // @TODO - fix it !
         // handle UnitOfWork#createEntity hash generation
         if (!is_array($targetId)) {
             $data[reset($assoc['joinColumnFieldNames'])] = $targetId;
             $targetEntity = $this->em->getClassMetadata($assoc['targetEntity']);
             $targetId = array($targetEntity->identifier[0] => $targetId);
         }
         $data[$name] = new AssociationCacheEntry($assoc['targetEntity'], $targetId);
     }
     return new EntityCacheEntry($metadata->name, $data);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:35,代码来源:DefaultEntityHydrator.php

示例14: supports

 /**
  * {@inheritdoc}
  */
 public function supports(PuliResource $resource)
 {
     if (false === $resource instanceof CmfResource) {
         return false;
     }
     return $this->metadataFactory->hasMetadataFor(ClassUtils::getRealClass($resource->getPayloadType()));
 }
开发者ID:symfony-cmf,项目名称:resource,代码行数:10,代码来源:PhpcrOdmEnhancer.php

示例15: save

 /**
  * {@inheritdoc}
  */
 public function save($group, array $options = [])
 {
     /* @var GroupInterface */
     if (!$group instanceof GroupInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\GroupInterface", "%s" provided.', ClassUtils::getClass($group)));
     }
     $this->eventDispatcher->dispatch(GroupEvents::PRE_SAVE, new GenericEvent($group));
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->versionContext->addContextInfo(sprintf('Comes from variant group %s', $group->getCode()), $this->productClassName);
     if ($group->getType()->isVariant()) {
         $template = $group->getProductTemplate();
         if (null !== $template) {
             $this->templateMediaManager->handleProductTemplateMedia($template);
         }
     }
     $this->objectManager->persist($group);
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (count($options['add_products']) > 0) {
         $this->addProducts($options['add_products']);
     }
     if (count($options['remove_products']) > 0) {
         $this->removeProducts($options['remove_products']);
     }
     if ($group->getType()->isVariant() && true === $options['copy_values_to_products']) {
         $this->copyVariantGroupValues($group);
     }
     $this->eventDispatcher->dispatch(GroupEvents::POST_SAVE, new GenericEvent($group));
 }
开发者ID:umpirsky,项目名称:pim-community-dev,代码行数:33,代码来源:GroupSaver.php


注:本文中的Doctrine\Common\Util\ClassUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。