Skip to content

Commit 8adae46

Browse files
committed
feature: all new app version tracker
1 parent d692f66 commit 8adae46

7 files changed

Lines changed: 94 additions & 18 deletions

File tree

.phpunit.cache/test-results

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":1,"defects":{"Tests\\Unit\\StringyTest::testStringyOf":5,"Tests\\Unit\\StringyTest::testIsEmpty":5,"Tests\\Unit\\StringyTest::testIsNotEmpty":5,"Tests\\Unit\\StringyTest::testExtractKeywords":5,"Tests\\Unit\\StringyTest::testExtractPhrases":5,"Tests\\Unit\\StringyTest::testWordCount":7,"Tests\\Unit\\StringyTest::testCharacterCount":7,"Tests\\Unit\\StringyTest::testInsert":7,"Tests\\Unit\\StringyTest::testGetHashtags":5,"Tests\\Unit\\StringyTest::testUrls":5,"Tests\\Unit\\StringyTest::testUsernames":5,"Tests\\Unit\\StringyTest::testIpAddressExtraction":7,"Tests\\Unit\\StringyTest::testCalculation":7,"Tests\\Unit\\StringyTest::testGetKeySentence":5,"Tests\\Unit\\StringyTest::testMentions":5,"Tests\\Unit\\StringyTest::testMask":7,"Tests\\Unit\\StringyTest::testAsPostalCode":7,"Tests\\Unit\\StringyTest::testAsPhone":7,"Tests\\Unit\\SupportTest::testStringyOf":8,"Tests\\Unit\\SupportTest::testCloudflarePurge":1,"Tests\\Unit\\SupportTest::testRouteHelper":8,"Tests\\Unit\\SupportTest::testSessionHelper":7,"Tests\\Unit\\SupportTest::testControllerMacros":7},"times":{"Tests\\Unit\\StringyTest::testStringyOf":0.015,"Tests\\Unit\\StringyTest::testIsEmpty":0.007,"Tests\\Unit\\StringyTest::testIsNotEmpty":0.001,"Tests\\Unit\\StringyTest::testExtractKeywords":0.006,"Tests\\Unit\\StringyTest::testExtractPhrases":0.002,"Tests\\Unit\\StringyTest::testWordCount":0,"Tests\\Unit\\StringyTest::testCharacterCount":0,"Tests\\Unit\\StringyTest::testSummary":0,"Tests\\Unit\\StringyTest::testGetKeySentence":0,"Tests\\Unit\\StringyTest::testInsert":0,"Tests\\Unit\\StringyTest::testGetHashtags":0.006,"Tests\\Unit\\StringyTest::testUrls":0,"Tests\\Unit\\StringyTest::testUsernames":0.006,"Tests\\Unit\\StringyTest::testMentions":0,"Tests\\Unit\\StringyTest::testIpAddressExtraction":0,"Tests\\Unit\\StringyTest::testCalculation":0.001,"Tests\\Unit\\StringyTest::testMask":0.002,"Tests\\Unit\\StringyTest::testAsPostalCode":0,"Tests\\Unit\\StringyTest::testAsPhone":0,"Tests\\Unit\\SupportTest::testStringyOf":0.031,"Tests\\Unit\\SupportTest::testCloudflarePurge":0,"Tests\\Unit\\SupportTest::testRouteHelper":0.001,"Tests\\Unit\\SupportTest::testSessionHelper":0.002,"Tests\\Unit\\SupportTest::testControllerMacros":0}}
1+
{"version":2,"defects":{"Tests\\Unit\\StringyTest::testGetHashtags":8,"Tests\\Unit\\StringyTest::testUrls":8,"Tests\\Unit\\StringyTest::testMentions":8,"Tests\\Unit\\SupportTest::testCloudflarePurge":1,"Tests\\Unit\\VersionTest::testVersion":8},"times":{"Tests\\Unit\\StringyTest::testStringyOf":0.016,"Tests\\Unit\\StringyTest::testExtractKeywords":0.005,"Tests\\Unit\\StringyTest::testExtractPhrases":0.002,"Tests\\Unit\\StringyTest::testWordCount":0,"Tests\\Unit\\StringyTest::testCharacterCount":0,"Tests\\Unit\\StringyTest::testSummary":0,"Tests\\Unit\\StringyTest::testGetKeySentence":0,"Tests\\Unit\\StringyTest::testInsert":0,"Tests\\Unit\\StringyTest::testGetHashtags":0,"Tests\\Unit\\StringyTest::testUrls":0,"Tests\\Unit\\StringyTest::testMentions":0,"Tests\\Unit\\StringyTest::testIpAddressExtraction":0,"Tests\\Unit\\StringyTest::testCalculation":0.001,"Tests\\Unit\\StringyTest::testMask":0.002,"Tests\\Unit\\StringyTest::testAsPostalCode":0,"Tests\\Unit\\StringyTest::testAsPhone":0.001,"Tests\\Unit\\SupportTest::testCloudflarePurge":0,"Tests\\Unit\\SupportTest::testRouteHelper":0.001,"Tests\\Unit\\SupportTest::testSessionHelper":0.002,"Tests\\Unit\\SupportTest::testControllerMacros":0,"Tests\\Unit\\VersionTest::testVersion":0.001}}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"illuminate/collections": "^9.0|^10.0|^11.0|^12.0",
1919
"donatello-za/rake-php-plus": "^1.0",
2020
"divineomega/php-summary": "^3.0",
21-
"nojimage/twitter-text-php": "^3.3",
2221
"hallindavid/manny": "^1.02",
2322
"nxp/math-executor": "^2.3"
2423
},
@@ -34,7 +33,8 @@
3433
},
3534
"files": [
3635
"src/GlobalHelpers/RouteHelper.php",
37-
"src/GlobalHelpers/SessionHelper.php"
36+
"src/GlobalHelpers/SessionHelper.php",
37+
"src/GlobalHelpers/VersionHelper.php"
3838
]
3939
},
4040
"autoload-dev": {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
/**
4+
* Get the current application version.
5+
*/
6+
if (! function_exists('app_version')) {
7+
function app_version()
8+
{
9+
return \Grafite\Support\Helpers\Version::release();
10+
}
11+
}

src/Helpers/Stringy.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,29 @@ public function calculate()
6464

6565
public function hashtags()
6666
{
67-
$data = Extractor::create()
68-
->extract(self::$string);
67+
$hashtags = [];
6968

70-
return collect($data['hashtags']);
69+
preg_match_all("/#(\w+)/u", self::$string, $matches);
70+
71+
if (!empty($matches[1])) {
72+
$hashtags = $matches[1];
73+
}
74+
75+
return collect($hashtags);
7176
}
7277

7378
public function urls()
7479
{
75-
$data = Extractor::create()
76-
->extract(self::$string);
80+
preg_match_all('#\bhttps?://[^,\s()<>]+(?:(\([\w\d]+\)|([^,[:punct:]\s]|/)))#', self::$string, $matches);
7781

78-
return collect($data['urls']);
82+
return collect($matches[0]);
7983
}
8084

8185
public function mentions()
8286
{
83-
$data = Extractor::create()
84-
->extract(self::$string);
87+
preg_match_all('/@([a-zA-Z0-9_]+)/', self::$string, $matches);
8588

86-
return collect($data['mentions']);
89+
return collect($matches[1]);
8790
}
8891

8992
public function ipAddresses()

src/Helpers/Version.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Grafite\Support\Helpers;
4+
5+
class Version
6+
{
7+
public static function release()
8+
{
9+
$build = self::build();
10+
11+
try {
12+
if (base_path('changelog.md')) {
13+
$version = preg_match("/## (.*?) -/", file_get_contents(base_path('changelog.md')), $matches) ? str_replace('[', '', str_replace(']', '', $matches[1])) : "";
14+
}
15+
16+
if (base_path('CHANGELOG.md')) {
17+
$version = preg_match("/## (.*?) -/", file_get_contents(base_path('CHANGELOG.md')), $matches) ? str_replace('[', '', str_replace(']', '', $matches[1])) : "";
18+
}
19+
} catch (\Throwable $th) {
20+
$version = '1.0.0';
21+
}
22+
23+
return $version.'-'.$build ?? '1.0.0';
24+
}
25+
26+
public static function build()
27+
{
28+
$iteration = '';
29+
30+
try {
31+
$files = \scandir(base_path('public/build/assets/'));
32+
33+
foreach ($files as $file) {
34+
if ($file !== '.' && $file !== '..') {
35+
$iteration .= $file;
36+
}
37+
}
38+
} catch (\Throwable $th) {
39+
$iteration = '1';
40+
}
41+
42+
$build = hash('crc32', $iteration);
43+
44+
return $build;
45+
}
46+
}

src/SupportProvider.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ public function boot()
3030
});
3131

3232
Blade::directive('version', function () {
33-
if (base_path('changelog.md')) {
34-
return '<?php echo preg_match("/## (.*?) -/", file_get_contents(base_path(\'changelog.md\')), $matches) ? str_replace(\'[\', \'\', str_replace(\']\', \'\', $matches[1])) : ""; ?>';
35-
}
36-
if (base_path('CHANGELOG.md')) {
37-
return '<?php echo preg_match("/## (.*?) -/", file_get_contents(base_path(\'CHANGELOG.md\')), $matches) ? str_replace(\'[\', \'\', str_replace(\']\', \'\', $matches[1])) : ""; ?>';
38-
}
33+
return '<?php echo \Grafite\Support\Helpers\Version::release(); ?>';
3934
});
4035

4136
Blade::directive('docs', function () {

tests/Unit/VersionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use Tests\TestCase;
6+
7+
class VersionTest extends TestCase
8+
{
9+
public function testVersion()
10+
{
11+
$this->assertNotEmpty(app_version());
12+
13+
$this->assertStringContainsString('-', app_version());
14+
15+
$parts = explode('-', app_version());
16+
17+
$this->assertCount(2, $parts);
18+
19+
$this->assertTrue(ctype_xdigit($parts[1]));
20+
}
21+
}

0 commit comments

Comments
 (0)