@@ -6,61 +6,61 @@ |
||
| 6 | 6 | { |
| 7 | 7 | protected static array $objects = []; |
| 8 | 8 | |
| 9 | - public static function add (NetObject $object): void |
|
| 9 | + public static function add(NetObject $object): void |
|
| 10 | 10 | { |
| 11 | - self::$objects[$object->selector] = \WeakReference::create ($object); |
|
| 11 | + self::$objects[$object->selector] = \WeakReference::create($object); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public static function get (int $selector): ?NetObject |
|
| 14 | + public static function get(int $selector): ?NetObject |
|
| 15 | 15 | { |
| 16 | 16 | if (!isset (self::$objects[$selector])) |
| 17 | 17 | return null; |
| 18 | 18 | |
| 19 | - $object = self::$objects[$selector]->get (); |
|
| 19 | + $object = self::$objects[$selector]->get(); |
|
| 20 | 20 | |
| 21 | 21 | if ($object === null) |
| 22 | - self::remove ($selector); |
|
| 22 | + self::remove($selector); |
|
| 23 | 23 | |
| 24 | 24 | return $object; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public static function exists (int $selector): bool |
|
| 27 | + public static function exists(int $selector): bool |
|
| 28 | 28 | { |
| 29 | 29 | return isset (self::$objects[$selector]); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public static function getObjects (): array |
|
| 32 | + public static function getObjects(): array |
|
| 33 | 33 | { |
| 34 | 34 | return self::$objects; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - public static function remove (int $selector): void |
|
| 37 | + public static function remove(int $selector): void |
|
| 38 | 38 | { |
| 39 | 39 | unset (self::$objects[$selector]); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public static function clean (): void |
|
| 42 | + public static function clean(): void |
|
| 43 | 43 | { |
| 44 | 44 | foreach (self::$objects as $selector => $reference) |
| 45 | - if ($reference->get () === null) |
|
| 45 | + if ($reference->get() === null) |
|
| 46 | 46 | unset (self::$objects[$selector]); |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | -function _c (int $selector): ?NetObject |
|
| 50 | +function _c(int $selector): ?NetObject |
|
| 51 | 51 | { |
| 52 | - return Components::get ($selector); |
|
| 52 | + return Components::get($selector); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // TODO: поддержка многоуровневых ссылок вида родитель->родитель->объект |
| 56 | -function c (string $name): ?NetObject |
|
| 56 | +function c(string $name): ?NetObject |
|
| 57 | 57 | { |
| 58 | - if (is_int ($name) && ($object = _c($name)) !== null) |
|
| 58 | + if (is_int($name) && ($object = _c($name)) !== null) |
|
| 59 | 59 | return $object; |
| 60 | 60 | |
| 61 | - foreach (Components::getObjects () as $selector => $reference) |
|
| 61 | + foreach (Components::getObjects() as $selector => $reference) |
|
| 62 | 62 | { |
| 63 | - $object = $reference->get (); |
|
| 63 | + $object = $reference->get(); |
|
| 64 | 64 | |
| 65 | 65 | if ($object === null) |
| 66 | 66 | continue; |
@@ -13,13 +13,15 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | public static function get (int $selector): ?NetObject |
| 15 | 15 | { |
| 16 | - if (!isset (self::$objects[$selector])) |
|
| 17 | - return null; |
|
| 16 | + if (!isset (self::$objects[$selector])) { |
|
| 17 | + return null; |
|
| 18 | + } |
|
| 18 | 19 | |
| 19 | 20 | $object = self::$objects[$selector]->get (); |
| 20 | 21 | |
| 21 | - if ($object === null) |
|
| 22 | - self::remove ($selector); |
|
| 22 | + if ($object === null) { |
|
| 23 | + self::remove ($selector); |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | return $object; |
| 25 | 27 | } |
@@ -41,9 +43,10 @@ discard block |
||
| 41 | 43 | |
| 42 | 44 | public static function clean (): void |
| 43 | 45 | { |
| 44 | - foreach (self::$objects as $selector => $reference) |
|
| 45 | - if ($reference->get () === null) |
|
| 46 | + foreach (self::$objects as $selector => $reference) { |
|
| 47 | + if ($reference->get () === null) |
|
| 46 | 48 | unset (self::$objects[$selector]); |
| 49 | + } |
|
| 47 | 50 | } |
| 48 | 51 | } |
| 49 | 52 | |
@@ -55,23 +58,24 @@ discard block |
||
| 55 | 58 | // TODO: поддержка многоуровневых ссылок вида родитель->родитель->объект |
| 56 | 59 | function c (string $name): ?NetObject |
| 57 | 60 | { |
| 58 | - if (is_int ($name) && ($object = _c($name)) !== null) |
|
| 59 | - return $object; |
|
| 61 | + if (is_int ($name) && ($object = _c($name)) !== null) { |
|
| 62 | + return $object; |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | foreach (Components::getObjects () as $selector => $reference) |
| 62 | 66 | { |
| 63 | 67 | $object = $reference->get (); |
| 64 | 68 | |
| 65 | - if ($object === null) |
|
| 66 | - continue; |
|
| 69 | + if ($object === null) { |
|
| 70 | + continue; |
|
| 71 | + } |
|
| 67 | 72 | |
| 68 | 73 | try |
| 69 | 74 | { |
| 70 | - if ($object->name == $name) |
|
| 71 | - return $object; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - catch (\WinformsException $e) {} |
|
| 75 | + if ($object->name == $name) { |
|
| 76 | + return $object; |
|
| 77 | + } |
|
| 78 | + } catch (\WinformsException $e) {} |
|
| 75 | 79 | } |
| 76 | 80 | |
| 77 | 81 | return null; |