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


PHP PropertyAccess\PropertyAccessor类代码示例

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


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

示例1: buildForm

 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $admin = clone $this->getAdmin($options);
     if ($admin->hasParentFieldDescription()) {
         $admin->getParentFieldDescription()->setAssociationAdmin($admin);
     }
     if ($options['delete'] && $admin->isGranted('DELETE')) {
         if (!array_key_exists('translation_domain', $options['delete_options']['type_options'])) {
             $options['delete_options']['type_options']['translation_domain'] = $admin->getTranslationDomain();
         }
         $builder->add('_delete', $options['delete_options']['type'], $options['delete_options']['type_options']);
     }
     // hack to make sure the subject is correctly set
     // https://github.com/sonata-project/SonataAdminBundle/pull/2076
     if ($builder->getData() === null) {
         $p = new PropertyAccessor(false, true);
         try {
             $subject = $p->getValue($admin->getParentFieldDescription()->getAdmin()->getSubject(), $this->getFieldDescription($options)->getFieldName() . $options['property_path']);
             $builder->setData($subject);
         } catch (NoSuchIndexException $e) {
             // no object here
         }
     }
     $admin->setSubject($builder->getData());
     $admin->defineFormBuilder($builder);
     $builder->addModelTransformer(new ArrayToModelTransformer($admin->getModelManager(), $admin->getClass()));
 }
开发者ID:kwuerl,项目名称:SonataAdminBundle,代码行数:30,代码来源:AdminType.php

示例2: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $propertyAccessor = new PropertyAccessor();
     $builder->add('firstName', null, array('label' => false, 'widget_form_group' => false, 'attr' => array('placeholder' => 'First name'), 'constraints' => array(new NotBlank(), new Length(array('max' => 100)))))->add('lastName', null, array('label' => false, 'widget_form_group' => false, 'attr' => array('placeholder' => 'Last name'), 'constraints' => array(new NotBlank(), new Length(array('max' => 100)))))->add('headline', null, array('label' => 'Occupation', 'render_required_asterisk' => true))->add('about', 'textarea', array('attr' => array('rows' => 3)))->add('contactEmail', 'email', array('render_required_asterisk' => true))->add('contactNumber', 'tel', array('format' => PhoneNumberFormat::INTERNATIONAL, 'attr' => array('placeholder' => 'International format (e.g. +61 412 345 678)'), 'invalid_message' => 'Phone number must follow international format (e.g. +61 412 345 678)', 'render_required_asterisk' => true))->add('industryPreference', 'entity', array('class' => 'App\\ResumeBundle\\Entity\\Industry', 'multiple' => true))->add('availableDate', 'date', array('widget' => 'single_text', 'format' => 'dd/MM/yyyy', 'html5' => false, 'label' => 'Available for employment from', 'attr' => array('class' => 'date-picker')))->add('employmentStatus', 'entity', array('class' => 'App\\ResumeBundle\\Entity\\EmploymentStatus', 'empty_data' => '', 'empty_value' => 'N/A', 'required' => false, 'choice_attr' => function ($choice, $key) use(&$propertyAccessor) {
         $value = $propertyAccessor->getValue($choice, 'noticeRequired');
         return ['data-require-notice' => $value ? 1 : 0];
     }, 'attr' => array('class' => 'employment-status-select')))->add('weeksOfNotice', null, array('label' => 'How many weeks of notice do you need?', 'widget_form_group_attr' => array('class' => 'form-group weeks-of-notice hidden')))->add('gs1Certifications', 'collection', array('label' => 'GS1 certifications', 'allow_add' => true, 'allow_delete' => true, 'type' => 'student_gs1_cert', 'prototype' => true, 'horizontal_wrap_children' => true, 'error_bubbling' => false, 'options' => array('label_render' => false, 'widget_remove_btn' => array('horizontal_wrapper_div' => array('class' => "col-sm-1"), 'wrapper_div' => false), 'horizontal' => true, 'horizontal_label_offset_class' => "", 'horizontal_input_wrapper_class' => "col-sm-11")))->add('certifications', 'collection', array('label' => 'Certifications', 'allow_add' => true, 'allow_delete' => true, 'type' => 'student_cert', 'prototype' => true, 'horizontal_wrap_children' => true, 'error_bubbling' => false, 'options' => array('label_render' => false, 'widget_remove_btn' => array('horizontal_wrapper_div' => array('class' => "col-sm-1"), 'wrapper_div' => false), 'horizontal' => true, 'horizontal_label_offset_class' => "", 'horizontal_input_wrapper_class' => "col-sm-11")))->add('educations', 'collection', array('label' => 'Education', 'allow_add' => true, 'allow_delete' => true, 'type' => 'student_education', 'prototype' => true, 'horizontal_wrap_children' => true, 'error_bubbling' => false, 'options' => array('label_render' => false, 'widget_remove_btn' => array('horizontal_wrapper_div' => array('class' => "col-sm-1  col-xs-12"), 'wrapper_div' => false), 'horizontal' => true, 'horizontal_label_offset_class' => "", 'horizontal_input_wrapper_class' => "col-sm-11  col-xs-12")))->add('socialNetworks', 'collection', array('allow_add' => true, 'allow_delete' => true, 'type' => 'student_social_network', 'prototype' => true, 'horizontal_wrap_children' => true, 'error_bubbling' => false, 'options' => array('label_render' => false, 'widget_remove_btn' => array('horizontal_wrapper_div' => array('class' => "col-sm-1"), 'wrapper_div' => false), 'horizontal' => true, 'horizontal_label_offset_class' => "", 'horizontal_input_wrapper_class' => "col-sm-11")))->add('country', 'country', array('preferred_choices' => array('AU'), 'label' => 'Country (current residence)', 'render_required_asterisk' => true))->add('state', 'text', array('label' => 'State (current residence)', 'render_required_asterisk' => true))->add('city', 'text', array('label' => 'City (current residence)', 'render_required_asterisk' => true))->add('workingRight', 'choice', array('choices' => array(0 => 'No', 1 => 'Yes'), 'render_required_asterisk' => true, 'choice_value' => function ($choiceKey) {
         if (null === $choiceKey) {
             return null;
         }
         $stringChoiceKey = (string) $choiceKey;
         if ('1' === $stringChoiceKey) {
             return 'true';
         }
         if ('0' === $stringChoiceKey || '' === $stringChoiceKey) {
             return 'false';
         }
         throw new \Exception('Unexpected choice key: ' . $choiceKey);
     }, 'expanded' => true, 'label' => 'Do you have full working rights in Australia?'))->add('avatar', 'student_avatar')->add('resume', 'student_resume', array('render_required_asterisk' => true))->add('save', 'submit', array('attr' => array('class' => 'save btn-sm btn-info')));
     // Make sure resume is uploaded
     $builder->get('resume')->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
         $resume = $event->getData();
         if ($resume->getId() === null && $resume->getFile() === null) {
             $event->getForm()->get('file')->addError(new FormError("You must upload a resume"));
         }
     });
 }
开发者ID:hoangnd25,项目名称:IndustryProject,代码行数:27,代码来源:StudentProfileType.php

示例3:

 function it_does_nothing_if_form_data_is_empty(FormEvent $event, FormInterface $form, PropertyAccessor $propertyAccessor)
 {
     $event->getForm()->willReturn($form);
     $form->getData()->willReturn(null);
     $event->setData(Argument::any())->shouldNotBeCalled();
     $propertyAccessor->setValue(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled();
     $this->preSubmit($event);
 }
开发者ID:norzechowicz,项目名称:doctrine-extensions-bundle,代码行数:8,代码来源:RemovableFileSubscriberSpec.php

示例4: 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);
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:8,代码来源:InStockValidatorSpec.php

示例5: offsetSet

 /**
  * {@inheritdoc}
  */
 public function offsetSet($offset, $value)
 {
     $action = new BatchAction($offset);
     $accessor = new PropertyAccessor();
     foreach ($value as $property => $val) {
         $accessor->setValue($action, $property, $val);
     }
     $this->actions[$offset] = $action;
 }
开发者ID:ynloultratech,项目名称:framework,代码行数:12,代码来源:BatchActionMapper.php

示例6: check

 /**
  * {@inheritdoc}
  */
 public function check($value, $match)
 {
     $accessor = new PropertyAccessor();
     try {
         $json = $this->decode($value);
         $accessor->getValue($json, $match);
     } catch (RuntimeException $e) {
         throw new ValidatorException($e->getMessage());
     }
 }
开发者ID:hogosha,项目名称:monitor,代码行数:13,代码来源:JsonValidator.php

示例7: 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;
 }
开发者ID:bravesheep,项目名称:crudify-bundle,代码行数:35,代码来源:CrudifyExtension.php

示例8: convert

 /**
  * {@inheritdoc}
  */
 public function convert($value)
 {
     $ref = new \ReflectionClass($this->class);
     $data = $ref->newInstanceWithoutConstructor();
     $this->propertyAccessor->setValue($data, $this->label, $value);
     return (object) $data;
 }
开发者ID:mcdir,项目名称:SonatraFormExtensionsBundle,代码行数:10,代码来源:NewTagConverter.php

示例9: 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;
 }
开发者ID:arsthanea,项目名称:kunstmaan-extra-bundle,代码行数:34,代码来源:FormAttributesTwigExtension.php

示例10: 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);
     }
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:35,代码来源:HasEnabledEntityValidator.php

示例11: 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));
         }
     }
 }
开发者ID:7rin0,项目名称:BigfootCoreBundle,代码行数:41,代码来源:TranslationRepository.php

示例12: 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);
 }
开发者ID:Newman101,项目名称:WellCommerce,代码行数:14,代码来源:DateTransformer.php

示例13: 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;
 }
开发者ID:alebon,项目名称:graviton,代码行数:16,代码来源:MappingTransformer.php

示例14: 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;
 }
开发者ID:abdielcs,项目名称:EasyAdminBundle,代码行数:8,代码来源:Autocomplete.php

示例15: convertItem

 /**
  * {@inheritdoc}
  */
 public function convertItem($item)
 {
     $result = [];
     foreach ($this->fields as $field) {
         $result[$field] = $this->accessor->getValue($item, $field);
     }
     return $result;
 }
开发者ID:Maksold,项目名称:platform,代码行数:11,代码来源:OrganizationSearchHandler.php


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