File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 < p style ="margin: 0; font-weight: 600; font-size: 12pt; margin-top: 0.15em; "> Черняев Александр</ p >
55 < p style ="margin: 0; font-size: 10pt; margin-top: 0.5em; "> Версия 1.0, издание первое</ p >
66 < p style ="margin: 0; font-size: 10pt; margin-top: 0.3em; "> ISBN 000-0-00000-000-0</ p >
7- < p style ="margin: 0; font-weight: 700; font-size: 12pt; margin-top: 1em; "> Липецк 2025</ p >
7+ < p style ="margin: 0; font-size: 10pt; margin-top: 0.3em; "> Коммит [commit]</ p >
8+ < p style ="margin: 0; font-weight: 700; font-size: 12pt; margin-top: 1em; "> Липецк [year]</ p >
89 </ div >
910</ div >
Original file line number Diff line number Diff line change 22
33namespace Dandy \Book ;
44
5+ use Illuminate \Support \Facades \Date ;
56use Illuminate \Support \Str ;
67use Mpdf \Config \ConfigVariables ;
78use Mpdf \Config \FontVariables ;
@@ -78,7 +79,12 @@ public function withTheme(string $themeHtml): static
7879 */
7980 public function withColophon (string $ html ): static
8081 {
81- $ this ->pdf ->WriteHTML ($ html );
82+ $ this ->pdf ->WriteHTML (
83+ Str::of ($ html )
84+ ->replace ('[commit] ' , self ::getCurrentGitCommitHash ())
85+ ->replace ('[year] ' , Date::now ()->format ('Y ' ))
86+ ->toString ()
87+ );
8288
8389 return $ this ;
8490 }
@@ -227,4 +233,23 @@ protected function addPageBreak(): void
227233 // $this->pdf->AddPage();
228234 $ this ->pdf ->WriteHTML ('<div style="page-break-after: always;"></div> ' );
229235 }
236+
237+ /**
238+ * Attempt to retrieve the current Git commit hash in PHP.
239+ * Note: This method assumes the project is using Git for version control.
240+ *
241+ * @return string|null
242+ */
243+ public static function getCurrentGitCommitHash (): ?string
244+ {
245+ $ gitPath = '.git/ ' ;
246+
247+ if (! file_exists ($ gitPath )) {
248+ return null ;
249+ }
250+
251+ $ head = trim (substr (file_get_contents ($ gitPath .'HEAD ' ), 4 ));
252+
253+ return Str::of (file_get_contents ($ gitPath .$ head ))->trim ()->limit (7 , '' );
254+ }
230255}
You can’t perform that action at this time.
0 commit comments