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


PHP PropertyAccess::createPropertyAccessorBuilder方法代码示例

本文整理汇总了PHP中Symfony\Component\PropertyAccess\PropertyAccess::createPropertyAccessorBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyAccess::createPropertyAccessorBuilder方法的具体用法?PHP PropertyAccess::createPropertyAccessorBuilder怎么用?PHP PropertyAccess::createPropertyAccessorBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\PropertyAccess\PropertyAccess的用法示例。


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

示例1: call

 /**
  * {@inheritdoc}
  */
 public function call(ActionEvent $event, string $format) : Response
 {
     $controller = $event->getController();
     $dataProvider = $event->getDataProvider();
     $request = $event->getRequest();
     $data = $dataProvider->get($request->get('id'));
     $this->checkRole($controller, $data);
     $allowed = $this->getOptions()['allow'];
     $properties = $request->get('data', []);
     $accessor = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();
     foreach ($properties as $property => $value) {
         if (in_array($property, $allowed) && $accessor->isWritable($data, $property)) {
             $accessor->setValue($data, $property, $value);
         }
     }
     $validator = $controller->get('validator');
     $errors = $validator->validate($data, null, ["update"]);
     $responseHandler = $controller->get('vardius_crud.response.handler');
     if (count($errors) > 0) {
         return new JsonResponse(['message' => 'Invalid data', 'errors' => $errors], 400);
     } else {
         $source = $dataProvider->getSource();
         $crudEvent = new CrudEvent($source, $controller);
         $dispatcher = $controller->get('event_dispatcher');
         $dispatcher->dispatch(CrudEvents::CRUD_PRE_UPDATE, $crudEvent);
         $dataProvider->update($data);
         $dispatcher->dispatch(CrudEvents::CRUD_POST_UPDATE, $crudEvent);
         return $responseHandler->getResponse($format, '', '', $data, 200, [], ['groups' => ['update']]);
     }
 }
开发者ID:vardius,项目名称:crud-bundle,代码行数:33,代码来源:UpdateAction.php

示例2: __construct

 /**
  * Construct the snapshot
  *
  * The following options are taken into account :
  * - snapshotClass : snapshot class to use for each elements. If none are
  *                   given, the normalize() method will transform this into
  *                   either an ArraySnapshot or an ObjectSnapshot, depending
  *                   on the situation.
  *
  * @param mixed $data    Either an array or a traversable, data to take a snapshot of
  * @param mixed $primary Property path compatible value to use to get the primary key of each elements
  * @param array $options Array of options
  *
  * @throws InvalidArgumentException the $data is not an array or a Traversable
  * @throws InvalidArgumentException the $data is not an at least 2 dimensional array
  * @throws InvalidArgumentException the snapshotClass in the options is not loadable
  * @throws InvalidArgumentException the snapshotClass in the options is not a valid snapshot class
  * @throws InvalidArgumentException one of the elements of the collection does not have a $primary key
  */
 public function __construct($data, $primary, array $options = [])
 {
     $this->data = [];
     $this->raw = $data;
     $primary = new PropertyPath($primary);
     $snapshot = null;
     $accessor = PropertyAccess::createPropertyAccessorBuilder()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
     if (isset($options['snapshotClass'])) {
         if (!class_exists($options['snapshotClass'])) {
             throw new InvalidArgumentException(sprintf('The snapshot class "%s" does not seem to be loadable', $options['snapshotClass']));
         }
         $refl = new ReflectionClass($options['snapshotClass']);
         if (!$refl->isInstantiable() || !$refl->isSubclassOf('Totem\\AbstractSnapshot')) {
             throw new InvalidArgumentException('A Snapshot Class should be instantiable and extends abstract class Totem\\AbstractSnapshot');
         }
         $snapshot = $options['snapshotClass'];
     }
     if (!is_array($data) && !$data instanceof Traversable) {
         throw new InvalidArgumentException(sprintf('An array or a Traversable was expected to take a snapshot of a collection, "%s" given', is_object($data) ? get_class($data) : gettype($data)));
     }
     foreach ($data as $key => $value) {
         if (!is_int($key)) {
             throw new InvalidArgumentException('The given array / Traversable is not a collection as it contains non numeric keys');
         }
         if (!$accessor->isReadable($value, $primary)) {
             throw new InvalidArgumentException(sprintf('The key "%s" is not defined or readable in one of the elements of the collection', $primary));
         }
         $primaryKey = $accessor->getValue($value, $primary);
         $this->link[$primaryKey] = $key;
         $this->data[$primaryKey] = $this->snapshot($value, $snapshot);
     }
     parent::normalize();
 }
开发者ID:krichprollsch,项目名称:Totem,代码行数:52,代码来源:CollectionSnapshot.php

示例3: access

 public static function access()
 {
     if (!self::$_access) {
         self::$_access = PropertyAccess::createPropertyAccessorBuilder()->disableExceptionOnInvalidIndex()->getPropertyAccessor();
     }
     return self::$_access;
 }
开发者ID:boltphp,项目名称:core,代码行数:7,代码来源:bucket.php

示例4: getPropertyAccessor

 /**
  * @return PropertyAccessorInterface
  */
 protected function getPropertyAccessor()
 {
     if (is_null($this->_propertyAccessor)) {
         $this->_propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();
     }
     return $this->_propertyAccessor;
 }
开发者ID:botanick,项目名称:serializer,代码行数:10,代码来源:ObjectSerializer.php

示例5: getField

 /**
  * @param string|PropertyPathInterface $propertyPath The property path to modify
  * @param mixed|null                   $default      The default value if the field does not exist
  *
  * @throws NoSuchIndexException
  *
  * @return mixed
  */
 public function getField($propertyPath, $default = null)
 {
     $propertyPathAccessor = PropertyAccess::createPropertyAccessorBuilder()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
     if ($propertyPathAccessor->isReadable($this->fields, $propertyPath)) {
         return $propertyPathAccessor->getValue($this->fields, $propertyPath);
     }
     return $default;
 }
开发者ID:nuxia,项目名称:nuxia-plugin,代码行数:16,代码来源:JsonFieldsTrait.php

示例6: getObjectFieldValue

 /**
  * @param object $object
  * @param string $field
  *
  * @return mixed
  */
 public static function getObjectFieldValue($object, $field)
 {
     $propertyAccess = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
     try {
         return $propertyAccess->getValue($object, $field);
     } catch (NoSuchPropertyException $e) {
         return parent::getObjectFieldValue($object, $field);
     }
 }
开发者ID:pierredup,项目名称:ruler,代码行数:15,代码来源:ClosureExpressionVisitor.php

示例7: testHandleEventWithInvalidConfigIncrement

 /**
  * test handle event with an invalid stats
  */
 public function testHandleEventWithInvalidConfigIncrement()
 {
     $client = $this->getMockedClient();
     $client->setPropertyAccessor(PropertyAccess\PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor());
     $client->addEventToListen('test', array('increment' => 'stats.<toto>'));
     $this->exception(function () use($client) {
         $event = new \Symfony\Component\EventDispatcher\Event();
         $client->handleEvent($event, 'test');
     });
 }
开发者ID:johndodev,项目名称:StatsdBundle,代码行数:13,代码来源:Client.php

示例8: get

 /** @inheritdoc */
 public function get($id, $key)
 {
     $config = $this->provider->read($id);
     $accessor = PropertyAccess::createPropertyAccessorBuilder()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
     try {
         return $accessor->getValue($config, $key);
     } catch (\Exception $e) {
         throw new \RuntimeException("Configuration does not have a key {$key} or {$key} is empty.", $e->getCode(), $e);
     }
 }
开发者ID:tomaskadlec,项目名称:lunch_guy,代码行数:11,代码来源:Configuration.php

示例9: setValues

 /**
  * {@inheritdoc}
  *
  * @param BasePageDocument $object
  */
 public function setValues($object, $locale, array $data)
 {
     $propertyAccess = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();
     $structure = $object->getStructure();
     foreach ($data as $property => $value) {
         try {
             $propertyAccess->setValue($structure, $property, $value);
         } catch (\InvalidArgumentException $e) {
             //ignore not existing properties
         }
     }
 }
开发者ID:sulu,项目名称:sulu,代码行数:17,代码来源:PageObjectProvider.php

示例10: field

 /**
  * @param Field $field
  * @param $entity
  * @param $applicationConfiguration
  * @return mixed
  */
 public function field(Field $field, $entity, ApplicationConfiguration $applicationConfiguration)
 {
     $accessor = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();
     $value = $accessor->getValue($entity, $field->getName());
     if ($value instanceof DateTime) {
         $value = $value->format($applicationConfiguration->dateFormat);
     } else {
         if (is_array($value)) {
             $value = $this->recursiveImplode(', ', $value);
         }
     }
     return $value;
 }
开发者ID:VincentChalnot,项目名称:AdminBundle,代码行数:19,代码来源:AdminExtension.php

示例11: readYamlFile

 /** @internal */
 public static function readYamlFile($filename, $propertyPath = null, $allowUndefinedIndex = false)
 {
     if (!file_exists($filename)) {
         throw new \InvalidArgumentException(sprintf('read_yaml_file: Unable to parse Yaml document. No such file: "%s".', $filename));
     }
     try {
         $yaml = Yaml::parse(file_get_contents($filename), Yaml::PARSE_DATETIME);
         return PropertyAccess::createPropertyAccessorBuilder()->enableExceptionOnInvalidIndex()->getPropertyAccessor()->getValue($yaml, $propertyPath);
     } catch (YamlParseException $e) {
         $e->setParsedFile($filename);
         throw new \InvalidArgumentException(sprintf('read_yaml_file: Unable to parse Yaml document. syntax error: "%s".', $e->getMessage()), 0, $e);
     } catch (NoSuchIndexException $e) {
         if ($allowUndefinedIndex) {
             return;
         }
         throw new \InvalidArgumentException(sprintf('read_yaml_file: Unable to read property from Yaml document "%s". no such index: "%s".', $filename, $e->getMessage()), 0, $e);
     }
 }
开发者ID:rollerworks,项目名称:SkeletonDancer,代码行数:19,代码来源:FilesystemProvider.php

示例12: replaceInNodeFormMethod

 /**
  * Replaces a string with a method name
  *
  * @param EventInterface $event An event
  * @param string         $eventName The name of the event
  * @param string         $node  The node in which the replacing will happen
  *
  * @return string
  */
 private static function replaceInNodeFormMethod($event, $eventName, $node)
 {
     $propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();
     // `event->getName()` is deprecated, we have to replace <name> directly with $eventName
     $node = str_replace('<name>', $eventName, $node);
     if (preg_match_all('/<([^>]*)>/', $node, $matches) > 0) {
         $tokens = $matches[1];
         foreach ($tokens as $token) {
             $value = $propertyAccessor->getValue($event, $token);
             $node = str_replace('<' . $token . '>', $value, $node);
         }
     }
     return $node;
 }
开发者ID:VoidAndAny,项目名称:StatsdBundle,代码行数:23,代码来源:Client.php

示例13: __construct

 public function __construct(Container $container, $idPrefix = null)
 {
     $this->container = $container;
     $this->idPrefix = (string) $idPrefix;
     $this->accessor = PropertyAccess::createPropertyAccessorBuilder()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
 }
开发者ID:rybakit,项目名称:phive-task-queue,代码行数:6,代码来源:PimpleCallbackResolver.php

示例14: __construct

 public function __construct($evaluationMode)
 {
     $this->evaluationMode = $evaluationMode;
     $this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
 }
开发者ID:ouniamani,项目名称:rest-api-behat-extension,代码行数:5,代码来源:JsonParser.php

示例15: testGetValueFailsIfNoSuchIndex

 /**
  * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchIndexException
  */
 public function testGetValueFailsIfNoSuchIndex()
 {
     $this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()->enableExceptionOnInvalidIndex()->getPropertyAccessor();
     $object = $this->getContainer(array('firstName' => 'Bernhard'));
     $this->propertyAccessor->getValue($object, '[lastName]');
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:9,代码来源:PropertyAccessorArrayAccessTest.php


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