| | private const ACTION_TAGS = 'tags'; |
| | |
| | - private const GET_REPOSITORY = 'repo'; |
| | - private const GET_ACTION = 'action'; |
| | - private const GET_HASH = 'hash'; |
| | - private const GET_NAME = 'name'; |
| | - |
| | private const REFERENCE_HEAD = 'HEAD'; |
| | private const ROUTE_REPO = 'repo'; |
| | private const EXTENSION_GIT = '.git'; |
| | |
| | private array $repos = []; |
| | private Git $git; |
| | - |
| | - private string $repoName = ''; |
| | - private array $repoData = []; |
| | - private string $action = ''; |
| | - private string $commitHash = ''; |
| | - private string $filePath = ''; |
| | - private string $baseHash = ''; |
| | |
| | public function __construct( string $reposPath, string $orderFile ) { |
 |
| | public function route(): Page { |
| | $this->normalizeQueryString(); |
| | + |
| | $uriParts = $this->parseUriParts(); |
| | $repoName = !empty( $uriParts ) ? array_shift( $uriParts ) : ''; |
 |
| | array $uriParts |
| | ): Page { |
| | - $this->repoData = $this->repos[$repoName]; |
| | - $this->repoName = $repoName; |
| | + $repoData = $this->repos[$repoName]; |
| | |
| | - $this->git->setRepository( $this->repoData['path'] ); |
| | + $this->git->setRepository( $repoData['path'] ); |
| | |
| | - $act = array_shift( $uriParts ); |
| | - $this->action = $act ?: self::ACTION_TREE; |
| | + $act = array_shift( $uriParts ); |
| | + $action = $act ?: self::ACTION_TREE; |
| | |
| | - $this->commitHash = self::REFERENCE_HEAD; |
| | - $this->filePath = ''; |
| | - $this->baseHash = ''; |
| | + $commitHash = self::REFERENCE_HEAD; |
| | + $filePath = ''; |
| | + $baseHash = ''; |
| | |
| | $hasHash = [ |
| | - self::ACTION_TREE, self::ACTION_BLOB, self::ACTION_RAW, |
| | + self::ACTION_TREE, |
| | + self::ACTION_BLOB, |
| | + self::ACTION_RAW, |
| | self::ACTION_COMMITS |
| | ]; |
| | |
| | - if( in_array( $this->action, $hasHash ) ) { |
| | - $hash = array_shift( $uriParts ); |
| | - $this->commitHash = $hash ?: self::REFERENCE_HEAD; |
| | - $this->filePath = implode( '/', $uriParts ); |
| | - } elseif( $this->action === self::ACTION_COMMIT ) { |
| | - $this->commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD; |
| | - } elseif( $this->action === self::ACTION_COMPARE ) { |
| | - $this->commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD; |
| | - $this->baseHash = array_shift( $uriParts ) ?? ''; |
| | + if( in_array( $action, $hasHash ) ) { |
| | + $hash = array_shift( $uriParts ); |
| | + $commitHash = $hash ?: self::REFERENCE_HEAD; |
| | + $filePath = implode( '/', $uriParts ); |
| | + } elseif( $action === self::ACTION_COMMIT ) { |
| | + $commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD; |
| | + } elseif( $action === self::ACTION_COMPARE ) { |
| | + $commitHash = array_shift( $uriParts ) ?? self::REFERENCE_HEAD; |
| | + $baseHash = array_shift( $uriParts ) ?? ''; |
| | } |
| | - |
| | - $this->populateGet(); |
| | |
| | - return $this->createPage(); |
| | + return $this->createPage( |
| | + $action, $repoData, $commitHash, $filePath, $baseHash |
| | + ); |
| | } |
| | |
| | - private function createPage(): Page { |
| | - return match( $this->action ) { |
| | + private function createPage( |
| | + string $action, |
| | + array $repoData, |
| | + string $commitHash, |
| | + string $filePath, |
| | + string $baseHash |
| | + ): Page { |
| | + return match( $action ) { |
| | self::ACTION_TREE, |
| | self::ACTION_BLOB => new FilePage( |
| | - $this->repos, $this->repoData, $this->git, $this->commitHash, |
| | - $this->filePath |
| | + $this->repos, $repoData, $this->git, $commitHash, $filePath |
| | ), |
| | self::ACTION_RAW => new RawPage( |
| | - $this->git, $this->commitHash |
| | + $this->git, $commitHash, $repoData['safe_name'], $filePath |
| | ), |
| | self::ACTION_COMMITS => new CommitsPage( |
| | - $this->repos, $this->repoData, $this->git, $this->commitHash |
| | + $this->repos, $repoData, $this->git, $commitHash |
| | ), |
| | self::ACTION_COMMIT => new DiffPage( |
| | - $this->repos, $this->repoData, $this->git, $this->commitHash |
| | + $this->repos, $repoData, $this->git, $commitHash |
| | ), |
| | self::ACTION_TAGS => new TagsPage( |
| | - $this->repos, $this->repoData, $this->git |
| | + $this->repos, $repoData, $this->git |
| | ), |
| | self::ACTION_COMPARE => new ComparePage( |
| | - $this->repos, $this->repoData, $this->git, $this->commitHash, |
| | - $this->baseHash |
| | + $this->repos, $repoData, $this->git, $commitHash, $baseHash |
| | ), |
| | default => new FilePage( |
| | - $this->repos, $this->repoData, $this->git, self::REFERENCE_HEAD, '' |
| | + $this->repos, $repoData, $this->git, self::REFERENCE_HEAD, '' |
| | ) |
| | }; |
 |
| | |
| | return $uriParts; |
| | - } |
| | - |
| | - private function populateGet(): void { |
| | - $_GET[self::GET_REPOSITORY] = $this->repoName; |
| | - $_GET[self::GET_ACTION] = $this->action; |
| | - $_GET[self::GET_HASH] = $this->commitHash; |
| | - $_GET[self::GET_NAME] = $this->filePath; |
| | } |
| | } |