-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asFileName): the function will now return an instance of CatPaw\…
…Cpre\FileName This new class allows you to manage file names located within the file system or within the .phar archive (if one exists).
- Loading branch information
Showing
6 changed files
with
81 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#!/bin/bash | ||
|
||
pushd src/lib/Gui/lib &&\ | ||
go build -o main.so -buildmode=c-shared main.go &&\ | ||
cpp -P ./main.h ./main.static.h &&\ | ||
popd || exit | ||
# pushd src/lib/Gui/lib &&\ | ||
# go build -o main.so -buildmode=c-shared main.go &&\ | ||
# cpp -P ./main.h ./main.static.h &&\ | ||
# popd || exit | ||
|
||
php -dxdebug.mode=debug -dxdebug.start_with_request=yes -dphar.readonly=0 ./bin/start --libraries='./src/lib' --entry='./src/gui-example.php' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?php | ||
use function CatPaw\Core\error; | ||
|
||
use function CatPaw\Core\goffi; | ||
use CatPaw\Gui\Contract; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace CatPaw\Core; | ||
|
||
use Phar; | ||
use Stringable; | ||
|
||
class FileName implements Stringable { | ||
/** | ||
* Create a file name starting from a `$base` directory. | ||
* @param array<string> $base | ||
* @return FileName | ||
*/ | ||
public static function create(array $path):self { | ||
return new self($path); | ||
} | ||
|
||
private bool $checkPhar = false; | ||
|
||
/** | ||
* @param array<string> $path | ||
*/ | ||
private function __construct(private array $path) { | ||
} | ||
|
||
/** | ||
* Given a `$path`, create a file name. | ||
* @param array<string> $path | ||
* @return string | ||
*/ | ||
private static function asFileName(array $path):string { | ||
$parts = []; | ||
$count = count($path); | ||
for ($index = 0; $index < $count; $index++) { | ||
$pathName = $path[$index]; | ||
if ($index < $count - 1 && !str_ends_with($pathName, '/')) { | ||
$pathName = "$pathName/"; | ||
} | ||
$parts[] = $pathName; | ||
} | ||
return join($parts)?:''; | ||
} | ||
|
||
/** | ||
* Lookup the file in in the `.phar` before falling back to the file system. | ||
* @return self | ||
*/ | ||
public function withPhar(): self { | ||
$this->checkPhar = true; | ||
return $this; | ||
} | ||
|
||
public function __toString(): string { | ||
if (isPhar()) { | ||
$phar = Phar::running(); | ||
$localizedFileName = str_replace("$phar/", '', self::asFileName($this->path)); | ||
|
||
if ($this->checkPhar) { | ||
$pharFileName = "$phar/$localizedFileName"; | ||
if (!file_exists($pharFileName)) { | ||
return realpath($localizedFileName); | ||
} | ||
return $pharFileName; | ||
} | ||
return realpath($localizedFileName); | ||
} else { | ||
return realpath(self::asFileName($this->path)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters