php Symfony-Component-Security-Core-Util-ClassUtils类(方法)实例源码

下面列出了php Symfony-Component-Security-Core-Util-ClassUtils 类(方法)源码代码实例,从而了解它的用法。

作者:daird    项目:cr   
/**
  * @param AbstractQueryDesigner $abstractQueryDesigner
  * @param object $entity
  * @param string $type
  *
  * @return string[]
  */
 public function getQueryContactInformationFields(AbstractQueryDesigner $abstractQueryDesigner, $entity, $type)
 {
     $contactInformationFields = $this->contactInformationFieldHelper->getEntityContactInformationColumns(ClassUtils::getRealClass($entity));
     if (empty($contactInformationFields)) {
         return [];
     }
     $definitionColumns = [];
     $definition = $abstractQueryDesigner->getDefinition();
     if ($definition) {
         $definition = json_decode($definition, JSON_OBJECT_AS_ARRAY);
         if (!empty($definition['columns'])) {
             $definitionColumns = array_map(function (array $columnDefinition) {
                 return $columnDefinition['name'];
             }, $definition['columns']);
         }
     }
     $typedFields = array_keys(array_filter($contactInformationFields, function ($contactInformationField) use($type) {
         return $contactInformationField === $type;
     }));
     if (!empty($definitionColumns)) {
         $typedFields = array_intersect($typedFields, $definitionColumns);
     }
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     return array_map(function ($typedField) use($propertyAccessor, $entity) {
         return (string) $propertyAccessor->getValue($entity, $typedField);
     }, $typedFields);
 }

作者:Maksol    项目:platfor   
/**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $sourceEntity = $fieldData->getSourceEntity();
     if ($masterEntity->getId() !== $sourceEntity->getId()) {
         $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $masterEntity->getId());
         $notes = $queryBuilder->getQuery()->getResult();
         if (!empty($notes)) {
             $entityManager = $this->doctrineHelper->getEntityManager(current($notes));
             foreach ($notes as $note) {
                 $entityManager->remove($note);
             }
         }
         $queryBuilder = $this->doctrineHelper->getEntityRepository('OroNoteBundle:Note')->getBaseAssociatedNotesQB(ClassUtils::getRealClass($masterEntity), $sourceEntity->getId());
         $notes = $queryBuilder->getQuery()->getResult();
         if (!empty($notes)) {
             foreach ($notes as $note) {
                 $note->setTarget($masterEntity);
             }
         }
         $fieldMetadata = $fieldData->getMetadata();
         $activityClass = $fieldMetadata->get('type');
         $entityClass = ClassUtils::getRealClass($sourceEntity);
         $queryBuilder = $this->doctrineHelper->getEntityRepository(ActivityList::ENTITY_NAME)->getActivityListQueryBuilderByActivityClass($entityClass, $sourceEntity->getId(), $activityClass);
         $activityListItems = $queryBuilder->getQuery()->getResult();
         $activityIds = ArrayUtils::arrayColumn($activityListItems, 'id');
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
     }
 }

作者:startup    项目:platform-   
public function testMerge()
 {
     $account1 = new User();
     $account2 = new User();
     $this->setId($account1, 1);
     $this->setId($account2, 2);
     $entityMetadata = new EntityMetadata(['type' => ClassUtils::getRealClass($account1)]);
     $entityData = new EntityData($entityMetadata, [$account1, $account2]);
     $entityData->setMasterEntity($account1);
     $fieldData = new FieldData($entityData, new FieldMetadata());
     $fieldData->setMode(MergeModes::NOTES_REPLACE);
     $fieldData->setSourceEntity($account2);
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock();
     $queryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf());
     $queryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([new ExtendNote()]));
     $repository = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\Repository\\ActivityListRepository')->disableOriginalConstructor()->setMethods(['getBaseAssociatedNotesQB', 'getActivityListQueryBuilderByActivityClass'])->getMock();
     $repository->expects($this->any())->method('getBaseAssociatedNotesQB')->willReturn($queryBuilder);
     $activityQueryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->setMethods(['getQuery', 'getResult'])->getMock();
     $activityQueryBuilder->expects($this->any())->method('getQuery')->will($this->returnSelf());
     $activityQueryBuilder->expects($this->any())->method('getResult')->will($this->returnValue([['id' => 1, 'relatedActivityId' => 11], ['id' => 3, 'relatedActivityId' => 2]]));
     $repository->expects($this->any())->method('getActivityListQueryBuilderByActivityClass')->willReturn($activityQueryBuilder);
     $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['remove'])->getMock();
     $this->doctrineHelper->expects($this->any())->method('getEntityRepository')->willReturn($repository);
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->willReturn($entityManager);
     $this->activityListManager->expects($this->once())->method('replaceActivityTargetWithPlainQuery');
     $this->strategy->merge($fieldData);
 }

作者:kassne    项目:auth-bundl   
public function onKernelController(FilterControllerEvent $event)
 {
     if (!$this->securityContext->getToken()) {
         return true;
     }
     $controller = $event->getController();
     list($object, $method) = $controller;
     $className = ClassUtils::getRealClass($object);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionMethod = $reflectionClass->getMethod($method);
     $classAnnotations = $this->annotationReader->getClassAnnotations($reflectionClass);
     $methodsAnnotations = $this->annotationReader->getMethodAnnotations($reflectionMethod);
     $allAnnotations = array_merge($classAnnotations, $methodsAnnotations);
     $ruleAnnotations = array_filter($allAnnotations, function ($annotation) {
         return $annotation instanceof Rule;
     });
     foreach ($ruleAnnotations as $ruleAnnotation) {
         if (is_array($ruleAnnotation->rules)) {
             $rules = $ruleAnnotation->rules;
         } else {
             $rules = explode(',', $ruleAnnotation->rules);
         }
         foreach ($rules as $rule) {
             $rule = trim($rule);
             if (empty($rule)) {
                 continue;
             }
             if ($this->securityContext->isGranted($rule)) {
                 return true;
             }
         }
     }
     throw new AccessDeniedException('The current user has no permissions on this action.');
 }

作者:Maksol    项目:platfor   
/**
  * Get class alias of specified entity
  *
  * @param object $object
  * @param bool   $isPlural
  *
  * @return null|string
  */
 public function getClassAlias($object, $isPlural = false)
 {
     if (!is_object($object)) {
         return null;
     }
     $className = ClassUtils::getRealClass($object);
     return $isPlural ? $this->entityAliasResolver->getPluralAlias($className) : $this->entityAliasResolver->getAlias($className);
 }

作者:laubosslin    项目:la   
/**
  * Creates a user security identity from a TokenInterface
  *
  * @param TokenInterface $token
  * @return UserSecurityIdentity
  */
 public static function fromToken(TokenInterface $token)
 {
     $user = $token->getUser();
     if ($user instanceof UserInterface) {
         return self::fromAccount($user);
     }
     return new self((string) $user, is_object($user) ? ClassUtils::getRealClass($user) : ClassUtils::getRealClass($token));
 }

作者:any    项目:platfor   
/**
  * @param AbstractUser $user
  * @return string
  */
 public function getAuditEntryFieldClass(AbstractUser $user)
 {
     $userClass = ClassUtils::getRealClass($user);
     if (!$this->entryFieldMap->containsKey($userClass)) {
         throw new \InvalidArgumentException(sprintf('Audit entry field not found for "%s"', $userClass));
     }
     return $this->entryFieldMap->get($userClass);
 }

作者:northdakot    项目:platfor   
/**
  * Get FQCN of specified entity
  *
  * @param object $object
  * @param bool   $escape Set TRUE to escape the class name for insertion into a route,
  *                       replacing \ with _ characters
  *
  * @return string
  */
 public function getClassName($object, $escape = false)
 {
     if (!is_object($object)) {
         return null;
     }
     $className = ClassUtils::getRealClass($object);
     return $escape ? $this->entityRoutingHelper->getUrlSafeClassName($className) : $className;
 }

作者:admarin198    项目:ticket   
/**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $object = $args->getEntity();
     if ($object instanceof AclAwareInterface) {
         $rules = $this->aclRulesManager->getEntityRule(ClassUtils::getRealClass($object));
         $this->aclManager->setAcl($object, $rules);
     }
 }

作者:ramunas    项目:platfor   
/**
  * @param array $entities
  * @return bool
  */
 protected function checkEntities(array $entities)
 {
     foreach ($entities as $entity) {
         if (in_array(ClassUtils::getRealClass($entity), $this->securityClasses, true)) {
             return true;
         }
     }
     return false;
 }

作者:snorche    项目:platfor   
/**
  * @param object $entity
  * @return string
  */
 public function getOwnerType($entity)
 {
     $ownerClassName = ClassUtils::getRealClass($entity);
     if (!$this->configProvider->hasConfig($ownerClassName)) {
         return null;
     }
     $config = $this->configProvider->getConfig($ownerClassName);
     return $config->get('owner_type');
 }

作者:Maksol    项目:platfor   
/**
  * @Route("/create/{entityClass}/{entityId}", name="oro_note_create")
  *
  * @Template("OroNoteBundle:Note:update.html.twig")
  * @AclAncestor("oro_note_create")
  */
 public function createAction($entityClass, $entityId)
 {
     $entityRoutingHelper = $this->getEntityRoutingHelper();
     $entity = $entityRoutingHelper->getEntity($entityClass, $entityId);
     $entityClass = ClassUtils::getRealClass($entity);
     $noteEntity = new Note();
     $noteEntity->setTarget($entity);
     $formAction = $entityRoutingHelper->generateUrlByRequest('oro_note_create', $this->getRequest(), $entityRoutingHelper->getRouteParameters($entityClass, $entityId));
     return $this->update($noteEntity, $formAction);
 }

作者:admarin198    项目:ticket   
/**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $className = ClassUtils::getRealClass($entity);
     $classRules = $this->aclRulesManager->getEntityRule($className);
     if ($classRules !== false) {
         $this->aclRulesManager->clearCreateEntityPermissions($classRules);
         $this->aclManager->setAcl($entity, $classRules);
     }
 }

作者:ReissClothin    项目:BackBe   
/**
  * Retrieves the available security identities for the given token.
  *
  * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token
  *
  * @return array An array of SecurityIdentityInterface implementations
  */
 public function getSecurityIdentities(TokenInterface $token)
 {
     $sids = parent::getSecurityIdentities($token);
     if ($token->getUser() instanceof \BackBee\CoreDomain\Security\User) {
         foreach ($token->getUser()->getGroups() as $group) {
             $securityIdentity = new UserSecurityIdentity($group->getObjectIdentifier(), ClassUtils::getRealClass($group));
             array_unshift($sids, $securityIdentity);
         }
     }
     return $sids;
 }

作者:gitter-badge    项目:diamantedesk-applicatio   
/**
  * @param DiamanteUser|null $user
  *
  * @return string
  */
 public function getAuditEntryFieldClass(DiamanteUser $user = null)
 {
     if ($user === null) {
         return $this->entryFieldMap->first();
     }
     $userClass = ClassUtils::getRealClass($user);
     if (!$this->entryFieldMap->containsKey($userClass)) {
         throw new \InvalidArgumentException(sprintf('Audit entry field not found for "%s"', $userClass));
     }
     return $this->entryFieldMap->get($userClass);
 }

作者:Maksol    项目:platfor   
/**
  * Gets organization of the given entity
  *
  * @param mixed $object
  * @return mixed
  * @throws InvalidEntityException     If entity is not an object
  * @throws \InvalidArgumentException  If owner property path is not defined
  */
 public function getOrganization($object)
 {
     if (!is_object($object)) {
         throw new InvalidEntityException('$object must be an object.');
     }
     $metadata = $this->metadataProvider->getMetadata(ClassUtils::getRealClass($object));
     if ($metadata->getGlobalOwnerFieldName()) {
         return $this->getValue($object, $metadata->getGlobalOwnerFieldName());
     }
     return null;
 }

作者:symb    项目:symb   
public function getAccessSetList($object)
 {
     $list = array();
     foreach ($this->voterList as $voter) {
         if ($voter->supportsClass(ClassUtils::getRealClass($object))) {
             $attributes = $voter->getAccessSets();
             $list = array_merge_recursive($list, $attributes);
         }
     }
     return $list;
 }

作者:Maksol    项目:platfor   
/**
  * {@inheritdoc}
  */
 public function getValue(ResultRecordInterface $record)
 {
     $entity = $record->getValue('entity');
     $entityClass = ClassUtils::getRealClass($entity);
     if ($this->mappingProvider->isClassSupported($entityClass)) {
         return parent::getValue($record);
     } else {
         $this->params[self::TEMPLATE_KEY] = $this->defaultTemplate;
         return $this->getTemplate()->render(['entityType' => $this->entityConfigProvider->getConfig($entityClass)->get('label'), 'entity' => $entity, 'indexer_item' => $record->getValue('indexer_item')]);
     }
 }

作者:pmd    项目:UnifikSystemBundl   
/**
  * Check if the entity is a Translatable entity
  *
  * @param $entity
  *
  * @return bool
  */
 protected function isTranslatable($entity)
 {
     if (!is_object($entity)) {
         return false;
     }
     // Support Doctrine Proxies
     $realClass = ClassUtils::getRealClass($entity);
     $reflClass = new \ReflectionClass($realClass);
     $traitNames = $reflClass->getTraitNames();
     return in_array('Unifik\\DoctrineBehaviorsBundle\\Model\\Translatable\\Translatable', $traitNames) && $reflClass->hasProperty('translations');
 }

作者:antramp    项目:cr   
/**
  * @param string|object $entityOrClass
  * @param string|null $type
  * @return array
  */
 public function getEntityTypedFields($entityOrClass, $type = null)
 {
     $entityOrClass = ClassUtils::getRealClass($entityOrClass);
     $contactInformationFields = $this->contactInformationFieldHelper->getEntityContactInformationColumns($entityOrClass);
     if (empty($contactInformationFields)) {
         return [];
     }
     if ($type) {
         $contactInformationFields = $this->filterByType($contactInformationFields, $type);
     }
     return $contactInformationFields;
 }


问题


面经


文章

微信
公众号

扫码关注公众号