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


PHP PropertyAccessorInterface::getValue方法代码示例

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


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

示例1: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($violationList, $format = null, array $context = [])
 {
     if ($violationList instanceof \Exception) {
         if ($this->debug) {
             $trace = $violationList->getTrace();
         }
     }
     $data = ['@context' => '/api/contexts/ConstraintViolationList', '@type' => 'ConstraintViolationList', 'title' => 'An error occurred', 'violations' => []];
     foreach ($violationList as $violation) {
         $key = $violation->getPropertyPath();
         $invalidValue = $violation->getInvalidValue();
         if (method_exists($violation->getRoot(), '__toString')) {
             $invalidValue = $this->propertyAccessor->getValue($violation->getRoot(), $violation->getPropertyPath());
         }
         if ($violation->getConstraint() instanceof UniqueEntity) {
             $class = method_exists($violation->getRoot(), 'getConfig') ? $violation->getRoot()->getConfig() : $violation->getRoot();
             $reflexion = new \ReflectionClass($class);
             $key = strtolower($reflexion->getShortname());
         }
         $data['violations'][$key][] = ['property' => $violation->getPropertyPath(), 'invalidValue' => $invalidValue, 'message' => $violation->getMessage()];
     }
     if (isset($trace)) {
         $data['trace'] = $trace;
     }
     return $data;
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:29,代码来源:ErrorViolationListNormalizer.php

示例2: normalize

 /**
  * {@inheritdoc}
  *
  * @throws CircularReferenceException
  */
 public function normalize($object, $format = null, array $context = array())
 {
     if (!isset($context['cache_key'])) {
         $context['cache_key'] = $this->getCacheKey($context);
     }
     if ($this->isCircularReference($object, $context)) {
         return $this->handleCircularReference($object);
     }
     $data = array();
     $attributes = $this->getAttributes($object, $context);
     foreach ($attributes as $attribute) {
         if (in_array($attribute, $this->ignoredAttributes)) {
             continue;
         }
         $attributeValue = $this->propertyAccessor->getValue($object, $attribute);
         if (isset($this->callbacks[$attribute])) {
             $attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue);
         }
         if (null !== $attributeValue && !is_scalar($attributeValue)) {
             if (!$this->serializer instanceof NormalizerInterface) {
                 throw new LogicException(sprintf('Cannot normalize attribute "%s" because injected serializer is not a normalizer', $attribute));
             }
             $attributeValue = $this->serializer->normalize($attributeValue, $format, $context);
         }
         if ($this->nameConverter) {
             $attribute = $this->nameConverter->normalize($attribute);
         }
         $data[$attribute] = $attributeValue;
     }
     return $data;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:36,代码来源:ObjectNormalizer.php

示例3: mapFormsToData

 /**
  * {@inheritdoc}
  */
 public function mapFormsToData(array $forms, &$data)
 {
     if (null === $data) {
         return;
     }
     if (!is_array($data) && !is_object($data)) {
         throw new UnexpectedTypeException($data, 'object, array or empty');
     }
     $iterator = new VirtualFormAwareIterator($forms);
     $iterator = new \RecursiveIteratorIterator($iterator);
     foreach ($iterator as $form) {
         /* @var \Symfony\Component\Form\FormInterface $form */
         $propertyPath = $form->getPropertyPath();
         $config = $form->getConfig();
         // Write-back is disabled if the form is not synchronized (transformation failed)
         // and if the form is disabled (modification not allowed)
         if (null !== $propertyPath && $config->getMapped() && $form->isSynchronized() && !$form->isDisabled()) {
             // If the data is identical to the value in $data, we are
             // dealing with a reference
             if (!is_object($data) || !$config->getByReference() || $form->getData() !== $this->propertyAccessor->getValue($data, $propertyPath)) {
                 $this->propertyAccessor->setValue($data, $propertyPath, $form->getData());
             }
         }
     }
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:28,代码来源:PropertyPathMapper.php

示例4: transform

 /**
  * Transforms an object into an elastica object having the required keys
  *
  * @param object $object the object to convert
  * @param array  $fields the keys we want to have in the returned array
  *
  * @return Document
  **/
 public function transform($object, array $fields)
 {
     $identifier = $this->propertyAccessor->getValue($object, $this->options['identifier']);
     $document = new Document($identifier);
     foreach ($fields as $key => $mapping) {
         if ($key == '_parent') {
             $property = null !== $mapping['property'] ? $mapping['property'] : $mapping['type'];
             $value = $this->propertyAccessor->getValue($object, $property);
             $document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
             continue;
         }
         $value = $this->propertyAccessor->getValue($object, $key);
         if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties']) && !empty($mapping['properties'])) {
             /* $value is a nested document or object. Transform $value into
              * an array of documents, respective the mapped properties.
              */
             $document->set($key, $this->transformNested($value, $mapping['properties']));
             continue;
         }
         if (isset($mapping['type']) && $mapping['type'] == 'attachment') {
             // $value is an attachment. Add it to the document.
             if ($value instanceof \SplFileInfo) {
                 $document->addFile($key, $value->getPathName());
             } else {
                 $document->addFileContent($key, $value);
             }
             continue;
         }
         $document->set($key, $this->normalizeValue($value));
     }
     return $document;
 }
开发者ID:benstinton,项目名称:FOSElasticaBundle,代码行数:40,代码来源:ModelToElasticaAutoTransformer.php

示例5: mapFormsToData

 /**
  * {@inheritdoc}
  */
 public function mapFormsToData($forms, &$data)
 {
     if (null === $data) {
         return;
     }
     if (!is_array($data) && !is_object($data)) {
         throw new UnexpectedTypeException($data, 'object, array or empty');
     }
     foreach ($forms as $form) {
         $propertyPath = $form->getPropertyPath();
         $config = $form->getConfig();
         // Write-back is disabled if the form is not synchronized (transformation failed),
         // if the form was not submitted and if the form is disabled (modification not allowed)
         if (null !== $propertyPath && $config->getMapped() && $form->isSubmitted() && $form->isSynchronized() && !$form->isDisabled()) {
             // If the field is of type DateTime and the data is the same skip the update to
             // keep the original object hash
             if ($form->getData() instanceof \DateTime && $form->getData() == $this->propertyAccessor->getValue($data, $propertyPath)) {
                 continue;
             }
             // If the data is identical to the value in $data, we are
             // dealing with a reference
             if (!is_object($data) || !$config->getByReference() || $form->getData() !== $this->propertyAccessor->getValue($data, $propertyPath)) {
                 $this->propertyAccessor->setValue($data, $propertyPath, $form->getData());
             }
         }
     }
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:30,代码来源:PropertyPathMapper.php

示例6: apply

 /**
  * {@inheritdoc}
  */
 public function apply(Request $request, ParamConverter $configuration) : bool
 {
     $class = $configuration->getClass();
     $constant = sprintf('%s::EMPTY_PROPERTIES', $class);
     $propertiesToBeSkipped = [];
     $instance = new $class();
     $declaredProperties = array_filter((new \ReflectionClass($class))->getProperties(), function (ReflectionProperty $property) use($class) {
         return $property->getDeclaringClass()->name === $class;
     });
     // fetch result properties that are optional and to be skipped as those must not be processed
     if (defined($constant)) {
         $propertiesToBeSkipped = constant($constant);
     }
     /** @var ReflectionProperty $property */
     foreach ($declaredProperties as $property) {
         $propertyName = $property->getName();
         if (in_array($propertyName, $propertiesToBeSkipped, true)) {
             continue;
         }
         // non-writable properties cause issues with the DTO creation
         if (!$this->propertyAccess->isWritable($instance, $propertyName)) {
             throw new \RuntimeException($this->getInvalidPropertyExceptionMessage($class, $propertyName));
         }
         $this->propertyAccess->setValue($instance, $propertyName, $this->findAttributeInRequest($request, $property, $this->propertyAccess->getValue($instance, $propertyName)));
     }
     $request->attributes->set($configuration->getName(), $instance);
     return true;
 }
开发者ID:sententiaregum,项目名称:sententiaregum,代码行数:31,代码来源:DTOConverter.php

示例7: getIriFromItem

 /**
  * {@inheritdoc}
  */
 public function getIriFromItem($item, $referenceType = RouterInterface::ABSOLUTE_PATH)
 {
     if ($resource = $this->resourceCollection->getResourceForEntity($item)) {
         return $this->router->generate($this->getRouteName($resource, 'item'), ['id' => $this->propertyAccessor->getValue($item, 'id')], $referenceType);
     }
     throw new \InvalidArgumentException(sprintf('No resource associated with the type "%s".', get_class($item)));
 }
开发者ID:bein-sports,项目名称:DunglasApiBundle,代码行数:10,代码来源:IriConverter.php

示例8: readFrom

 public function readFrom($data)
 {
     $values = array();
     foreach ($this->paths as $path) {
         $values[] = $this->accessor->getValue($data, $path);
     }
     return $values;
 }
开发者ID:devhelp,项目名称:normalizer,代码行数:8,代码来源:PathsReader.php

示例9: resolveRouteParameters

 /**
  * @param mixed[] $parameters
  * @param mixed[] $data
  *
  * @return mixed[]
  */
 private function resolveRouteParameters(array $parameters, $data)
 {
     $routeParameters = [];
     foreach ($parameters as $parameter) {
         $routeParameters[$parameter] = $this->propertyAccessor->getValue($data, $parameter);
     }
     return $routeParameters;
 }
开发者ID:php-lug,项目名称:lug,代码行数:14,代码来源:LinkType.php

示例10: getPrice

 /**
  * {@inheritdoc}
  */
 public function getPrice(array $weightables)
 {
     $total = 0;
     foreach ($weightables as $weightable) {
         $total += $this->propertyAccessor->getValue($weightable, $this->shippingPriceField);
     }
     return $total;
 }
开发者ID:iosystems,项目名称:shipping-bundle,代码行数:11,代码来源:PerProductPriceCalculator.php

示例11: getFormNormDataLocale

 /**
  * @param FormInterface $form
  * @return mixed
  */
 public function getFormNormDataLocale(FormInterface $form)
 {
     $classMetadata = $this->getFormTranslatableMetadata($form);
     if (empty($classMetadata) || !$form->getNormData()) {
         return null;
     }
     return $this->propertyAccessor->getValue($form->getNormData(), $classMetadata->localeProperty);
 }
开发者ID:szymach,项目名称:admin-translatable-bundle,代码行数:12,代码来源:TranslatableFormHelper.php

示例12: get

 /**
  * @param string      $name
  * @param string|null $path
  *
  * @return mixed
  */
 public function get($name, $path = null)
 {
     $path = $path ?: (isset($this->mapping[$name]) ? $this->mapping[$name] : $name);
     if (is_array($this->data)) {
         $path = '[' . str_replace('.', '][', $path) . ']';
     }
     return $this->accessor->getValue($this->data, $path);
 }
开发者ID:jfsimon,项目名称:datagrid,代码行数:14,代码来源:Entity.php

示例13: buildView

 /**
  * genere le formulaire.
  *
  * @param \Symfony\Component\Form\FormView      $view
  * @param \Symfony\Component\Form\FormInterface $form
  * @param array                                 $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     foreach ($view->vars['choices'] as $choice) {
         $dataNode = $choice->data;
         $level = $this->propertyAccessor->getValue($dataNode, 'lvl');
         $choice->label = str_repeat(str_repeat(' ', $level), 4) . $choice->label;
     }
 }
开发者ID:victoire,项目名称:victoire,代码行数:15,代码来源:HierarchyTreeType.php

示例14: getProperty

 /**
  * {@inheritdoc}
  */
 public function getProperty(MetadataSubjectInterface $metadataSubject, $propertyPath = null)
 {
     $metadata = $this->metadataProvider->findMetadataBySubject($metadataSubject);
     if (null === $propertyPath) {
         return $metadata;
     }
     return $this->propertyAccessor->getValue($metadata, $propertyPath);
 }
开发者ID:ahmadrabie,项目名称:Sylius,代码行数:11,代码来源:MetadataAccessor.php

示例15: getState

 /**
  * {@inheritdoc}
  */
 public function getState($object)
 {
     try {
         return $this->propertyAccessor->getValue($object, $this->propertyPath);
     } catch (SymfonyNoSuchPropertyException $e) {
         throw new NoSuchPropertyException(sprintf('Property path "%s" on object "%s" does not exist.', $this->propertyPath, get_class($object)), $e->getCode(), $e);
     }
 }
开发者ID:Rioji,项目名称:Finite,代码行数:11,代码来源:PropertyPathStateAccessor.php


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