forked from wasmerio/wasmer-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStore.php
59 lines (51 loc) · 1.16 KB
/
Store.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Wasm;
/**
* @api
*/
final class Store
{
/**
* @var resource The inner `wasm_store_t` resource
*/
private $inner;
/**
* Create a Wasm\Store from a `wasm_store_t` resource.
*
* @param $store resource a `wasm_store_t` resource
*
* @throw Exception\InvalidArgumentException If the `$store` argument is not a valid `wasm_store_t` resource
*/
public function __construct($store)
{
if (false === is_resource($store) || 'wasm_store_t' !== get_resource_type($store)) {
throw new Exception\InvalidArgumentException();
}
$this->inner = $store;
}
public function __destruct()
{
try {
\wasm_store_delete($this->inner);
} catch (\TypeError $error) {
if (is_resource($this->inner)) {
throw $error;
}
}
}
/**
* @return resource
*/
public function inner()
{
return $this->inner;
}
/**
* @api
*/
public static function new(Engine $engine): self
{
return new self(\wasm_store_new($engine->inner()));
}
}