-
-
Notifications
You must be signed in to change notification settings - Fork 999
Expand file tree
/
Copy pathPathManifestRepository.php
More file actions
108 lines (91 loc) · 2.55 KB
/
Copy pathPathManifestRepository.php
File metadata and controls
108 lines (91 loc) · 2.55 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Leantime\Core\Sessions;
use Exception;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Filesystem\Filesystem;
class PathManifestRepository
{
/**
* The application implementation.
*
* @var \Illuminate\Contracts\Foundation\Application
*/
protected $app;
/**
* The filesystem instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* The path to the manifest file.
*
* @var string
*/
protected $manifestPath;
/**
* Create a new service repository instance.
*
* @return void
*/
public function __construct(ApplicationContract $app, Filesystem $files)
{
$this->app = $app;
$this->files = $files;
$this->manifestPath = storage_path('framework');
}
/**
* Load the service provider manifest JSON file.
*
* @return array|null
*/
public function loadManifest(string $manifestName)
{
if ($this->files->exists($this->manifestPath.'/'.$manifestName.'.php')) {
$manifest = $this->files->getRequire($this->manifestPath.'/'.$manifestName.'.php');
if ($manifest) {
return array_merge(['when' => []], $manifest[$manifestName]);
}
}
return null;
}
/**
* Determine if the manifest should be compiled.
*
* @param array|null $manifest
* @param array $paths
* @return bool
*/
public function shouldRefresh($manifest, $paths)
{
return is_null($manifest) || $manifest != $paths;
}
/**
* Create a fresh service manifest data structure.
*
* @param string $manifestName
* @return array
*/
protected function freshManifest($manifestName, array $paths)
{
return [$manifestName => $paths];
}
/**
* Write the service manifest file to disk.
*
* @return array
*
* @throws \Exception
*/
public function writeManifest(string $manifestName, array $paths)
{
if (! is_writable($dirname = dirname($this->manifestPath.'/'.$manifestName.'.php'))) {
throw new Exception("The {$dirname} directory must be present and writable.");
}
$manifest = $this->freshManifest($manifestName, $paths);
$this->files->replace(
$this->manifestPath.'/'.$manifestName.'.php', '<?php return '.var_export($manifest, true).';'
);
return array_merge(['when' => []], $manifest[$manifestName]);
}
}