Skip to content

Commit 17b2d65

Browse files
author
Charles J. C. Elling Espejel
committed
Remove dependency in the symfony/property-access library
1 parent 7586b5b commit 17b2d65

File tree

4 files changed

+30
-48
lines changed

4 files changed

+30
-48
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"require": {
4141
"php": ">=5.3.2",
4242
"behat/transliterator": "~1.2",
43-
"doctrine/common": "~2.4",
44-
"symfony/property-access": "~2.7|~3.0"
43+
"doctrine/common": "~2.4"
4544
},
4645
"require-dev": {
4746
"doctrine/mongodb-odm": ">=1.0.2",

composer7.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"require": {
4141
"php": ">=5.4",
4242
"behat/transliterator": "~1.2",
43-
"doctrine/common": "~2.4",
44-
"symfony/property-access": "~2.7|~3.0"
43+
"doctrine/common": "~2.4"
4544
},
4645
"replace": {
4746
"ext-mongo": "1.6.12"

lib/Gedmo/Mapping/MappedEventSubscriber.php

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
use Doctrine\Common\EventSubscriber;
88
use Doctrine\Common\Persistence\ObjectManager;
99
use Doctrine\Common\EventArgs;
10-
use Symfony\Component\PropertyAccess\PropertyAccessor;
11-
use Symfony\Component\PropertyAccess\PropertyAccess;
10+
use Gedmo\Mapping\Event\AdapterInterface;
1211

1312
/**
1413
* This is extension of event subscriber class and is
@@ -66,13 +65,7 @@ abstract class MappedEventSubscriber implements EventSubscriber
6665
* @var \Doctrine\Common\Annotations\AnnotationReader
6766
*/
6867
private static $defaultAnnotationReader;
69-
70-
/**
71-
*
72-
* @var PropertyAccessor
73-
*/
74-
private $propertyAccessor;
75-
68+
7669
/**
7770
* Constructor
7871
*/
@@ -269,23 +262,22 @@ private function getDefaultAnnotationReader()
269262
}
270263

271264
/**
272-
* @return \Symfony\Component\PropertyAccess\PropertyAccessor
273-
*/
274-
public function getPropertyAccessor()
275-
{
276-
if($this->propertyAccessor === null)
277-
{
278-
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
279-
}
280-
return $this->propertyAccessor;
281-
}
282-
283-
/**
284-
* @param \Symfony\Component\PropertyAccess\PropertyAccessor $propertyAccessor
265+
* Sets the value for a mapped field
266+
*
267+
* @param AdapterInterface $adapter
268+
* @param object $object
269+
* @param string $field
270+
* @param mixed $oldValue
271+
* @param mixed $newValue
285272
*/
286-
public function setPropertyAccessor($propertyAccessor)
273+
protected function setFieldValue(AdapterInterface $adapter, $object, $field, $oldValue, $newValue)
287274
{
288-
$this->propertyAccessor = $propertyAccessor;
275+
$manager = $adapter->getObjectManager();
276+
$meta = $manager->getClassMetadata(get_class($object));
277+
$uow = $manager->getUnitOfWork();
278+
279+
$meta->getReflectionProperty($field)->setValue($object, $newValue);
280+
$uow->propertyChanged($object, $field, $oldValue, $newValue);
281+
$adapter->recomputeSingleObjectChangeSet($uow, $meta, $object);
289282
}
290-
291283
}

lib/Gedmo/Sortable/SortableListener.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ private function processInsert(SortableAdapter $ea, array $config, $meta, $objec
159159
{
160160
$em = $ea->getObjectManager();
161161
$uow = $em->getUnitOfWork();
162-
$accessor = $this->getPropertyAccessor();
163162

164-
$old = $accessor->getValue($object, $config['position']);
165-
$newPosition = $accessor->getValue($object, $config['position']);
163+
$old = $meta->getReflectionProperty($config['position'])->getValue($object);
164+
$newPosition = $meta->getReflectionProperty($config['position'])->getValue($object);
165+
166166
if (is_null($newPosition)) {
167167
$newPosition = -1;
168168
}
@@ -211,8 +211,7 @@ private function processInsert(SortableAdapter $ea, array $config, $meta, $objec
211211

212212
// Set new position
213213
if ($old < 0 || is_null($old)) {
214-
$accessor->setValue($object, $config['position'], $newPosition);
215-
$ea->recomputeSingleObjectChangeSet($uow, $meta, $object);
214+
$this->setFieldValue($ea, $object, $config['position'], $old, $newPosition);
216215
}
217216
}
218217

@@ -228,7 +227,6 @@ private function processUpdate(SortableAdapter $ea, array $config, $meta, $objec
228227
{
229228
$em = $ea->getObjectManager();
230229
$uow = $em->getUnitOfWork();
231-
$accessor = $this->getPropertyAccessor();
232230

233231
$changed = false;
234232
$groupHasChanged = false;
@@ -252,7 +250,7 @@ private function processUpdate(SortableAdapter $ea, array $config, $meta, $objec
252250
if (array_key_exists($config['position'], $changeSet)) {
253251
$oldPosition = $changeSet[$config['position']][0];
254252
} else {
255-
$oldPosition = $accessor->getValue($object, $config['position']);
253+
$oldPosition = $meta->getReflectionProperty($config['position'])->getValue($object);
256254
}
257255
$this->addRelocation($oldHash, $config['useObjectClass'], $oldGroups, $oldPosition + 1, $this->maxPositions[$oldHash] + 1, -1);
258256
$groupHasChanged = true;
@@ -354,8 +352,7 @@ private function processUpdate(SortableAdapter $ea, array $config, $meta, $objec
354352
}
355353

356354
// Set new position
357-
$accessor->setValue($object, $config['position'], $newPosition);
358-
$ea->recomputeSingleObjectChangeSet($uow, $meta, $object);
355+
$this->setFieldValue($ea, $object, $config['position'], $oldPosition, $newPosition);
359356
}
360357

361358
/**
@@ -368,8 +365,7 @@ private function processUpdate(SortableAdapter $ea, array $config, $meta, $objec
368365
*/
369366
private function processDeletion(SortableAdapter $ea, array $config, $meta, $object)
370367
{
371-
$accessor = $this->getPropertyAccessor();
372-
$position = $accessor->getValue($object, $config['position']);
368+
$position = $meta->getReflectionProperty($config['position'])->getValue($object);
373369

374370
// Get groups
375371
$groups = $this->getGroups($meta, $config, $object);
@@ -417,7 +413,6 @@ public function postFlush(EventArgs $args)
417413
{
418414
$ea = $this->getEventAdapter($args);
419415
$em = $ea->getObjectManager();
420-
$accessor = $this->getPropertyAccessor();
421416
foreach ($this->relocations as $hash => $relocation) {
422417
$config = $this->getConfiguration($em, $relocation['name']);
423418
foreach ($relocation['deltas'] as $delta) {
@@ -455,12 +450,12 @@ public function postFlush(EventArgs $args)
455450
}
456451

457452
$oid = spl_object_hash($object);
458-
$pos = $accessor->getValue($object, $config['position']);
453+
$pos = $meta->getReflectionProperty($config['position'])->getValue($object);
459454
$matches = $pos >= $delta['start'];
460455
$matches = $matches && ($delta['stop'] <= 0 || $pos < $delta['stop']);
461456
$value = reset($relocation['groups']);
462457
while ($matches && ($group = key($relocation['groups']))) {
463-
$gr = $accessor->getValue($object, $group);
458+
$gr = $meta->getReflectionProperty($group)->getValue($object);
464459
if (null === $value) {
465460
$matches = $gr === null;
466461
} elseif (is_object($gr) && is_object($value) && $gr !== $value) {
@@ -478,9 +473,7 @@ public function postFlush(EventArgs $args)
478473
$value = next($relocation['groups']);
479474
}
480475
if ($matches) {
481-
$newValue = $pos + $delta['delta'];
482-
$accessor->setValue($object, $config['position'], $newValue);
483-
$ea->setOriginalObjectProperty($uow, $oid, $config['position'], $newValue);
476+
$this->setFieldValue($ea, $object, $config['position'], $pos, $pos + $delta['delta']);
484477
}
485478
}
486479
}
@@ -584,11 +577,10 @@ private function addRelocation($hash, $class, $groups, $start, $stop, $delta, ar
584577
*/
585578
private function getGroups($meta, $config, $object)
586579
{
587-
$accessor = $this->getPropertyAccessor();
588580
$groups = array();
589581
if (isset($config['groups'])) {
590582
foreach ($config['groups'] as $group) {
591-
$groups[$group] = $accessor->getValue($object, $group);
583+
$groups[$group] = $meta->getReflectionProperty($group)->getValue($object);
592584
}
593585
}
594586

0 commit comments

Comments
 (0)