1 | <?php |
||
10 | class Signature extends Serializable implements SignatureInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var \GMP |
||
14 | */ |
||
15 | private $r; |
||
16 | |||
17 | /** |
||
18 | * @var \GMP |
||
19 | */ |
||
20 | private $s; |
||
21 | |||
22 | /** |
||
23 | * @var EcAdapter |
||
24 | */ |
||
25 | private $ecAdapter; |
||
26 | |||
27 | /** |
||
28 | * @var resource |
||
29 | */ |
||
30 | private $secp256k1_sig; |
||
31 | |||
32 | /** |
||
33 | * @param EcAdapter $adapter |
||
34 | * @param \GMP $r |
||
35 | * @param \GMP $s |
||
36 | * @param resource $secp256k1_ecdsa_signature_t |
||
37 | */ |
||
38 | 104 | public function __construct(EcAdapter $adapter, \GMP $r, \GMP $s, $secp256k1_ecdsa_signature_t) |
|
39 | { |
||
40 | 104 | if (!is_resource($secp256k1_ecdsa_signature_t) || |
|
41 | 104 | !get_resource_type($secp256k1_ecdsa_signature_t) === SECP256K1_TYPE_SIG |
|
42 | ) { |
||
43 | throw new \InvalidArgumentException('Secp256k1\Signature\Signature expects ' . SECP256K1_TYPE_SIG . ' resource'); |
||
44 | } |
||
45 | |||
46 | 104 | $this->secp256k1_sig = $secp256k1_ecdsa_signature_t; |
|
47 | 104 | $this->ecAdapter = $adapter; |
|
48 | 104 | $this->r = $r; |
|
49 | 104 | $this->s = $s; |
|
50 | 104 | } |
|
51 | |||
52 | /** |
||
53 | * @return \GMP |
||
54 | */ |
||
55 | 3 | public function getR() |
|
59 | |||
60 | /** |
||
61 | * @return \GMP |
||
62 | */ |
||
63 | 3 | public function getS() |
|
67 | |||
68 | /** |
||
69 | * @return resource |
||
70 | */ |
||
71 | 92 | public function getResource() |
|
75 | |||
76 | /** |
||
77 | * @param Signature $other |
||
78 | * @return bool |
||
79 | */ |
||
80 | 25 | private function doEquals(Signature $other) |
|
81 | { |
||
82 | 25 | $a = ''; |
|
83 | 25 | $b = ''; |
|
84 | 25 | secp256k1_ecdsa_signature_serialize_der($this->ecAdapter->getContext(), $a, $this->getResource()); |
|
85 | 25 | secp256k1_ecdsa_signature_serialize_der($this->ecAdapter->getContext(), $b, $other->getResource()); |
|
86 | |||
87 | 25 | return $a === $b; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param SignatureInterface $signature |
||
92 | * @return bool |
||
93 | */ |
||
94 | 25 | public function equals(SignatureInterface $signature) |
|
95 | { |
||
96 | /** @var Signature $signature */ |
||
97 | 25 | return $this->doEquals($signature); |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * @return \BitWasp\Buffertools\BufferInterface |
||
102 | */ |
||
103 | public function getBuffer() |
||
107 | } |
||
108 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: