mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-17 17:47:12 +00:00
* Added test-ffi target, use it in CI * Added clang-format config, fixed RETURN_STRING API mismatch * Skip installing php and packages on the PHP docker images * Removed al2 job that was never going to work, and compiler tests * Fixed basic test for extension loading * Cleaned up lib structure, fixed tests * use test-ci target to conditionally test in GitHub * Use v0.8.1 of builder
38 lines
939 B
PHP
38 lines
939 B
PHP
<?php
|
|
|
|
/**
|
|
* Base class for all native resources, tracks all outstanding resources
|
|
* and provides basic leak checking
|
|
*/
|
|
abstract class NativeResource {
|
|
protected static $crt = null;
|
|
protected static $resources = [];
|
|
protected $native = null;
|
|
|
|
function __construct() {
|
|
if (is_null(self::$crt)) {
|
|
try {
|
|
self::$crt = new CRT();
|
|
} catch (Exception $e) {
|
|
echo 'Exception while loading CRT: ', $e->getMessage(), "\n";
|
|
}
|
|
}
|
|
|
|
self::$resources[spl_object_hash($this)] = 1;
|
|
}
|
|
|
|
protected function acquire($handle) {
|
|
$this->native = $handle;
|
|
}
|
|
|
|
protected function release() {
|
|
$this->native = null;
|
|
}
|
|
|
|
function __destruct() {
|
|
// Should have been destroyed and released by derived resource
|
|
assert($this->native == null);
|
|
unset(self::$resources[spl_object_hash($this)]);
|
|
}
|
|
}
|