-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHeader.php
More file actions
71 lines (57 loc) · 1.5 KB
/
Header.php
File metadata and controls
71 lines (57 loc) · 1.5 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
<?php declare(strict_types = 1);
namespace rask\Libload;
use rask\Libload\Parsing\ParseException;
/**
* Class Header
*
* @internal
*/
final class Header
{
/**
* Path to header file.
*/
protected string $file_path;
/**
* Full header file contents.
*/
protected string $header_contents;
/**
* Header constructor.
*/
public function __construct(string $header_file_path)
{
if (\is_file($header_file_path) === false) {
throw new ParseException('Cannot parse header file, not a file');
}
if (\is_readable($header_file_path) === false) {
throw new ParseException('Cannot parse header file, file not readable');
}
$this->file_path = $header_file_path;
$header_file = \file_get_contents($header_file_path);
\assert($header_file !== false); // We don't use false-inducing args when getting file contents above.
$this->header_contents = $header_file;
}
/**
* Get the defined FFI_LIB path.
*/
public function getFfiLib() : ?string
{
\preg_match('/^#define +FFI_LIB +[\'"](.+?)[\'"]\n/', $this->header_contents, $matched);
return $matched[1] ?? null;
}
/**
* Get full text contents of header.
*/
public function getContents() : string
{
return $this->header_contents;
}
/**
* Get the header file path.
*/
public function getPath() : string
{
return $this->file_path;
}
}