本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例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;
}
}
示例7: convertItem
/**
* {@inheritdoc}
*/
public function convertItem($item)
{
$result = [];
foreach ($this->fields as $field) {
$result[$field] = $this->accessor->getValue($item, $field);
}
return $result;
}
示例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);
}
示例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;
}
示例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;
}
示例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];
}
示例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;
}
示例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);
};
}
示例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);
}
}
示例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;
}