forked from wasmerio/wasmer-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngine.php
59 lines (50 loc) · 1.13 KB
/
Engine.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 Engine
{
/**
* @var resource
*/
private $inner;
/**
* @param ?resource $engine
*/
public function __construct($engine = null)
{
$engine = $engine ?? \wasm_engine_new();
if (false === is_resource($engine) || 'wasm_engine_t' !== get_resource_type($engine)) {
throw new Exception\InvalidArgumentException();
}
$this->inner = $engine;
}
public function __destruct()
{
try {
\wasm_engine_delete($this->inner);
} catch (\TypeError $error) {
if (is_resource($this->inner)) {
throw $error;
}
}
}
/**
* @return resource
*/
public function inner()
{
return $this->inner;
}
/**
* @api
*
* @throw Exception\InvalidArgumentException If the `$kind` is not a valid value kind
*/
public static function new(?Config $config = null): self
{
return new self($config ? \wasm_engine_new_with_config($config->inner()) : \wasm_engine_new());
}
}