本文整理汇总了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);
}
示例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;
}
示例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);
}
示例4: getAccessotr
/**
* @return PropertyAccessor
*/
protected static function getAccessotr()
{
if (is_null(static::$accessor)) {
static::$accessor = PropertyAccess::createPropertyAccessor();
}
return static::$accessor;
}
示例5: getPropertyAccessor
/**
* @return \Symfony\Component\PropertyAccess\PropertyAccessor
*/
protected function getPropertyAccessor()
{
if (!$this->propertyAccessor) {
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
}
return $this->propertyAccessor;
}
示例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;
}
示例7: __construct
/**
* Construct
*/
public function __construct()
{
$this->accessor = PropertyAccess::createPropertyAccessor();
foreach ($this->getFieldDefinitions() as $field) {
$this->fields[$field->getName()] = $field;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
示例13: getAccessor
/**
* @return PropertyAccessor
*/
protected function getAccessor()
{
if ($this->accessor == null) {
$this->accessor = PropertyAccess::createPropertyAccessor();
}
return $this->accessor;
}
示例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));
}
示例15: testPropertyAccess
public function testPropertyAccess()
{
$object = new AccessorHelper();
$accessor = PropertyAccess::createPropertyAccessor();
$accessor->setValue($object, 'name', 'test');
$this->assertEquals('test', $accessor->getValue($object, 'name'));
}