/** * {@inheritdoc} */ public function transform($value) { $result = []; if (is_array($value)) { $result = array_map(function ($tag) { return json_encode(['id' => $this->propertyAccessor->getValue($tag, 'id'), 'name' => $this->propertyAccessor->getValue($tag, 'name')]); }, $value); $result = implode(';;', $result); } return $result; }
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']); }
/** * @param object $object * @param string $property * * @return mixed */ protected function getValue($object, $property) { if (!$this->propertyAccessor) { $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); } try { return $this->propertyAccessor->getValue($object, $property); } catch (NoSuchPropertyException $e) { try { $reflectionClass = new \ReflectionClass($object); $reflectionProperty = $reflectionClass->getProperty($property); $reflectionProperty->setAccessible(true); return $reflectionProperty->getValue($object); } catch (\ReflectionException $ex) { throw new InvalidEntityException(sprintf('$object must have either "%s" method or "%s" property.', Inflector::camelize(sprintf('get_%s', $property)), $property), 0, $ex); } } }
/** * Has value * * @param string $name * @return boolean */ public function has($name) { if (array_key_exists($name, $this->data)) { return true; } else { try { $this->propertyAccessor->getValue($this->data, $this->getMappedPath($name)); } catch (NoSuchPropertyException $e) { return false; } return true; } }
/** * @param AbstractAddress $from * @param AbstractAddress $to * @param string $property */ protected function setValue(AbstractAddress $from, AbstractAddress $to, $property) { if (!$this->propertyAccessor) { $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); } try { $value = $this->propertyAccessor->getValue($from, $property); if (!$value || $value instanceof Collection && $value->isEmpty()) { return; } $this->propertyAccessor->setValue($to, $property, $value); } catch (NoSuchPropertyException $e) { } }
/** * {@inheritdoc} */ public function removeOption($id, $optionName) { $options = $this->rawLayout->getProperty($id, RawLayout::OPTIONS); $this->propertyAccessor->remove($options, $this->getPropertyPath($optionName)); $this->rawLayout->setProperty($id, RawLayout::OPTIONS, $options); }
/** * @param array $array * @param string|PropertyPathInterface|callable $propertyPath * @param bool $reverse * @param bool $stringComparison * @param bool $caseInsensitive * * @return array|null * * @SuppressWarnings(PHPMD.NPathComplexity) */ private static function prepareSortable($array, $propertyPath, $reverse, $stringComparison, $caseInsensitive) { $propertyAccessor = new PropertyAccessor(); $isSimplePropertyPath = is_string($propertyPath) && !preg_match('/.\\[/', $propertyPath); $isCallback = is_callable($propertyPath); $defaultValue = $stringComparison ? '' : 0; $needSorting = $reverse; $result = []; $lastVal = null; $index = 0; foreach ($array as $key => $value) { if (is_array($value) && $isSimplePropertyPath) { // get array property directly to speed up $val = isset($value[$propertyPath]) || array_key_exists($propertyPath, $value) ? $value[$propertyPath] : null; } elseif ($isCallback) { $val = call_user_func($propertyPath, $value); } else { $val = $propertyAccessor->getValue($value, $propertyPath); } if (null === $val) { $val = $defaultValue; } elseif ($caseInsensitive) { $val = strtolower($val); } $result[$key] = [$val, $index++]; if ($lastVal === null) { $lastVal = $val; } elseif (0 !== self::compare($lastVal, $val, $stringComparison)) { $lastVal = $val; $needSorting = true; } } if (!$needSorting) { return null; } return $result; }
/** * @param array $source * @param array $config * @return mixed * @throws InvalidArgumentException */ protected function getParameterValue($source, array $config) { $propertyAccessor = new PropertyAccessor(); try { $path = ''; foreach (explode('.', $config['path']) as $part) { $path .= '[' . $part . ']'; } $result = $propertyAccessor->getValue($source, $path); } catch (NoSuchPropertyException $exception) { if (array_key_exists('default', $config)) { $result = $config['default']; } else { throw new InvalidArgumentException(sprintf('Cannot bind datasource parameter "%s", there is no datagrid parameter with path "%s".', $config['name'], $config['path']), 0, $exception); } } if ((null === $result || $result === [] || $result === ['']) && isset($config['default'])) { $result = $config['default']; } return $result; }
/** * @dataProvider getPathsWithMissingIndex */ public function testRemoveThrowsNoExceptionIfIndexNotFound($collection, $path) { $clone = unserialize(serialize($collection)); $this->propertyAccessor->remove($collection, $path); $this->assertEquals($clone, $collection); }
public function testTicket5755() { $object = new Ticket5775Object(); $this->propertyAccessor->setValue($object, 'property', 'foobar'); $this->assertEquals('foobar', $object->getProperty()); }
/** * {@inheritdoc} */ public function convertItem($item) { $isGranted = $this->securityFacade->isGranted('oro_tag_unassign_global'); $isOwner = $this->propertyAccessor->getValue($item, 'owner'); return ['id' => json_encode(['id' => $this->propertyAccessor->getValue($item, 'id'), 'name' => $this->propertyAccessor->getValue($item, 'name')]), 'name' => $this->propertyAccessor->getValue($item, 'name'), 'locked' => !($isGranted || $isOwner)]; }
/** * @dataProvider getValidPropertyPaths */ public function testIsWritable($collection, $path) { $this->assertTrue($this->propertyAccessor->isWritable($collection, $path, 'Updated')); }