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


PHP PropertyAccess::getPropertyAccessor方法代碼示例

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


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

示例1: onSubmit

 /**
  * Reorder the children of the parent form data at $this->name.
  *
  * For whatever reason we have to go through the parent object, just
  * getting the collection from the form event and reordering it does
  * not update the stored order.
  *
  * @param FormEvent $event
  */
 public function onSubmit(FormEvent $event)
 {
     $form = $event->getForm()->getParent();
     $data = $form->getData();
     if (!is_object($data)) {
         return;
     }
     $accessor = PropertyAccess::getPropertyAccessor();
     // use deprecated BC method to support symfony 2.2
     $newCollection = $accessor->getValue($data, $this->name);
     if (!$newCollection instanceof Collection) {
         return;
     }
     /* @var $newCollection Collection */
     $newCollection->clear();
     /** @var $item FormBuilder */
     foreach ($form->get($this->name) as $key => $item) {
         if ($item->get('_delete')->getData()) {
             // do not re-add a deleted child
             continue;
         }
         if ($item->getName() && !is_numeric($item->getName())) {
             // keep key in collection
             $newCollection[$item->getName()] = $item->getData();
         } else {
             $newCollection[] = $item->getData();
         }
     }
 }
開發者ID:jmontoyaa,項目名稱:SonataDoctrinePhpcrAdminBundle,代碼行數:38,代碼來源:CollectionOrderListener.php

示例2: 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(array('routeName' => null, 'routeParams' => array(), 'pageParameter' => '[page]', 'queryString' => null), $options);
     if (null === $viewName) {
         $viewName = $this->container->getParameter('white_october_pagerfanta.default_view');
     }
     $router = $this->container->get('router');
     if (null === $options['routeName']) {
         $request = $this->container->get('request');
         $options['routeName'] = $request->attributes->get('_route');
         if ('_internal' === $options['routeName']) {
             throw new \Exception('PagerfantaBundle can not guess the route when used in a subrequest');
         }
         $options['routeParams'] = array_merge($request->query->all(), $request->attributes->get('_route_params'));
     }
     $routeName = $options['routeName'];
     $routeParams = $options['routeParams'];
     $pagePropertyPath = new PropertyPath($options['pageParameter']);
     $routeGenerator = function ($page) use($router, $routeName, $routeParams, $pagePropertyPath, $options) {
         $propertyAccessor = PropertyAccess::getPropertyAccessor();
         $propertyAccessor->setValue($routeParams, $pagePropertyPath, $page);
         $url = $router->generate($routeName, $routeParams);
         if ($options['queryString']) {
             $url .= '?' . $options['queryString'];
         }
         return $url;
     };
     return $this->container->get('white_october_pagerfanta.view_factory')->get($viewName)->render($pagerfanta, $routeGenerator, $options);
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:38,代碼來源:PagerfantaExtension.php

示例3: __construct

 public function __construct(Container $container)
 {
     $this->basePath = app_upload();
     $this->baseSource = app_upload() . '/uploads';
     $this->propertyAccessor = PropertyAccess::getPropertyAccessor();
     $this->basedirs = array();
 }
開發者ID:subbly,項目名稱:framework,代碼行數:7,代碼來源:MediaResolver.php

示例4: 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::getPropertyAccessor();
     $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:ilosada,項目名稱:chamilo-lms-icpna,代碼行數:38,代碼來源:PagerfantaExtension.php

示例5: getText

 protected function getText($object)
 {
     if (!$this->property || !class_exists('Symfony\\Component\\PropertyAccess\\PropertyAccess')) {
         return (string) $object;
     }
     $accessor = PropertyAccess::getPropertyAccessor();
     return $accessor->getValue($object, $this->property);
 }
開發者ID:ptsavdar,項目名稱:ZenstruckFormBundle,代碼行數:8,代碼來源:AjaxEntityTransformer.php

示例6: __construct

 /**
  * Creates a new object choice list.
  *
  * @param array|\Traversable       $choices           The array of choices. Choices may also be given
  *                                                    as hierarchy of unlimited depth by creating nested
  *                                                    arrays. The title of the sub-hierarchy can be
  *                                                    stored in the array key pointing to the nested
  *                                                    array. The topmost level of the hierarchy may also
  *                                                    be a \Traversable.
  * @param string                   $labelPath         A property path pointing to the property used
  *                                                    for the choice labels. The value is obtained
  *                                            by calling the getter on the object. If the
  *                                                    path is NULL, the object's __toString() method
  *                                                    is used instead.
  * @param array                    $preferredChoices  A flat array of choices that should be
  *                                                    presented to the user with priority.
  * @param string                   $groupPath         A property path pointing to the property used
  *                                                    to group the choices. Only allowed if
  *                                                    the choices are given as flat array.
  * @param string                   $valuePath         A property path pointing to the property used
  *                                                    for the choice values. If not given, integers
  *                                                    are generated instead.
  * @param PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
  */
 public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::getPropertyAccessor();
     $this->labelPath = null !== $labelPath ? new PropertyPath($labelPath) : null;
     $this->groupPath = null !== $groupPath ? new PropertyPath($groupPath) : null;
     $this->valuePath = null !== $valuePath ? new PropertyPath($valuePath) : null;
     parent::__construct($choices, array(), $preferredChoices);
 }
開發者ID:acappel01,項目名稱:opencall,代碼行數:32,代碼來源:ObjectChoiceList.php

示例7: __construct

 /**
  * @param IItem $root
  * @param int $maxDepth
  * @param array $filter
  */
 public function __construct(IItem $root, $maxDepth = -1, $filter = array())
 {
     parent::__construct($root, parent::SELF_FIRST);
     parent::setMaxDepth($maxDepth);
     $this->filter = $filter;
     $this->accessor = PropertyAccess::getPropertyAccessor();
     $this->iterated = new \SplObjectStorage();
 }
開發者ID:appsco,項目名稱:component-firi,代碼行數:13,代碼來源:BushIterator.php

示例8: getValue

 /**
  * {@inheritDoc}
  */
 public function getValue($source)
 {
     try {
         return PropertyAccess::getPropertyAccessor()->getValue($source, $this->sourcePropertyPath);
     } catch (NoSuchPropertyException $ex) {
         // ignore properties not found
     }
 }
開發者ID:Aasit,項目名稱:DISCOUNT--SRV-I,代碼行數:11,代碼來源:Simple.php

示例9: testResolveEntityUrl

 /** @dataProvider provideResolveEntityUrlTestData */
 public function testResolveEntityUrl($pattern, $context, $expectation)
 {
     $actions = Actions::enable();
     $entity = new Entity($context, PropertyAccess::getPropertyAccessor());
     $method = new \ReflectionMethod($actions, 'resolveEntityUrl');
     $method->setAccessible(true);
     $url = $method->invoke($actions, $pattern, $entity);
     $this->assertEquals($expectation, $url);
 }
開發者ID:jfsimon,項目名稱:datagrid,代碼行數:10,代碼來源:ActionsTest.php

示例10: remap

 /** Re-map, initially the purpose was to have a dual of map($target, $data), it ends up being
  * more general : Maps $source stuff over $target based of an list of (from ; to) pairs defined
  * as $ppaths (key->value).
  *
  * Fixme: map() shall disappear in favor of this one func.
  *
  * @param  mixed $source Anything that the PropertyPath component can work with, typically an object or array.
  * @param  array $ppaths A mapping of property paths over $source, to property paths over $target.
  * @param  array $target Likewise $source, defaults to array().
  * @return mixed $target.
  *
  * Fixme: //public static function remap($source, \Traversable $ppaths, $target = array())
  */
 public static function remap($source, array $ppaths, $target = array())
 {
     $accessor = PropertyAccess::getPropertyAccessor();
     foreach ($ppaths as $from => $to) {
         $to = $to ?: "[{$from}]";
         $value = $accessor->getValue($source, $from);
         $accessor->setValue($target, $to, $value);
     }
     return $target;
 }
開發者ID:fabic,項目名稱:php-utils,代碼行數:23,代碼來源:ValueMapper.php

示例11: transform

 public function transform($entity)
 {
     if (null === $entity) {
         return null;
     }
     //if (!$this->unitOfWork->isInIdentityMap($entity) and !$this->unitOfWork->isScheduledForInsert($entity)) {
     //    throw new TransformationFailedException("Entities must be managed");
     //}
     return !empty($this->property) ? PropertyAccess::getPropertyAccessor()->getValue($entity, $this->property) : current($this->unitOfWork->getEntityIdentifier($entity));
 }
開發者ID:mwveliz,項目名稱:bl,代碼行數:10,代碼來源:EntityToPropertyTransformer.php

示例12: transform

 /**
  * Transforms an object into an sphinx 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 array
  **/
 public function transform($object, array $fields)
 {
     $accessor = PropertyAccess::getPropertyAccessor();
     $identifier = $accessor->getValue($object, $this->options['identifier']);
     $document = array('id' => $identifier);
     foreach ($fields as $key) {
         $property = $accessor->getValue($object, $key);
         $document[$key] = $this->normalizeValue($property);
     }
     return $document;
 }
開發者ID:camdram,項目名稱:sphinx-realtime-bundle,代碼行數:19,代碼來源:ModelToSphinxAutoTransformer.php

示例13: preSetData

 public function preSetData(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     }
     $accessor = PropertyAccess::getPropertyAccessor();
     $city = $accessor->getValue($data, $this->propertyPathToCity);
     $country = $city ? $city->getProvince()->getCountry() : null;
     $this->addCountryForm($form, $country);
 }
開發者ID:sourcevx,項目名稱:Test,代碼行數:12,代碼來源:AddCountryFieldSubscriber.php

示例14: preSetData

 public function preSetData(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     }
     $accessor = PropertyAccess::getPropertyAccessor();
     $centro = $accessor->getValue($data, $this->propertyPathToCentro);
     $tipo = $centro ? $centro->getTipo() : null;
     $this->addTipoCentroForm($form, $tipo);
 }
開發者ID:pepesalcedo,項目名稱:SEIP,代碼行數:12,代碼來源:AddTipoCentroFieldSubscriber.php

示例15: preSetData

 public function preSetData(FormEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     }
     $accessor = PropertyAccess::getPropertyAccessor();
     $model = $accessor->getValue($data, $this->propertyPathToModel);
     $country = $model ? $model->getBrand() : null;
     $this->addBrandForm($form, $country);
 }
開發者ID:Lezas,項目名稱:Dynamic_form,代碼行數:12,代碼來源:AddBrandFieldSubscriber.php


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