當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PropertyAccessorInterface::setValue方法代碼示例

本文整理匯總了PHP中Symfony\Component\PropertyAccess\PropertyAccessorInterface::setValue方法的典型用法代碼示例。如果您正苦於以下問題:PHP PropertyAccessorInterface::setValue方法的具體用法?PHP PropertyAccessorInterface::setValue怎麽用?PHP PropertyAccessorInterface::setValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\PropertyAccess\PropertyAccessorInterface的用法示例。


在下文中一共展示了PropertyAccessorInterface::setValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: 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

示例3: setDefaultValues

 /**
  * @param object $entity Entity
  *
  * @throws \Darvin\Utils\DefaultValue\DefaultValueException
  */
 protected function setDefaultValues($entity)
 {
     $entityClass = ClassUtils::getClass($entity);
     $meta = $this->extendedMetadataFactory->getExtendedMetadata($entityClass);
     if (!isset($meta['defaultValues']) || empty($meta['defaultValues'])) {
         return;
     }
     $defaultValuesMap = $meta['defaultValues'];
     $this->filterDefaultValuesMap($defaultValuesMap, $entity, $entityClass);
     if (empty($defaultValuesMap)) {
         return;
     }
     $sourcePropertyValues = $this->getSourcePropertyValues(array_unique(array_values($defaultValuesMap)), $entity, $entityClass);
     $recomputeChangeSet = false;
     foreach ($defaultValuesMap as $targetProperty => $sourcePropertyPath) {
         if (null === $sourcePropertyValues[$sourcePropertyPath]) {
             continue;
         }
         if (!$this->propertyAccessor->isWritable($entity, $targetProperty)) {
             throw new DefaultValueException(sprintf('Property "%s::$%s" is not writable.', $entityClass, $targetProperty));
         }
         $this->propertyAccessor->setValue($entity, $targetProperty, $sourcePropertyValues[$sourcePropertyPath]);
         $recomputeChangeSet = true;
     }
     if ($recomputeChangeSet) {
         $this->recomputeChangeSet($entity);
     }
 }
開發者ID:darvinstudio,項目名稱:darvin-utils,代碼行數:33,代碼來源:DefaultValueSubscriber.php

示例4: 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

示例5:

 function it_creates_theme_from_valid_array($themeClassName, PropertyAccessorInterface $propertyAccessor)
 {
     $data = ['name' => 'Foo bar', 'logical_name' => 'foo/bar'];
     $propertyAccessor->setValue(Argument::any(), 'name', 'Foo bar')->shouldBeCalled();
     $propertyAccessor->setValue(Argument::any(), 'logical_name', 'foo/bar')->shouldBeCalled();
     $propertyAccessor->setValue(Argument::any(), 'parentsNames', [])->shouldBeCalled();
     $this->createFromArray($data)->shouldHaveType($themeClassName);
 }
開發者ID:liverbool,項目名稱:dos-theme-bundle,代碼行數:8,代碼來源:ThemeFactorySpec.php

示例6: setValue

 /**
  * @inheritdoc
  */
 public function setValue(&$objectOrArray, $propertyPath, $value)
 {
     if ($objectOrArray instanceof \stdClass) {
         $objectOrArray->{$propertyPath} = $value;
         return;
     }
     $this->decoratedPropertyAccessor->setValue($objectOrArray, $propertyPath, $value);
 }
開發者ID:nelmio,項目名稱:alice,代碼行數:11,代碼來源:StdPropertyAccessor.php

示例7: setState

 /**
  * {@inheritdoc}
  */
 public function setState(&$object, $value)
 {
     try {
         $this->propertyAccessor->setValue($object, $this->propertyPath, $value);
     } 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

示例8: setAttributeValue

 /**
  * {@inheritdoc}
  */
 protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
 {
     try {
         $this->propertyAccessor->setValue($object, $attribute, $value);
     } catch (NoSuchPropertyException $exception) {
         // Properties not found are ignored
     }
 }
開發者ID:cilefen,項目名稱:symfony,代碼行數:11,代碼來源:ObjectNormalizer.php

示例9: set

 /**
  * @param mixed $value
  */
 public function set($value)
 {
     if ($this->path) {
         $this->accessor->setValue($this->object, $this->path, $value);
     } else {
         $this->object = $value;
     }
 }
開發者ID:bcncommerce,項目名稱:serializer,代碼行數:11,代碼來源:Accessor.php

示例10: create

 /**
  * {@inheritdoc}
  */
 public function create($entityClass, array $defaultValues = array(), array $options = array())
 {
     $object = new $entityClass();
     foreach ($defaultValues as $propertyPath => $value) {
         $this->propertyAccessor->setValue($object, $propertyPath, $value);
     }
     return $object;
 }
開發者ID:antoineguigan,項目名稱:CustomEntityBundle,代碼行數:11,代碼來源:Manager.php

示例11: create

 /**
  * {@inheritdoc}
  */
 public function create(array $options = [])
 {
     $class = $this->resource->getModel();
     $object = new $class();
     foreach ($options as $propertyPath => $value) {
         $this->propertyAccessor->setValue($object, $propertyPath, $value);
     }
     return $object;
 }
開發者ID:php-lug,項目名稱:lug,代碼行數:12,代碼來源:Factory.php

示例12: create

 /**
  * @inheritdoc
  */
 public function create(array $parameters = array())
 {
     $class = $this->options['class'];
     $object = new $class();
     foreach ($parameters as $key => $value) {
         $this->propertyAccessor->setValue($object, $key, $value);
     }
     return $object;
 }
開發者ID:qimnet,項目名稱:crud-bundle,代碼行數:12,代碼來源:DoctrineEntityManager.php

示例13: setValue

 /**
  * {@inheritdoc}
  */
 public function setValue($object, ColumnInfoInterface $columnInfo, $data, array $options = array())
 {
     if (!isset($options['propertyPath'])) {
         throw new \InvalidArgumentException('propertyPath option is required');
     }
     foreach ($data as $locale => $value) {
         $object->setLocale($locale);
         $this->propertyAccessor->setValue($object, 'translation.' . $options['propertyPath'], $value);
     }
 }
開發者ID:javiersantos,項目名稱:pim-community-dev,代碼行數:13,代碼來源:NestedTranslationTransformer.php

示例14: createFromArray

 /**
  * {@inheritdoc}
  */
 public function createFromArray(array $themeData)
 {
     /** @var ThemeInterface $theme */
     $theme = new $this->themeClassName();
     $themeData = $this->optionsResolver->resolve($themeData);
     foreach ($themeData as $attributeKey => $attributeValue) {
         $this->propertyAccessor->setValue($theme, $this->normalizeAttributeKey($attributeKey), $attributeValue);
     }
     return $theme;
 }
開發者ID:benakacha,項目名稱:Sylius,代碼行數:13,代碼來源:ThemeFactory.php

示例15: setValue

 /**
  * {@inheritdoc}
  */
 public function setValue($object, ColumnInfoInterface $columnInfo, $data, array $options = array())
 {
     if ($columnInfo->getLocale()) {
         $locale = $columnInfo->getLocale();
     } else {
         $suffixes = $columnInfo->getSuffixes();
         $locale = array_shift($suffixes);
     }
     $object->setLocale($locale);
     $this->propertyAccessor->setValue($object, 'translation.' . $columnInfo->getPropertyPath(), $data);
 }
開發者ID:noglitchyo,項目名稱:pim-community-dev,代碼行數:14,代碼來源:TranslationTransformer.php


注:本文中的Symfony\Component\PropertyAccess\PropertyAccessorInterface::setValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。