forked from danog/MadelineProto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLegacyMigrator.php
40 lines (36 loc) · 1.29 KB
/
LegacyMigrator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php declare(strict_types=1);
namespace danog\MadelineProto;
use danog\AsyncOrm\Annotations\OrmMappedArray;
use danog\AsyncOrm\DbAutoProperties;
use danog\AsyncOrm\Driver\MemoryArray as DriverMemoryArray;
use danog\MadelineProto\Db\CachedArray;
use danog\MadelineProto\Db\MemoryArray;
use ReflectionClass;
/** @internal */
trait LegacyMigrator
{
use DbAutoProperties;
/** @return list<\ReflectionProperty> */
private function getDbAutoProperties(): array
{
$res = [];
$closure = function (string $propName): void {
if (isset($this->{$propName})) {
if ($this->{$propName} instanceof CachedArray) {
unset($this->{$propName});
} elseif ($this->{$propName} instanceof MemoryArray) {
$this->{$propName} = new DriverMemoryArray($this->{$propName}->getArrayCopy());
}
}
};
foreach ((new ReflectionClass(static::class))->getProperties() as $property) {
$attr = $property->getAttributes(OrmMappedArray::class);
if (!$attr) {
continue;
}
$closure->bindTo($this, $property->getDeclaringClass()->getName())($property->getName());
$res []= $property;
}
return $res;
}
}