-
Notifications
You must be signed in to change notification settings - Fork 59
/
Encoder.php
51 lines (41 loc) · 1.12 KB
/
Encoder.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
<?php
namespace SilverStripe\GraphQL\Schema\Storage;
use SilverStripe\Core\Injector\Injectable;
use InvalidArgumentException;
use SilverStripe\Core\Path;
use SilverStripe\GraphQL\Schema\Interfaces\Encoder as EncoderInterface;
class Encoder implements EncoderInterface
{
use Injectable;
private string $includeFile;
/**
* @var object|array
*/
private $scope;
private array $globals = [];
/**
* @param object|array $scope
*/
public function __construct(string $includeFile, $scope, array $globals = [])
{
if (!file_exists($includeFile ?? '')) {
throw new InvalidArgumentException(sprintf(
'File "%s" does not exist',
$includeFile
));
}
$this->includeFile = $includeFile;
$this->scope = $scope;
$this->globals = $globals;
}
public function encode(): string
{
ob_start();
$scope = $this->scope;
$globals = $this->globals;
include($this->includeFile);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}