public function __construct($args = null)
{
$args = is_array($args) ? $args : func_get_args();
if (count($args) < 2) {
$args = array_merge($args, [null]);
}
list($this->dir, $this->path) = $args;
$this->dir = $this->normalizePath($this->dir);
$this->path = $this->normalizePath($this->path);
$basePath = $this->normalizePath(base_path());
// Windows support: Convert backslash to slash
// Expand paths
if ($this->dir) {
$this->dir = $this->normalizePath(realpath($this->dir));
}
if ($this->path) {
$this->path = $this->normalizePath(realpath($this->path));
}
// If path is given as the second arg
if ($this->dir && File::extension($this->dir) != "") {
list($this->dir, $this->path) = [null, $this->dir];
}
// Default dir to the directory of the path
if ($this->path) {
$this->dir = $this->dir ?: dirname($this->path);
}
// If directory is given w/o path, pick a random manifest.json location
if ($this->dir && !$this->path) {
// Find the first manifest.json in the directory
$paths = find_paths($this->dir . "/manifest*.json");
if (!empty($paths)) {
$this->path = head($paths);
} else {
$this->path = $this->dir . "/manifest-" . md5(uniqid(mt_rand(), true)) . ".json";
}
}
if (!$this->dir && !$this->path) {
throw new Exception("manifest requires output path", 1);
}
$data = [];
try {
if (File::exists($this->path)) {
// \Log::info("Load manifest !");//debug
$data = json_decode(File::get($this->path), true);
}
} catch (Exception $e) {
\Log::error($this->path . " is invalid: " . get_classname($e) . " " . $e->getMessage());
}
$this->data = $data;
}