File tree Expand file tree Collapse file tree 1 file changed +13
-14
lines changed
Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Original file line number Diff line number Diff line change 1010
1111final readonly class GenericBackupNameResolver implements BackupNameResolver
1212{
13+ private const Separator = '--- ' ;
14+
1315 public function generateFilename (CarbonImmutable $ createdAt , string $ id ): string
1416 {
15- return implode ('' , [
17+ return implode (static ::Separator , [
1618 str (config ('app.name ' ))->slug (),
17- '- ' ,
1819 $ createdAt ->timestamp ,
19- '- ' ,
2020 $ id ,
2121 ]);
2222 }
2323
24- public function parseFilename (string $ path ): ResolvedBackupData
24+ public function parseFilename (string $ path ): ? ResolvedBackupData
2525 {
2626 /** @var string */
2727 $ filename = pathinfo ($ path , PATHINFO_FILENAME );
2828
29- $ createdAt = CarbonImmutable::createFromTimestamp ((string ) str ($ filename )
30- ->beforeLast ('- ' )
31- ->afterLast ('- ' ));
29+ $ parts = explode (static ::Separator, $ filename );
3230
33- $ id = (string ) str ($ filename )
34- ->afterLast ('- ' )
35- ->before ('.zip ' );
31+ if (count ($ parts ) !== 3 )
32+ return null ;
3633
37- $ name = (string ) str ($ filename )
38- ->remove ('- ' . $ createdAt ->timestamp )
39- ->before ('.zip ' );
34+ [$ name , $ createdAt , $ id ] = $ parts ;
4035
41- return new ResolvedBackupData (createdAt: $ createdAt , id: $ id , name: $ name );
36+ return new ResolvedBackupData (
37+ createdAt: CarbonImmutable::createFromTimestamp ($ createdAt ),
38+ id: $ id ,
39+ name: $ name ,
40+ );
4241 }
4342}
You can’t perform that action at this time.
0 commit comments