php Symfony-Component-PropertyAccess-PropertyAccess类(方法)实例源码

下面列出了php Symfony-Component-PropertyAccess-PropertyAccess 类(方法)源码代码实例,从而了解它的用法。

作者:jmontoya    项目:SonataDoctrinePhpcrAdminBundl   
/**
  * 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();
         }
     }
 }

作者:Maksol    项目:platfor   
/**
  * @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));
 }

作者:johnpancoas    项目:data-validato   
/**
  * Construct
  */
 public function __construct()
 {
     $this->accessor = PropertyAccess::createPropertyAccessor();
     foreach ($this->getFieldDefinitions() as $field) {
         $this->fields[$field->getName()] = $field;
     }
 }

作者:abdeldaye    项目:pim-community-de   
/**
  * 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;
 }

作者:moder    项目:foundatio   
/**
  * @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;
 }

作者:dstansb    项目:camdra   
/**
  * @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());
 }

作者:hauteloo    项目:rabbitmq-ap   
/**
  * @return \Symfony\Component\PropertyAccess\PropertyAccessor
  */
 protected function getPropertyAccessor()
 {
     if (!$this->propertyAccessor) {
         $this->propertyAccessor = PropertyAccess::createPropertyAccessor();
     }
     return $this->propertyAccessor;
 }

作者:Maksol    项目:platfor   
/**
  * @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;
 }

作者:antramp    项目:cr   
/**
  * @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));
 }

作者:TuxCoffeeCorne    项目:tc   
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__));
 }

作者:ramunas    项目:platfor   
/**
  * @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));
 }

作者:hafeez300    项目:orocommerc   
/**
  * @param object $object
  * @param string $propertyName
  */
 public function __construct($object, $propertyName)
 {
     $this->accessor = PropertyAccess::createPropertyAccessor();
     $this->object = $object;
     $this->propertyName = $propertyName;
     $this->findAdderAndRemover();
 }

作者:clarolin    项目:distributio   
/**
  * 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);
 }

作者:subbl    项目:framewor   
public function __construct(Container $container)
 {
     $this->basePath = app_upload();
     $this->baseSource = app_upload() . '/uploads';
     $this->propertyAccessor = PropertyAccess::getPropertyAccessor();
     $this->basedirs = array();
 }

作者:antramp    项目:cr   
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);
 }

作者:gunjir    项目:gin   
/**
  * @return PropertyAccessor
  */
 protected static function getAccessotr()
 {
     if (is_null(static::$accessor)) {
         static::$accessor = PropertyAccess::createPropertyAccessor();
     }
     return static::$accessor;
 }

作者:saxulu    项目:saxulum-accesso   
public function testPropertyAccess()
 {
     $object = new AccessorHelper();
     $accessor = PropertyAccess::createPropertyAccessor();
     $accessor->setValue($object, 'name', 'test');
     $this->assertEquals('test', $accessor->getValue($object, 'name'));
 }

作者:nany    项目:Syliu   
/**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $choiceList = function (Options $options) {
         return new ObjectChoiceList($options['option']->getValues(), 'value', array(), null, 'id', PropertyAccess::createPropertyAccessor());
     };
     $resolver->setDefaults(array('choice_list' => $choiceList))->setRequired(array('option'))->addAllowedTypes(array('option' => 'Sylius\\Component\\Variation\\Model\\OptionInterface'));
 }

作者:ramunas    项目:platfor   
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;
 }

作者:cubich    项目:cubich   
/**
  * {@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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号