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


PHP PropertyAccess::createPropertyAccessor方法代码示例

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


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

示例1: renderPagerfanta

 /**
  * Renders a pagerfanta.
  *
  * @param PagerfantaInterface $pagerfanta The pagerfanta.
  * @param string              $viewName   The view name.
  * @param array               $options    An array of options (optional).
  *
  * @return string The pagerfanta rendered.
  */
 public function renderPagerfanta(PagerfantaInterface $pagerfanta, $viewName = null, array $options = array())
 {
     $options = array_replace($this->app['pagerfanta.view.options'], $options);
     if (null === $viewName) {
         $viewName = $options['default_view'];
     }
     $router = $this->app['url_generator'];
     //Custom router and router params
     if (isset($this->app['pagerfanta.view.router.name'])) {
         $options['routeName'] = $this->app['pagerfanta.view.router.name'];
     }
     if (isset($this->app['pagerfanta.view.router.params'])) {
         $options['routeParams'] = $this->app['pagerfanta.view.router.params'];
     }
     if (null === $options['routeName']) {
         $request = $this->app['request'];
         $options['routeName'] = $request->attributes->get('_route');
         $options['routeParams'] = array_merge($request->query->all(), $request->attributes->get('_route_params'));
     }
     $routeName = $options['routeName'];
     $routeParams = $options['routeParams'];
     $pageParameter = $options['pageParameter'];
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     $routeGenerator = function ($page) use($router, $routeName, $routeParams, $pageParameter, $propertyAccessor) {
         $propertyAccessor->setValue($routeParams, $pageParameter, $page);
         return $router->generate($routeName, $routeParams);
     };
     return $this->app['pagerfanta.view_factory']->get($viewName)->render($pagerfanta, $routeGenerator, $options);
 }
开发者ID:franmomu,项目名称:silex-pagerfanta-provider,代码行数:38,代码来源:PagerfantaExtension.php

示例2: getJobStatistics

 public function getJobStatistics(Job $job)
 {
     $statisticData = array();
     $dataPerCharacteristic = array();
     $stmt = $this->em->getConnection()->prepare('SELECT * FROM jms_job_statistics WHERE job_id = :jobId');
     $stmt->execute(array('jobId' => $job->getId()));
     $statistics = $stmt->fetchAll();
     $propertyAccess = PropertyAccess::createPropertyAccessor();
     foreach ($statistics as $row) {
         $dataPerCharacteristic[$propertyAccess->getValue($row, '[characteristic]')][] = array($propertyAccess->getValue($row, '[createdAt]'), $propertyAccess->getValue($row, '[charValue]'));
     }
     if ($dataPerCharacteristic) {
         $statisticData = array(array_merge(array('Time'), $chars = array_keys($dataPerCharacteristic)));
         $startTime = strtotime($dataPerCharacteristic[$chars[0]][0][0]);
         $endTime = strtotime($dataPerCharacteristic[$chars[0]][count($dataPerCharacteristic[$chars[0]]) - 1][0]);
         $scaleFactor = $endTime - $startTime > 300 ? 1 / 60 : 1;
         // This assumes that we have the same number of rows for each characteristic.
         for ($i = 0, $c = count(reset($dataPerCharacteristic)); $i < $c; $i++) {
             $row = array((strtotime($dataPerCharacteristic[$chars[0]][$i][0]) - $startTime) * $scaleFactor);
             foreach ($chars as $name) {
                 $value = (double) $dataPerCharacteristic[$name][$i][1];
                 switch ($name) {
                     case 'memory':
                         $value /= 1024 * 1024;
                         break;
                 }
                 $row[] = $value;
             }
             $statisticData[] = $row;
         }
     }
     return $statisticData;
 }
开发者ID:ramunasd,项目名称:platform,代码行数:33,代码来源:JobManager.php

示例3: transform

 /**
  * {@inheritdoc}
  */
 public function transform($model)
 {
     if (null === $model) {
         return null;
     }
     if (count($this->repository->getIdentifierProperties()) > 1) {
         throw new \InvalidArgumentException('Cannot transform object with multiple identifiers');
     }
     $identifierProperty = $this->repository->getIdentifierProperties()[0];
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     if ($this->multiple) {
         if (!is_array($model)) {
             throw new UnexpectedTypeException($model, 'array');
         }
         $identifiers = [];
         foreach ($model as $object) {
             $identifiers[] = $propertyAccessor->getValue($object, $identifierProperty);
         }
         return $identifiers;
     }
     if (!is_object($model)) {
         throw new UnexpectedTypeException($model, 'object');
     }
     return $propertyAccessor->getValue($model, $identifierProperty);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:28,代码来源:IdentifiableModelTransformer.php

示例4: getAccessotr

 /**
  * @return PropertyAccessor
  */
 protected static function getAccessotr()
 {
     if (is_null(static::$accessor)) {
         static::$accessor = PropertyAccess::createPropertyAccessor();
     }
     return static::$accessor;
 }
开发者ID:gunjiro,项目名称:ginq,代码行数:10,代码来源:PropertySelector.php

示例5: getPropertyAccessor

 /**
  * @return \Symfony\Component\PropertyAccess\PropertyAccessor
  */
 protected function getPropertyAccessor()
 {
     if (!$this->propertyAccessor) {
         $this->propertyAccessor = PropertyAccess::createPropertyAccessor();
     }
     return $this->propertyAccessor;
 }
开发者ID:hautelook,项目名称:rabbitmq-api,代码行数:10,代码来源:AbstractRabbitMQModel.php

示例6: multisort

 /**
  * Sort the given array of arrays/objects using paths.
  *
  * e.g.
  *
  *      $data = array(
  *          array('foobar' => 'b'),
  *          array('foobar' => 'a'),
  *      );
  *
  *      SortUtils::multisort($data, '[foobar]', 'asc');
  *
  *      echo $data[0]; // "a"
  *
  * You can also use method names:
  *
  *      SortUtils::multisort($data, 'getFoobar', 'asc');
  *
  * Or sort on multidimensional arrays:
  *
  *      SortUtils::multisort($data, 'foobar.bar.getFoobar', 'asc');
  *
  * And you can sort on multiple paths:
  *
  *      SortUtils::multisort($data, array('foo', 'bar'), 'asc');
  *
  * The path is any path accepted by the property access component:
  *
  * @link http://symfony.com/doc/current/components/property_access/introduction.html
  *
  * @param array        $values
  * @param string|array $path      Path or paths on which to sort on
  * @param string       $direction Direction to sort in (either ASC or DESC)
  *
  * @return array
  */
 public static function multisort($values, $paths, $direction = 'ASC')
 {
     $accessor = PropertyAccess::createPropertyAccessor();
     $values = (array) $values;
     $paths = (array) $paths;
     usort($values, function ($a, $b) use($accessor, $paths) {
         foreach ($paths as $i => $path) {
             $aOrder = $accessor->getValue($a, $path);
             $bOrder = $accessor->getValue($b, $path);
             if (is_string($aOrder)) {
                 $aOrder = strtolower($aOrder);
                 $bOrder = strtolower($bOrder);
             }
             if ($aOrder == $bOrder) {
                 if (count($paths) == $i + 1) {
                     return 0;
                 } else {
                     continue;
                 }
             }
             return $aOrder < $bOrder ? -1 : 1;
         }
     });
     if (strtoupper($direction) == 'DESC') {
         $values = array_reverse($values);
     }
     return $values;
 }
开发者ID:sulu,项目名称:sulu,代码行数:64,代码来源:SortUtils.php

示例7: __construct

 /**
  * Construct
  */
 public function __construct()
 {
     $this->accessor = PropertyAccess::createPropertyAccessor();
     foreach ($this->getFieldDefinitions() as $field) {
         $this->fields[$field->getName()] = $field;
     }
 }
开发者ID:johnpancoast,项目名称:data-validator,代码行数:10,代码来源:AbstractDataModel.php

示例8: getCommandFrom

 /**
  * {@inheritdoc}
  */
 public function getCommandFrom($className)
 {
     if (class_exists($className)) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $reflector = new \ReflectionClass($className);
         $instance = $reflector->newInstanceWithoutConstructor();
         foreach ($reflector->getProperties() as $property) {
             if ($instance instanceof ConsoleCommandInterface && $property->getName() == 'io') {
                 continue;
             }
             if (!$this->format->hasArgument($property->getName()) && !$this->format->hasOption($property->getName())) {
                 throw new \InvalidArgumentException(sprintf("There is not '%s' argument defined in the %s command", $property->getName(), $className));
             }
             $value = null;
             if ($this->format->hasArgument($property->getName())) {
                 $value = $this->args->getArgument($property->getName());
             } elseif ($this->format->hasOption($property->getName())) {
                 $value = $this->args->getOption($property->getName());
             }
             $accessor->setValue($instance, $property->getName(), $value);
         }
         return $instance;
     }
     return;
 }
开发者ID:cubiche,项目名称:cubiche,代码行数:28,代码来源:ConsoleArgsToCommand.php

示例9: buildCredentials

 /**
  * @param FormEvent $event
  */
 public function buildCredentials(FormEvent $event)
 {
     /** @var array $data */
     $data = $event->getData();
     if (is_null($data)) {
         return;
     }
     $propertyPath = is_array($data) ? '[factoryName]' : 'factoryName';
     $factoryName = PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
     if (empty($factoryName)) {
         return;
     }
     $form = $event->getForm();
     $form->add('config', 'form');
     $configForm = $form->get('config');
     $gatewayFactory = $this->registry->getGatewayFactory($factoryName);
     $config = $gatewayFactory->createConfig();
     $propertyPath = is_array($data) ? '[config]' : 'config';
     $firstTime = false == PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
     foreach ($config['payum.default_options'] as $name => $value) {
         $propertyPath = is_array($data) ? "[config][{$name}]" : "config[{$name}]";
         if ($firstTime) {
             PropertyAccess::createPropertyAccessor()->setValue($data, $propertyPath, $value);
         }
         $type = is_bool($value) ? 'checkbox' : 'text';
         $options = array();
         $options['required'] = in_array($name, $config['payum.required_options']);
         $configForm->add($name, $type, $options);
     }
     $event->setData($data);
 }
开发者ID:Raxer971,项目名称:challenge,代码行数:34,代码来源:GatewayConfigType.php

示例10: manageLevel

 /**
  * @param array|Collection $data
  * @param integer $level
  * @return array
  */
 private function manageLevel($data, $level)
 {
     if ($level > $this->levelNb) {
         return array();
     }
     $accessor = PropertyAccess::createPropertyAccessor();
     $labelAccessor = isset($this->options[$level]['labelAccessor']) ? $this->options[$level]['labelAccessor'] : null;
     $valueAccessor = isset($this->options[$level]['valueAccessor']) ? $this->options[$level]['valueAccessor'] : null;
     $groupAccessor = isset($this->options[$level]['groupAccessor']) ? $this->options[$level]['groupAccessor'] : null;
     $extraDataAccessor = isset($this->options[$level]['extraDataAccessor']) ? $this->options[$level]['extraDataAccessor'] : null;
     $cascadeData = array();
     foreach ($data as $element) {
         if ($level < $this->levelNb) {
             $nextLevelAccessor = isset($this->options[$level]['nextLevelAccessor']) ? $this->options[$level]['nextLevelAccessor'] : null;
             $nextLevelData = $nextLevelAccessor ? $accessor->getValue($element, $nextLevelAccessor) : null;
             $children = $this->manageLevel($nextLevelData, $level + 1);
         } else {
             $children = null;
         }
         $cascadeDataRow = array('label' => $labelAccessor ? $accessor->getValue($element, $labelAccessor) : (string) $element, 'value' => $valueAccessor ? $accessor->getValue($element, $valueAccessor) : uniqid(), 'children' => $children);
         if (null != $groupAccessor) {
             $cascadeDataRow['group'] = $accessor->getValue($element, $groupAccessor);
         }
         if (null != $extraDataAccessor) {
             $cascadeDataRow['data'] = $accessor->getValue($element, $extraDataAccessor);
         }
         $cascadeData[] = $cascadeDataRow;
     }
     return $cascadeData;
 }
开发者ID:cgtechnosoft2013,项目名称:smart-utils,代码行数:35,代码来源:CascadeManager.php

示例11: __construct

 /**
  * Constructor
  *
  * @param ObjectRepository          $repository
  * @param bool                      $multiple
  * @param PropertyAccessorInterface $propertyAccessor
  * @param string                    $delimiter
  */
 public function __construct(ObjectRepository $repository, $multiple, PropertyAccessorInterface $propertyAccessor = null, $delimiter = ',')
 {
     $this->repository = $repository;
     $this->multiple = $multiple;
     $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
     $this->delimiter = $delimiter;
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:15,代码来源:EntityToIdentifierTransformer.php

示例12: testSettersAndGetters

 /**
  * @dataProvider propertiesDataProvider
  * @param string $property
  * @param mixed $value
  */
 public function testSettersAndGetters($property, $value)
 {
     $obj = new JobResult();
     $accessor = PropertyAccess::createPropertyAccessor();
     $accessor->setValue($obj, $property, $value);
     $this->assertEquals($value, $accessor->getValue($obj, $property));
 }
开发者ID:Maksold,项目名称:platform,代码行数:12,代码来源:JobResultTest.php

示例13: getAccessor

 /**
  * @return PropertyAccessor
  */
 protected function getAccessor()
 {
     if ($this->accessor == null) {
         $this->accessor = PropertyAccess::createPropertyAccessor();
     }
     return $this->accessor;
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:MappedData.php

示例14: testProperties

 /**
  * @param string $property
  * @param mixed  $value
  * @param mixed  $expected
  *
  * @dataProvider propertyProvider
  */
 public function testProperties($property, $value, $expected)
 {
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     $this->assertNull($propertyAccessor->getValue($this->website, $property));
     $propertyAccessor->setValue($this->website, $property, $value);
     $this->assertEquals($expected, $propertyAccessor->getValue($this->website, $property));
 }
开发者ID:Maksold,项目名称:platform,代码行数:14,代码来源:TrackingWebsiteTest.php

示例15: testPropertyAccess

 public function testPropertyAccess()
 {
     $object = new AccessorHelper();
     $accessor = PropertyAccess::createPropertyAccessor();
     $accessor->setValue($object, 'name', 'test');
     $this->assertEquals('test', $accessor->getValue($object, 'name'));
 }
开发者ID:saxulum,项目名称:saxulum-accessor,代码行数:7,代码来源:SymfonyTest.php


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