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


PHP PropertyAccess\PropertyAccessorInterface類代碼示例

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


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

示例1:

 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

示例2: getPropertyValue

 /**
  * @param \Symfony\Component\PropertyAccess\PropertyAccessorInterface $accessor
  * @param \FSi\Bundle\AdminBundle\Display\Property $property
  * @return mixed
  */
 private function getPropertyValue(PropertyAccessorInterface $accessor, Property $property)
 {
     $value = $accessor->getValue($this->object, $property->getPath());
     foreach ($property->getValueFormatters() as $formatter) {
         $value = $formatter->format($value);
     }
     return $value;
 }
開發者ID:kbedn,項目名稱:admin-bundle,代碼行數:13,代碼來源:ObjectDisplay.php

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

示例4: testRenderWithoutScalar

 /**
  * @expectedException \Lug\Component\Grid\Exception\InvalidTypeException
  * @expectedExceptionMessage The "name" number column type expects a numeric value, got "stdClass".
  */
 public function testRenderWithoutScalar()
 {
     $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue(new \stdClass()));
     $column = $this->createColumnMock();
     $column->expects($this->once())->method('getName')->will($this->returnValue('name'));
     $this->type->render($data, ['column' => $column, 'path' => $path]);
 }
開發者ID:blazarecki,項目名稱:lug,代碼行數:11,代碼來源:NumberTypeTest.php

示例5: getIriFromItem

 /**
  * {@inheritdoc}
  */
 public function getIriFromItem($item, $referenceType = RouterInterface::ABSOLUTE_PATH)
 {
     if ($resource = $this->resourceCollection->getResourceForEntity($item)) {
         return $this->router->generate($this->getRouteName($resource, 'item'), ['id' => $this->propertyAccessor->getValue($item, 'id')], $referenceType);
     }
     throw new \InvalidArgumentException(sprintf('No resource associated with the type "%s".', get_class($item)));
 }
開發者ID:bein-sports,項目名稱:DunglasApiBundle,代碼行數:10,代碼來源:IriConverter.php

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

示例7: normalize

 /**
  * {@inheritdoc}
  */
 public function normalize($violationList, $format = null, array $context = [])
 {
     if ($violationList instanceof \Exception) {
         if ($this->debug) {
             $trace = $violationList->getTrace();
         }
     }
     $data = ['@context' => '/api/contexts/ConstraintViolationList', '@type' => 'ConstraintViolationList', 'title' => 'An error occurred', 'violations' => []];
     foreach ($violationList as $violation) {
         $key = $violation->getPropertyPath();
         $invalidValue = $violation->getInvalidValue();
         if (method_exists($violation->getRoot(), '__toString')) {
             $invalidValue = $this->propertyAccessor->getValue($violation->getRoot(), $violation->getPropertyPath());
         }
         if ($violation->getConstraint() instanceof UniqueEntity) {
             $class = method_exists($violation->getRoot(), 'getConfig') ? $violation->getRoot()->getConfig() : $violation->getRoot();
             $reflexion = new \ReflectionClass($class);
             $key = strtolower($reflexion->getShortname());
         }
         $data['violations'][$key][] = ['property' => $violation->getPropertyPath(), 'invalidValue' => $invalidValue, 'message' => $violation->getMessage()];
     }
     if (isset($trace)) {
         $data['trace'] = $trace;
     }
     return $data;
 }
開發者ID:eliberty,項目名稱:api-bundle,代碼行數:29,代碼來源:ErrorViolationListNormalizer.php

示例8: transform

 /**
  * Transforms an object into an elastica object having the required keys
  *
  * @param object $object the object to convert
  * @param array  $fields the keys we want to have in the returned array
  *
  * @return Document
  **/
 public function transform($object, array $fields)
 {
     $identifier = $this->propertyAccessor->getValue($object, $this->options['identifier']);
     $document = new Document($identifier);
     foreach ($fields as $key => $mapping) {
         if ($key == '_parent') {
             $property = null !== $mapping['property'] ? $mapping['property'] : $mapping['type'];
             $value = $this->propertyAccessor->getValue($object, $property);
             $document->setParent($this->propertyAccessor->getValue($value, $mapping['identifier']));
             continue;
         }
         $value = $this->propertyAccessor->getValue($object, $key);
         if (isset($mapping['type']) && in_array($mapping['type'], array('nested', 'object')) && isset($mapping['properties']) && !empty($mapping['properties'])) {
             /* $value is a nested document or object. Transform $value into
              * an array of documents, respective the mapped properties.
              */
             $document->set($key, $this->transformNested($value, $mapping['properties']));
             continue;
         }
         if (isset($mapping['type']) && $mapping['type'] == 'attachment') {
             // $value is an attachment. Add it to the document.
             if ($value instanceof \SplFileInfo) {
                 $document->addFile($key, $value->getPathName());
             } else {
                 $document->addFileContent($key, $value);
             }
             continue;
         }
         $document->set($key, $this->normalizeValue($value));
     }
     return $document;
 }
開發者ID:benstinton,項目名稱:FOSElasticaBundle,代碼行數:40,代碼來源:ModelToElasticaAutoTransformer.php

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

示例10: get

 /**
  * @param string      $name
  * @param string|null $path
  *
  * @return mixed
  */
 public function get($name, $path = null)
 {
     $path = $path ?: (isset($this->mapping[$name]) ? $this->mapping[$name] : $name);
     if (is_array($this->data)) {
         $path = '[' . str_replace('.', '][', $path) . ']';
     }
     return $this->accessor->getValue($this->data, $path);
 }
開發者ID:jfsimon,項目名稱:datagrid,代碼行數:14,代碼來源:Entity.php

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

示例12: readFrom

 public function readFrom($data)
 {
     $values = array();
     foreach ($this->paths as $path) {
         $values[] = $this->accessor->getValue($data, $path);
     }
     return $values;
 }
開發者ID:devhelp,項目名稱:normalizer,代碼行數:8,代碼來源:PathsReader.php

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

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

示例15: resolveRouteParameters

 /**
  * @param mixed[] $parameters
  * @param mixed[] $data
  *
  * @return mixed[]
  */
 private function resolveRouteParameters(array $parameters, $data)
 {
     $routeParameters = [];
     foreach ($parameters as $parameter) {
         $routeParameters[$parameter] = $this->propertyAccessor->getValue($data, $parameter);
     }
     return $routeParameters;
 }
開發者ID:php-lug,項目名稱:lug,代碼行數:14,代碼來源:LinkType.php


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