2 Commits
3 changed files with 37 additions and 15 deletions

No files matched your search

+3 -3
View File
@@ -43,9 +43,9 @@ return [
PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(PostRequestAuthentication::class)), PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(PostRequestAuthentication::class)),
MacAddressAuthentication::class => create(MacAddressAuthentication::class)->constructor(get(Authenticate::class), "mac"), # MacAddressAuthentication::class => create(MacAddressAuthentication::class)->constructor(get(Authenticate::class), "mac"),
LocalMacAddressMiddleware::class => create(LocalMacAddressMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(MacAddressAuthentication::class)), # LocalMacAddressMiddleware::class => create(LocalMacAddressMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(MacAddressAuthentication::class)),
'authentication.method' => null, 'authentication.method' => null,
@@ -68,4 +68,4 @@ return [
]), 401); ]), 401);
}; };
}, },
]; ];
+1 -12
View File
@@ -80,18 +80,7 @@ return [
return uniqid("debug_"); return uniqid("debug_");
} }
$gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR; return \Lean\Git::getLatestCommit(getenv("PROJECT_PATH"));
if ( file_exists($gitdir . "HEAD") ) {
if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) {
$file = explode(": ", $currentBranch)[1];
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
return file_exists($path) ? trim(file_get_contents($path), " \t\n\r") : null;
}
}
return "gitless-project";
}, },
Kash\CacheInvalidator::class => create(Kash\CacheInvalidator::class)->constructor(getenv('CACHE_PATH')."/version.cache", (bool) getenv('DEBUG')), Kash\CacheInvalidator::class => create(Kash\CacheInvalidator::class)->constructor(getenv('CACHE_PATH')."/version.cache", (bool) getenv('DEBUG')),
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Lean;
class Git
{
public static function projectVersion(string $projectPath) : string
{
$gitdir = implode(DIRECTORY_SEPARATOR, [ $projectPath, ".git", "refs", "tags" ]);
if ( file_exists($gitdir) ) {
$tags = array_filter(scandir($gitdir, SCANDIR_SORT_DESCENDING), fn($e) => ! str_starts_with($e, '.'));
}
return array_shift($tags);
}
public static function getLatestCommit(string $projectPath) : string
{
$gitdir = implode(DIRECTORY_SEPARATOR, [ getenv("PROJECT_PATH"), ".git", "" ]);
if ( file_exists($gitdir . "HEAD") ) {
if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) {
$file = explode(": ", $currentBranch)[1];
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
return file_exists($path) ? trim(file_get_contents($path), " \t\n\r") : "";
}
}
return "";
}
}