File tree Expand file tree Collapse file tree 5 files changed +73
-3
lines changed Expand file tree Collapse file tree 5 files changed +73
-3
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ public function register()
5757
5858 $ this ->registerBlade ();
5959
60+ $ this ->registerHelpers ();
61+
6062 if ($ this ->app ->runningInConsole ()) {
6163 $ this ->registerArtisanCommands ();
6264 }
@@ -89,6 +91,20 @@ protected function registerBlade()
8991 Blade::directive ('app_version ' , function () {
9092 return "<?php echo resolve('app.version.manager')->formatted(); ?> " ;
9193 });
94+
95+ Blade::directive ('app_build ' , function () {
96+ return "<?php echo resolve('app.version.manager')->build(); ?> " ;
97+ });
98+ }
99+
100+ /**
101+ * Register package helpers.
102+ *
103+ * @return void
104+ */
105+ protected function registerHelpers ()
106+ {
107+ require __DIR__ . '/helpers.php ' ;
92108 }
93109
94110 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use AvtoDev \AppVersion \Contracts \AppVersionManagerContract ;
4+
5+ if (! function_exists ('app_version ' )) {
6+ /**
7+ * Returns application version.
8+ *
9+ * @return string
10+ */
11+ function app_version ()
12+ {
13+ return resolve (AppVersionManagerContract::class)->formatted ();
14+ }
15+ }
16+
17+ if (! function_exists ('app_build ' )) {
18+ /**
19+ * Returns application build (only) version.
20+ *
21+ * @return string
22+ */
23+ function app_build ()
24+ {
25+ return resolve (AppVersionManagerContract::class)->build ();
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -22,8 +22,7 @@ public function testRendering()
2222
2323 view ()->addNamespace ('stubs ' , __DIR__ . '/stubs/view ' );
2424
25- $ rendered = view ('stubs::app_version ' )->render ();
26-
27- $ this ->assertEquals ("Application version: {$ manager ->formatted ()}" , $ rendered );
25+ $ this ->assertEquals ("Application version: {$ manager ->formatted ()}" , view ('stubs::app_version ' )->render ());
26+ $ this ->assertEquals ("Build version: {$ manager ->build ()}" , view ('stubs::app_build ' )->render ());
2827 }
2928}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace AvtoDev \AppVersion \Tests ;
4+
5+ use AvtoDev \AppVersion \Contracts \AppVersionManagerContract ;
6+
7+ /**
8+ * Class HelpersTest.
9+ */
10+ class HelpersTest extends AbstractTestCase
11+ {
12+ /**
13+ * Test helpers.
14+ *
15+ * @return void
16+ */
17+ public function testHelpers ()
18+ {
19+ /** @var AppVersionManagerContract $manager */
20+ $ manager = $ this ->app ->make (AppVersionManagerContract::class);
21+ $ manager ->setBuild ($ build = 'pre-alpha2 ' );
22+
23+ $ this ->assertEquals ("1.0.0- {$ build }" , app_version ());
24+
25+ $ this ->assertEquals ("{$ build }" , app_build ());
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ Build version: @app_build ()
You can’t perform that action at this time.
0 commit comments