You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
831 B
PHTML
54 lines
831 B
PHTML
5 years ago
|
<?php
|
||
|
|
||
|
|
||
|
namespace Cijber\OpenSSL\C;
|
||
|
|
||
|
|
||
|
use FFI;
|
||
|
use FFI\CData;
|
||
|
|
||
|
class CBackedObject
|
||
|
{
|
||
|
protected CData $cObj;
|
||
|
protected bool $freed = false;
|
||
|
|
||
|
/**
|
||
|
* CBackedObject constructor.
|
||
|
* @param CData $cObj
|
||
|
*/
|
||
|
protected function __construct(CData $cObj)
|
||
|
{
|
||
|
$this->cObj = $cObj;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Mark backing C object as freed
|
||
|
*/
|
||
|
public function freed()
|
||
|
{
|
||
|
$this->freed = true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Free backing C object, object is useless after this operation
|
||
|
*/
|
||
|
public final function free()
|
||
|
{
|
||
|
if ($this->freed) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$this->freeObject();
|
||
|
$this->freed();
|
||
|
}
|
||
|
|
||
|
protected function freeObject()
|
||
|
{
|
||
|
FFI::free($this->cObj);
|
||
|
}
|
||
|
|
||
|
public function __destruct()
|
||
|
{
|
||
|
$this->free();
|
||
|
}
|
||
|
}
|