-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #762 from mailchimp/Issue759-2.3
closes #759 for magento 2.3
- Loading branch information
Showing
2 changed files
with
69 additions
and
19 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,60 @@ | ||
<?php | ||
/** | ||
* Ebizmarts_MailChimp Magento JS component | ||
* | ||
* @category Ebizmarts | ||
* @package Ebizmarts_MailChimp | ||
* @author Ebizmarts Team <info@ebizmarts.com> | ||
* @copyright Ebizmarts (http://ebizmarts.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
|
||
namespace Ebizmarts\MailChimp\Model\Config; | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
use Magento\Framework\Component\ComponentRegistrarInterface; | ||
use Magento\Framework\Exception\FileSystemException; | ||
use Magento\Framework\Filesystem\Directory\ReadFactory; | ||
|
||
class ModuleVersion | ||
{ | ||
const COMPOSER_FILE_NAME = 'composer.json'; | ||
/** | ||
* @var ComponentRegistrarInterface | ||
*/ | ||
private $componentRegistrar; | ||
/** | ||
* @var ReadFactory | ||
*/ | ||
private $readFactory; | ||
|
||
/** | ||
* ModuleVersion constructor. | ||
* @param ComponentRegistrarInterface $componentRegistrar | ||
* @param ReadFactory $readFactory | ||
*/ | ||
public function __construct(ComponentRegistrarInterface $componentRegistrar, ReadFactory $readFactory) { | ||
$this->componentRegistrar = $componentRegistrar; | ||
$this->readFactory = $readFactory; | ||
} | ||
public function getModuleVersion($moduleName) : string | ||
{ | ||
$emptyVersionNumber = ''; | ||
$composerJsonData = null; | ||
try { | ||
$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); | ||
$directoryRead = $this->readFactory->create($path); | ||
$composerJsonData = $directoryRead->readFile(self::COMPOSER_FILE_NAME); | ||
} catch(\LogicException $pathException) { | ||
return $emptyVersionNumber; | ||
} catch(FileSystemException $fsException) { | ||
return $emptyVersionNumber; | ||
} | ||
$jsonData = json_decode($composerJsonData); | ||
if ($jsonData === null) { | ||
return $emptyVersionNumber; | ||
} | ||
return $jsonData->version ?? $emptyVersionNumber; | ||
} | ||
} | ||
|