1 <?php declare(strict_types=1);
3 namespace Cli\Services;
9 public static function search(string $directory = ''): string
11 $directoriesToSearch = $directory ? [$directory] : [
13 static::getCliDirectory(),
16 foreach ($directoriesToSearch as $directory) {
17 if ($directory && static::isProbablyAppDirectory($directory)) {
25 public static function require(string $directory = ''): string
27 $dir = static::search($directory);
30 throw new \Exception('Could not find a valid BookStack installation');
36 protected static function getCliDirectory(): string
38 $scriptDir = dirname(__DIR__);
39 if (str_starts_with($scriptDir, 'phar://')) {
40 $scriptDir = dirname(Phar::running(false));
43 return dirname($scriptDir);
46 protected static function isProbablyAppDirectory(string $directory): bool
48 return file_exists($directory . DIRECTORY_SEPARATOR . 'version')
49 && file_exists($directory . DIRECTORY_SEPARATOR . 'package.json');