Skip to content

Commit c5bf40c

Browse files
committed
Improve proxy class constructor
1 parent 5e9694d commit c5bf40c

File tree

3 files changed

+31
-46
lines changed

3 files changed

+31
-46
lines changed

src/Proxy.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use FFI\Proxy\Exception\NotAvailableException;
1515

16-
abstract class Proxy implements ProxyInterface, ApiInterface
16+
abstract class Proxy implements ApiInterface
1717
{
1818
use ProxyAwareTrait;
1919
use ApiAwareTrait;
@@ -25,6 +25,16 @@ abstract class Proxy implements ProxyInterface, ApiInterface
2525
*/
2626
public \FFI $ffi;
2727

28+
/**
29+
* @param \FFI|null $ffi
30+
*/
31+
public function __construct(\FFI $ffi = null)
32+
{
33+
if ($ffi !== null) {
34+
$this->ffi = $ffi;
35+
}
36+
}
37+
2838
/**
2939
* Proxy should not be serializable.
3040
*/

src/ProxyAwareTrait.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313

1414
/**
1515
* @property-read \FFI $ffi
16-
* @mixin ProxyInterface
17-
* @psalm-require-implements ProxyInterface
1816
*/
1917
trait ProxyAwareTrait
2018
{
2119
/**
22-
* @see ProxyInterface::__call()
23-
*
2420
* @psalm-param string $method
2521
* @psalm-param array $args
2622
* @psalm-return mixed
@@ -31,9 +27,7 @@ public function __call(string $method, array $args)
3127
}
3228

3329
/**
34-
* @see ProxyInterface::__get()
35-
*
36-
* @psalm-param string $name
30+
* @psalm-param non-empty-string $name
3731
* @psalm-return mixed
3832
*/
3933
public function __get(string $name)
@@ -42,14 +36,30 @@ public function __get(string $name)
4236
}
4337

4438
/**
45-
* @see ProxyInterface::__set()
46-
*
47-
* @psalm-param string $name
39+
* @psalm-param non-empty-string $name
4840
* @psalm-param mixed $value
4941
* @psalm-return void
5042
*/
5143
public function __set(string $name, $value): void
5244
{
5345
$this->ffi->$name = $value;
5446
}
47+
48+
/**
49+
* @psalm-param non-empty-string $name
50+
* @psalm-return bool
51+
*/
52+
public function __isset(string $name): bool
53+
{
54+
return isset($this->ffi->$name);
55+
}
56+
57+
/**
58+
* @psalm-param non-empty-string $name
59+
* @psalm-return bool
60+
*/
61+
public function __unset(string $name): void
62+
{
63+
unset($this->ffi->$name);
64+
}
5565
}

src/ProxyInterface.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)