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


PHP PropertyAccess\PropertyAccess类代码示例

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


在下文中一共展示了PropertyAccess类的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: testSettersAndGetters

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

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

示例4: __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

示例5: __invoke

 /**
  * @param object             $entity
  * @param ContainerInterface $container
  *
  * @return array
  */
 public function __invoke($entity, ContainerInterface $container)
 {
     /* @var EntityManager $em */
     $em = $container->get('doctrine.orm.entity_manager');
     if (!$this->accessor) {
         $this->accessor = PropertyAccess::createPropertyAccessor();
     }
     $meta = $em->getClassMetadata(get_class($entity));
     $result = array();
     foreach ($meta->getFieldNames() as $fieldName) {
         $result[$fieldName] = $this->accessor->getValue($entity, $fieldName);
     }
     $hasToStringMethod = in_array('__toString', get_class_methods(get_class($entity)));
     foreach ($meta->getAssociationNames() as $fieldName) {
         if (isset($this->associativeFieldMappings[$fieldName])) {
             $expression = $this->associativeFieldMappings[$fieldName];
             $result[$fieldName] = $this->accessor->getValue($entity, $expression);
         } elseif ($hasToStringMethod) {
             $result[$fieldName] = $entity->__toString();
         }
     }
     $finalResult = array();
     foreach ($result as $fieldName => $fieldValue) {
         if (in_array($fieldName, $this->excludedFields)) {
             continue;
         }
         $finalResult[$fieldName] = $fieldValue;
     }
     return $finalResult;
 }
开发者ID:modera,项目名称:foundation,代码行数:36,代码来源:DoctrineEntityHydrator.php

示例6: createFeed

 /**
  * @param $data array
  * @param format string, either rss or atom
  */
 protected function createFeed(View $view, Request $request)
 {
     $feed = new Feed();
     $data = $view->getData();
     $item = current($data);
     $annotationData = $this->reader->read($item);
     if ($item && ($feedData = $annotationData->getFeed())) {
         $class = get_class($item);
         $feed->setTitle($feedData->getName());
         $feed->setDescription($feedData->getDescription());
         $feed->setLink($this->urlGen->generateCollectionUrl($class));
         $feed->setFeedLink($this->urlGen->generateCollectionUrl($class, $request->getRequestFormat()), $request->getRequestFormat());
     } else {
         $feed->setTitle('Camdram feed');
         $feed->setDescription('Camdram feed');
     }
     $lastModified = null;
     $accessor = PropertyAccess::createPropertyAccessor();
     // Add one or more entries. Note that entries must be manually added once created.
     foreach ($data as $document) {
         $entry = $feed->createEntry();
         $entry->setTitle($accessor->getValue($document, $feedData->getTitleField()));
         $entry->setLink($this->urlGen->generateUrl($document));
         $entry->setDescription($this->twig->render($feedData->getTemplate(), array('entity' => $document)));
         if ($accessor->isReadable($document, $feedData->getUpdatedAtField())) {
             $entry->setDateModified($accessor->getValue($document, $feedData->getUpdatedAtField()));
         }
         $feed->addEntry($entry);
         if (!$lastModified || $entry->getDateModified() > $lastModified) {
             $lastModified = $entry->getDateModified();
         }
     }
     $feed->setDateModified($lastModified);
     return $feed->export($request->getRequestFormat());
 }
开发者ID:dstansby,项目名称:camdram,代码行数:39,代码来源:FeedViewHandler.php

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

示例8: getAttachmentAction

 /**
  * @Route("attachment/{codedString}.{extension}",
  *   name="oro_attachment_file",
  *   requirements={"extension"="\w+"}
  * )
  */
 public function getAttachmentAction($codedString, $extension)
 {
     list($parentClass, $fieldName, $parentId, $type, $filename) = $this->get('oro_attachment.manager')->decodeAttachmentUrl($codedString);
     $parentEntity = $this->getDoctrine()->getRepository($parentClass)->find($parentId);
     if (!$this->get('oro_security.security_facade')->isGranted('VIEW', $parentEntity)) {
         throw new AccessDeniedException();
     }
     $accessor = PropertyAccess::createPropertyAccessor();
     $attachment = $accessor->getValue($parentEntity, $fieldName);
     if ($attachment instanceof Collection) {
         foreach ($attachment as $attachmentEntity) {
             if ($attachmentEntity->getOriginalFilename() === $filename) {
                 $attachment = $attachmentEntity;
                 break;
             }
         }
     }
     if ($attachment instanceof Collection || $attachment->getOriginalFilename() !== $filename) {
         throw new NotFoundHttpException();
     }
     $response = new Response();
     $response->headers->set('Cache-Control', 'public');
     if ($type == 'get') {
         $response->headers->set('Content-Type', $attachment->getMimeType() ?: 'application/force-download');
     } else {
         $response->headers->set('Content-Type', 'application/force-download');
         $response->headers->set('Content-Disposition', sprintf('attachment;filename="%s"', $attachment->getOriginalFilename()));
     }
     $response->headers->set('Content-Length', $attachment->getFileSize());
     $response->setContent($this->get('oro_attachment.manager')->getContent($attachment));
     return $response;
 }
开发者ID:Maksold,项目名称:platform,代码行数:38,代码来源:FileController.php

示例9: testGetSet

 /**
  * @dataProvider getSetDataProvider
  */
 public function testGetSet($property, $value)
 {
     $obj = new Call();
     $accessor = PropertyAccess::createPropertyAccessor();
     $accessor->setValue($obj, $property, $value);
     $this->assertSame($value, $accessor->getValue($obj, $property));
 }
开发者ID:antrampa,项目名称:crm,代码行数:10,代码来源:CallTest.php

示例10: setUp

 protected function setUp()
 {
     $this->context = $this->getMock('Symfony\\Component\\Validator\\ExecutionContext', array(), array(), '', false);
     $this->validator = new ExpressionValidator(PropertyAccess::createPropertyAccessor());
     $this->validator->initialize($this->context);
     $this->context->expects($this->any())->method('getClassName')->will($this->returnValue(__CLASS__));
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:7,代码来源:ExpressionValidatorTest.php

示例11: testSettersAndGetters

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

示例12: __construct

 /**
  * @param object $object
  * @param string $propertyName
  */
 public function __construct($object, $propertyName)
 {
     $this->accessor = PropertyAccess::createPropertyAccessor();
     $this->object = $object;
     $this->propertyName = $propertyName;
     $this->findAdderAndRemover();
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:11,代码来源:CollectionAccessor.php

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

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

示例15: testProcess

 public function testProcess()
 {
     $item = ['property' => 'value'];
     $expectedProperty = 'property2';
     $expectedValue = 'value2';
     /** @var \PHPUnit_Framework_MockObject_MockObject|SerializerInterface $serializer */
     $serializer = $this->getMock('Symfony\\Component\\Serializer\\SerializerInterface');
     $serializer->expects($this->once())->method('deserialize')->will($this->returnCallback(function ($item) {
         return (object) $item;
     }));
     $this->processor->setSerializer($serializer);
     /** @var \PHPUnit_Framework_MockObject_MockObject|StrategyInterface $strategy */
     $strategy = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Strategy\\StrategyInterface');
     $strategy->expects($this->once())->method('process')->with($this->isType('object'))->will($this->returnCallback(function ($item) use($expectedProperty, $expectedValue) {
         $item->{$expectedProperty} = $expectedValue;
         return $item;
     }));
     $this->processor->setStrategy($strategy);
     $this->processor->setEntityName('\\stdClass');
     /** @var \PHPUnit_Framework_MockObject_MockObject|ContextInterface $context */
     $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $context->expects($this->once())->method('getConfiguration')->will($this->returnValue([]));
     $this->processor->setImportExportContext($context);
     $result = $this->processor->process($item);
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     $this->assertNotEmpty($propertyAccessor->getValue($result, $expectedProperty), $expectedValue);
 }
开发者ID:antrampa,项目名称:crm,代码行数:27,代码来源:ContextProcessorTest.php


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