本文整理汇总了PHP中Symfony\Component\PropertyAccess\PropertyAccessor::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyAccessor::setValue方法的具体用法?PHP PropertyAccessor::setValue怎么用?PHP PropertyAccessor::setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\PropertyAccess\PropertyAccessor
的用法示例。
在下文中一共展示了PropertyAccessor::setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConstraintViolation
protected function getConstraintViolation(ConstraintViolation $constraintViolation, array &$messages)
{
$path = new PropertyPath($constraintViolation->getPropertyPath());
$elements = $path->getElements();
$elements[] = $constraintViolation->getConstraint()->validatedBy();
$this->propertyAccessor->setValue($messages, $this->buildPath($elements), $constraintViolation->getMessage());
}
示例2: create
/**
* {@inheritdoc}
*/
public function create(&$node, $singlePath, $value)
{
if (!$this->isWritable($node, $singlePath)) {
throw new InvalidPathException(sprintf('Path %s could not be created in object of type %s', $singlePath, gettype($node)));
}
$this->propertyAccess->setValue($node, $singlePath, $value);
}
示例3: convert
/**
* {@inheritdoc}
*/
public function convert($value)
{
$ref = new \ReflectionClass($this->class);
$data = $ref->newInstanceWithoutConstructor();
$this->propertyAccessor->setValue($data, $this->label, $value);
return (object) $data;
}
示例4: reverseTransform
/**
* Transforms date string to DateTime object
*
* @param object $modelData
* @param PropertyPathInterface $propertyPath
* @param mixed $value
*/
public function reverseTransform($modelData, PropertyPathInterface $propertyPath, $value)
{
if (false === ($date = $this->createDateFromString($value))) {
$date = null;
}
$this->propertyAccessor->setValue($modelData, $propertyPath, $date);
}
示例5: 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;
}
示例6: addWhereCondition
/**
* {@inheritdoc}
*/
protected function addWhereCondition($entityClassName, $tableAlias, $fieldName, $columnExpr, $columnAlias, $filterName, array $filterData)
{
$filter = ['column' => $this->getFilterByExpr($entityClassName, $tableAlias, $fieldName, $columnExpr), 'filter' => $filterName, 'filterData' => $filterData];
if ($columnAlias) {
$filter['columnAlias'] = $columnAlias;
}
$this->accessor->setValue($this->filters, $this->currentFilterPath, $filter);
$this->incrementCurrentFilterPath();
}
示例7: duplicateTranslatableEntity
private function duplicateTranslatableEntity(LocaleAwareInterface $entity, array $properties, LocaleInterface $targetLocale)
{
$duplicate = clone $entity;
foreach ($properties as $propertyName) {
$value = sprintf('%s-%s', $this->propertyAccessor->getValue($entity, $propertyName), $targetLocale->getCode());
$this->propertyAccessor->setValue($duplicate, $propertyName, $value);
$duplicate->setLocale($targetLocale->getCode());
$this->doctrineHelper->getEntityManager()->persist($duplicate);
}
}
示例8: 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);
}
}
示例9: setData
/**
* @param AssociationTypeInterface $associationType
* @param string $field
* @param mixed $data
*/
protected function setData(AssociationTypeInterface $associationType, $field, $data)
{
if ('labels' === $field) {
foreach ($data as $localeCode => $label) {
$associationType->setLocale($localeCode);
$translation = $associationType->getTranslation();
$translation->setLabel($label);
}
} else {
$this->accessor->setValue($associationType, $field, $data);
}
}
示例10: reverseTransform
/**
* @inheritdoc
*/
public function reverseTransform($value)
{
if (is_null($value)) {
return null;
}
if (!is_numeric($value) && $this->tags && $this->property) {
$object = $this->metadata->newInstance();
$this->propertyAccessor->setValue($object, $this->property, $value);
return $object;
}
return $this->em->getRepository($this->class)->find($value);
}
示例11: fillFromArray
/**
* @param object $entity
* @param array $data
*/
protected function fillFromArray($entity, array $data)
{
foreach ($data as $key => $value) {
try {
$this->guessTypeAndConvert($key, $value);
$this->propertyAccessor->setValue($entity, $key, $value);
} catch (NoSuchPropertyException $e) {
if ($key !== 'reference') {
printf('--- Unknown property %s. Omitted.' . PHP_EOL, $key);
}
}
}
}
示例12: setValue
private function setValue(&$item, $key, $value, $options = [])
{
$this->debug && $this->logger->info("Value adding is started.");
switch ($options['type']) {
case "string":
case "text":
case "integer":
case "collection":
case "bool":
if (isset($options['modifier'])) {
$value = $this->modify($value, $options['modifier'], $item);
}
break;
case "date":
if (!array_key_exists('format', $options)) {
$options['format'] = "Y-m-d H:i:s";
}
$value = !empty($value) ? \DateTime::createFromFormat($options['format'], $value) : new \DateTime();
break;
case "object":
$value = $this->setObjectValue($item, $key, $value, $options);
break;
}
if (array_key_exists('value', $options)) {
$value = $options['value'];
}
$value ? $this->accessor->setValue($item, $key, $value) : $this->logger->alert("Value is null for {$key}.");
$this->debug && $this->logger->info("Value adding is completed.");
}
示例13: setDefaultOptions
/**
* @param Attribute $attribute
* @param array $options
*/
public function setDefaultOptions(Attribute $attribute, array $options)
{
$attributeOptions = [];
$attributeDefaultValues = [];
foreach ($options as $optionData) {
$order = $this->getOption($optionData, 'order', 0);
$data = $this->getOption($optionData, 'data', []);
$masterOptionId = $this->getOption($optionData, 'master_option_id');
$masterOption = $attribute->getOptionById($masterOptionId);
if (!$masterOption) {
$masterOption = new AttributeOption();
$attribute->addOption($masterOption);
}
foreach ($data as $localeId => $localeData) {
$localeValue = $this->getOption($localeData, 'value', '');
$option = $this->generateOption($masterOption, $localeId, $localeValue, $order);
$attributeOptions[] = $option;
if (!empty($localeData['is_default'])) {
$attributeDefaultValues[] = $this->generateOptionDefaultValue($attribute, $option, $localeId);
}
}
}
$this->propertyAccessor->setValue($attribute, 'options', $attributeOptions);
$this->propertyAccessor->setValue($attribute, 'defaultValues', $attributeDefaultValues);
}
示例14: testSetTypeHint
public function testSetTypeHint()
{
$date = new \DateTimeImmutable();
$object = new TestClass('Kévin');
$this->propertyAccessor->setValue($object, 'date', $date);
$this->assertSame($date, $object->getDate());
}
示例15: testSetValueDeepWithMagicGetter
public function testSetValueDeepWithMagicGetter()
{
$obj = new TestClassMagicGet('foo');
$obj->publicProperty = array('foo' => array('bar' => 'some_value'));
$this->propertyAccessor->setValue($obj, 'publicProperty[foo][bar]', 'Updated');
$this->assertSame('Updated', $obj->publicProperty['foo']['bar']);
}