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


PHP PropertyAccessor::getValue方法代码示例

本文整理汇总了PHP中Symfony\Component\PropertyAccess\PropertyAccessor::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyAccessor::getValue方法的具体用法?PHP PropertyAccessor::getValue怎么用?PHP PropertyAccessor::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\PropertyAccess\PropertyAccessor的用法示例。


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

示例1: renderBlock

 public function renderBlock(\Twig_Template $template, ColumnInterface $column, $object, $context, $blocks)
 {
     try {
         $value = $this->accessor->getValue($object, $column->getName());
     } catch (ExceptionInterface $exception) {
         $value = null;
     }
     $block = 'crudify_field_' . $column->getType();
     // check if the block exists
     $hasBlock = false;
     if (!isset($blocks[$block])) {
         $current = $template;
         do {
             if ($current->hasBlock($block)) {
                 break;
             }
             $current = $current->getParent($context);
         } while ($current instanceof \Twig_Template);
         if ($current instanceof \Twig_Template) {
             $hasBlock = true;
         }
     } else {
         $hasBlock = true;
     }
     if ($hasBlock) {
         $context['value'] = $value;
         $context['definition'] = $column->getParent()->getParent();
         $context['column'] = $column;
         $context['object'] = $object;
         $result = $template->renderBlock($block, $context, $blocks);
     } else {
         $result = htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
     }
     return $result;
 }
开发者ID:bravesheep,项目名称:crudify-bundle,代码行数:35,代码来源:CrudifyExtension.php

示例2: validate

 /**
  * @param object     $entity
  * @param Constraint $constraint
  *
  * @throws UnexpectedTypeException
  * @throws ConstraintDefinitionException
  */
 public function validate($entity, Constraint $constraint)
 {
     if (!$constraint instanceof HasEnabledEntity) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\HasEnabledEntity');
     }
     $enabled = $this->accessor->getValue($entity, $constraint->enabledPath);
     if ($enabled === true) {
         return;
     }
     $objectManager = $this->getProperObjectManager($constraint->objectManager, $entity);
     $this->ensureEntityHasProvidedEnabledField($objectManager, $entity, $constraint->enabledPath);
     $criteria = array($constraint->enabledPath => true);
     $repository = $objectManager->getRepository(get_class($entity));
     $results = $repository->{$constraint->repositoryMethod}($criteria);
     /* If the result is a MongoCursor, it must be advanced to the first
      * element. Rewinding should have no ill effect if $result is another
      * iterator implementation.
      */
     if ($results instanceof \Iterator) {
         $results->rewind();
     } elseif (is_array($results)) {
         reset($results);
     }
     if ($this->isLastEnabledEntity($results, $entity)) {
         $errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $constraint->enabledPath;
         $this->context->addViolationAt($errorPath, $constraint->message);
     }
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:35,代码来源:HasEnabledEntityValidator.php

示例3: formAttributes

 /**
  * @param FormView $formView
  * @param array    $data
  *
  * @return FormView
  */
 public function formAttributes(FormView $formView, array $data)
 {
     $formView = clone $formView;
     foreach ($data as $key => $value) {
         $path = 'children[' . str_replace('.', '].children[', $key) . ']';
         if (false === $this->accessor->isReadable($formView, $path)) {
             continue;
         }
         /** @var FormView $field */
         $field = $this->accessor->getValue($formView, $path);
         if (false === $field instanceof FormView) {
             throw new \RuntimeException("Cannot set form attribute: {$key} is not a FormView instance");
         }
         if (is_string($value)) {
             $value = ["class" => " {$value}"];
         }
         if (false === isset($field->vars['attr'])) {
             $field->vars['attr'] = [];
         }
         foreach ($value as $name => $attribute) {
             if (isset($field->vars['attr'][$name]) && " " === substr($attribute, 0, 1)) {
                 $attribute = $field->vars['attr'][$name] . $attribute;
             }
             $field->vars['attr'][$name] = trim($attribute);
         }
     }
     return $formView;
 }
开发者ID:arsthanea,项目名称:kunstmaan-extra-bundle,代码行数:34,代码来源:FormAttributesTwigExtension.php

示例4: translate

 /**
  * @param object $entity
  * @param string $field
  * @param string $locale
  * @param mixed $fieldData
  * @throws \Bigfoot\Bundle\CoreBundle\Exception\InvalidArgumentException
  */
 public function translate($entity, $field, $locale, $fieldData)
 {
     $em = $this->em;
     $meta = $em->getClassMetadata(get_class($entity));
     $listener = $this->getTranslatableListener();
     $persistDefaultLocaleTransInEntity = $listener->getPersistDefaultLocaleTranslation();
     if (is_object($entity)) {
         $entityClass = $entity instanceof Proxy ? get_parent_class($entity) : get_class($entity);
     } else {
         throw new InvalidArgumentException('Argument 1 passed to TranslationRepository::translate must be an object');
     }
     $reflectionClass = new \ReflectionClass($entityClass);
     $entityTranslationClass = $this->isPersonnalTranslationRecursive($reflectionClass)->class;
     if ($locale === $listener->getTranslatableLocale($entity, $meta)) {
         $meta->getReflectionProperty($field)->setValue($entity, $fieldData);
         $em->persist($entity);
     } elseif (!$persistDefaultLocaleTransInEntity && $locale === $listener->getDefaultLocale()) {
         $trans = new $entityTranslationClass($locale, $field, $fieldData);
         $listener->setTranslationInDefaultLocale(spl_object_hash($entity), $field, $trans);
     } else {
         $translationClassRepository = $this->em->getRepository($entityTranslationClass);
         $meta = $em->getClassMetadata(get_class($entity));
         $identifier = $meta->getSingleIdentifierFieldName();
         $translation = null;
         if ($entity && $this->propertyAccessor->getValue($entity, $identifier)) {
             $translation = $translationClassRepository->findOneBy(array('locale' => $locale, 'field' => $field, 'object' => $entity));
         }
         if ($translation) {
             $translation->setContent($fieldData);
         } elseif ($fieldData !== null) {
             $entity->addTranslation(new $entityTranslationClass($locale, $field, $fieldData));
         }
     }
 }
开发者ID:7rin0,项目名称:BigfootCoreBundle,代码行数:41,代码来源:TranslationRepository.php

示例5: transform

 /**
  * {@inheritdoc}
  */
 public function transform($value)
 {
     if (null === $value) {
         return null;
     }
     if (!is_array($value) && !$value instanceof \Traversable) {
         throw new UnexpectedTypeException($value, 'array or Traversable');
     }
     $result = [LocalizedFallbackValueCollectionType::FIELD_VALUES => [], LocalizedFallbackValueCollectionType::FIELD_IDS => []];
     foreach ($value as $localizedFallbackValue) {
         /** @var LocalizedFallbackValue $localizedFallbackValue */
         $locale = $localizedFallbackValue->getLocale();
         if ($locale) {
             $key = $locale->getId();
         } else {
             $key = 0;
         }
         $fallback = $localizedFallbackValue->getFallback();
         if ($fallback) {
             $value = new FallbackType($fallback);
         } else {
             $value = $this->propertyAccessor->getValue($localizedFallbackValue, $this->field);
         }
         $result[LocalizedFallbackValueCollectionType::FIELD_VALUES][$key ?: null] = $value;
         $result[LocalizedFallbackValueCollectionType::FIELD_IDS][$key] = $localizedFallbackValue->getId();
     }
     return $result;
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:31,代码来源:LocalizedFallbackValueCollectionTransformer.php

示例6: getDefaultValueByField

 /**
  * @param AttributeDefaultValue|null $defaultValue
  * @param string $field
  * @return mixed
  */
 protected function getDefaultValueByField($defaultValue, $field)
 {
     if ($defaultValue) {
         return $this->propertyAccessor->getValue($defaultValue, $field);
     } else {
         return null;
     }
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:13,代码来源:DefaultsTransformerHelper.php

示例7: convertItem

 /**
  * {@inheritdoc}
  */
 public function convertItem($item)
 {
     $result = [];
     foreach ($this->fields as $field) {
         $result[$field] = $this->accessor->getValue($item, $field);
     }
     return $result;
 }
开发者ID:Maksold,项目名称:platform,代码行数:11,代码来源:OrganizationSearchHandler.php

示例8: InStock

 function it_should_not_add_violation_if_stock_is_sufficient(PropertyAccessor $propertyAccessor, InventoryUnitInterface $inventoryUnit, StockableInterface $stockable, AvailabilityCheckerInterface $availabilityChecker)
 {
     $propertyAccessor->getValue($inventoryUnit, 'stockable')->willReturn($stockable);
     $propertyAccessor->getValue($inventoryUnit, 'quantity')->willReturn(1);
     $availabilityChecker->isStockSufficient($stockable, 1)->willReturn(true);
     $constraint = new InStock();
     $this->validate($inventoryUnit, $constraint);
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:8,代码来源:InStockValidatorSpec.php

示例9: transform

 /**
  * Applies the given mapping on a given object or array.
  *
  * @param  object|array $raw         The input object or array
  * @param  array        $mapping     The mapping
  * @param  object|array $transformed The output object or array.
  * @return array
  */
 public function transform($raw, array $mapping, $transformed = [])
 {
     foreach ($mapping as $destination => $source) {
         $value = $this->propertyAccessor->isReadable($raw, $source) ? $this->propertyAccessor->getValue($raw, $source) : null;
         $this->propertyAccessor->setValue($transformed, $destination, $value);
     }
     return $transformed;
 }
开发者ID:alebon,项目名称:graviton,代码行数:16,代码来源:MappingTransformer.php

示例10: processResults

 private function processResults($entities, $targetEntityConfig)
 {
     $results = array();
     foreach ($entities as $entity) {
         $results[] = array('id' => $this->propertyAccessor->getValue($entity, $targetEntityConfig['primary_key_field_name']), 'text' => (string) $entity);
     }
     return $results;
 }
开发者ID:abdielcs,项目名称:EasyAdminBundle,代码行数:8,代码来源:Autocomplete.php

示例11: transform

 /**
  * @inheritdoc
  */
 public function transform($value)
 {
     if (null === $value) {
         return [];
     }
     $text = is_null($this->property) ? (string) $value : $this->propertyAccessor->getValue($value, $this->property);
     $identifier = $this->propertyAccessor->getValue($value, $this->metadata->getIdentifier()[0]);
     return [$identifier ?: $text => $text];
 }
开发者ID:snovichkov,项目名称:Select2Bundle,代码行数:12,代码来源:EntityToPropertyTransformer.php

示例12: InvalidPathException

 /**
  * {@inheritdoc}
  */
 public function &get(&$node, $singlePath)
 {
     if (!$singlePath || !$this->isReadable($node, $singlePath)) {
         throw new InvalidPathException(sprintf('Path %s is not readable', $singlePath));
     }
     // Only variables may be returned as reference
     $value = $this->propertyAccess->getValue($node, $singlePath);
     return $value;
 }
开发者ID:chili-labs,项目名称:json-pointer,代码行数:12,代码来源:PropertyAccessAccessor.php

示例13: resolve

 /**
  * @inheritdoc
  */
 public function resolve($func)
 {
     if (!is_string($func)) {
         return null;
     }
     $propertyPath = new PropertyPath($func);
     return function ($item) use($propertyPath) {
         return $this->propertyAccessor->getValue($item, $propertyPath);
     };
 }
开发者ID:draco1989,项目名称:BCCEnumerableUtility,代码行数:13,代码来源:PropertyPathResolver.php

示例14: copyTranslatableEntity

 protected function copyTranslatableEntity(LocaleAwareInterface $entity, LocaleInterface $targetLocale)
 {
     $duplicate = clone $entity;
     foreach ($entity->getCopyingSensitiveProperties() as $propertyName) {
         $value = sprintf('%s-%s', $this->propertyAccessor->getValue($entity, $propertyName), $targetLocale->getCode());
         $this->propertyAccessor->setValue($duplicate, $propertyName, $value);
         $duplicate->setLocale($targetLocale->getCode());
         $this->entityManager->persist($duplicate);
     }
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:10,代码来源:LocaleCopier.php

示例15: filter

 /**
  * @param mixed $item
  *
  * @return bool
  */
 public function filter($item)
 {
     $filename = $this->property === null ? $item : $this->accessor->getValue($item, $this->property);
     foreach ($this->extensions as $extension) {
         if (preg_match(sprintf('/\\.%s/', $extension), $filename) === 1) {
             return true;
         }
     }
     return false;
 }
开发者ID:cocur,项目名称:plum,代码行数:15,代码来源:FileExtensionFilter.php


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