本文整理汇总了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();
}
}
}
示例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));
}
示例3: __construct
/**
* Construct
*/
public function __construct()
{
$this->accessor = PropertyAccess::createPropertyAccessor();
foreach ($this->getFieldDefinitions() as $field) {
$this->fields[$field->getName()] = $field;
}
}
示例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;
}
示例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;
}
示例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());
}
示例7: getPropertyAccessor
/**
* @return \Symfony\Component\PropertyAccess\PropertyAccessor
*/
protected function getPropertyAccessor()
{
if (!$this->propertyAccessor) {
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
}
return $this->propertyAccessor;
}
示例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;
}
示例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));
}
示例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__));
}
示例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));
}
示例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();
}
示例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);
}
示例14: __construct
public function __construct(Container $container)
{
$this->basePath = app_upload();
$this->baseSource = app_upload() . '/uploads';
$this->propertyAccessor = PropertyAccess::getPropertyAccessor();
$this->basedirs = array();
}
示例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);
}