Debian Codegraph @

lib/3rdParty/composer/aws/aws-crt-php/src/AWS/CRT/NativeResource.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 * SPDX-License-Identifier: Apache-2.0.
5 */
6 namespace AWS\CRT;
7
8 use AWS\CRT\CRT as CRT;
9
10 /**
11 * Base class for all native resources, tracks all outstanding resources
12 * and provides basic leak checking
13 */
14 abstract class NativeResource {
15 protected static $crt = null;
16 protected static $resources = [];
17 protected $native = null;
18
19 protected function __construct() {
20 if (is_null(self::$crt)) {
21 self::$crt = new CRT();
22 }
23
24 self::$resources[spl_object_hash($this)] = 1;
25 }
26
27 protected function acquire($handle) {
28 return $this->native = $handle;
29 }
30
31 protected function release() {
32 $native = $this->native;
33 $this->native = null;
34 return $native;
35 }
36
37 function __destruct() {
38 // Should have been destroyed and released by derived resource
39 assert($this->native == null);
40 unset(self::$resources[spl_object_hash($this)]);
41 }
42 }