-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced trait with custom version compare function, that can handl…
…e the Lumen version string.
- Loading branch information
1 parent
c2941a7
commit 3e86538
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: sune | ||
* Date: 21/01/2018 | ||
* Time: 16.11 | ||
*/ | ||
|
||
namespace Prettus\Repository\Traits; | ||
|
||
trait ComparesVersionsTrait | ||
{ | ||
/** | ||
* Version compare function that can compare both Laravel and Lumen versions. | ||
* | ||
* @param string $frameworkVersion | ||
* @param string $compareVersion | ||
* @param string|null $operator | ||
* @return mixed | ||
*/ | ||
public function versionCompare($frameworkVersion, $compareVersion, $operator = null) | ||
{ | ||
// Lumen (5.5.2) (Laravel Components 5.5.*) | ||
$lumenPattern = '/Lumen \((\d\.\d\.[\d|\*])\)( \(Laravel Components (\d\.\d\.[\d|\*])\))?/'; | ||
|
||
if (preg_match($lumenPattern, $frameworkVersion, $matches)) { | ||
$frameworkVersion = isset($matches[3]) ? $matches[3] : $matches[1]; // Prefer Laravel Components version. | ||
} | ||
|
||
return version_compare($frameworkVersion, $compareVersion, $operator); | ||
} | ||
} |