本文整理汇总了PHP中Symfony\Component\Security\Core\Util\ClassUtils类的典型用法代码示例。如果您正苦于以下问题:PHP ClassUtils类的具体用法?PHP ClassUtils怎么用?PHP ClassUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClassUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getQueryContactInformationFields
/**
* @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);
}
示例2: merge
/**
* {@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());
}
}
示例3: testMerge
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);
}
示例4: onKernelController
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.');
}
示例5: getClassAlias
/**
* 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);
}
示例6: fromToken
/**
* 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));
}
示例7: getAuditEntryFieldClass
/**
* @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);
}
示例8: getClassName
/**
* 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;
}
示例9: postPersist
/**
* @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);
}
}
示例10: checkEntities
/**
* @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;
}
示例11: getOwnerType
/**
* @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');
}
示例12: createAction
/**
* @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);
}
示例13: postPersist
/**
* @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);
}
}
示例14: getSecurityIdentities
/**
* 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;
}
示例15: getAuditEntryFieldClass
/**
* @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);
}