forked from cardgate/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.php
36 lines (31 loc) · 1.39 KB
/
registration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Cardgate\Payment;
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Cardgate_Payment',
__DIR__
);
/**
* Dynamic payment method class loader.
*/
class Registration {
public static function autoload( $sClassName ) {
$sClassPrefix = 'Cardgate\Payment\Model\PaymentMethod';
if ( FALSE !== strstr( $sClassName, $sClassPrefix ) ) {
$sPM = substr( $sClassName, strlen( $sClassPrefix ) + 1 );
$oFileSystem = \Magento\Framework\App\ObjectManager::getInstance()->get( \Magento\Framework\Filesystem::class );
$oDirectory = $oFileSystem->getDirectoryWrite( \Magento\Framework\App\Filesystem\DirectoryList::TMP );
$sVersion = \Magento\Framework\App\ObjectManager::getInstance()->get( \Magento\Framework\Module\ModuleListInterface::class )->getOne( 'Cardgate_Payment' )['setup_version'];
$sFilename = "paymentmethod_cardgate_{$sVersion}_{$sPM}.php";
if ( ! $oDirectory->isFile( $sFilename ) ) {
$oDirectory->writeFile( $sFilename, "<?php\nnamespace Cardgate\\Payment\\Model\\PaymentMethod;\nclass {$sPM} extends \\Cardgate\\Payment\\Model\\PaymentMethod\\nonexistent {\n}\n" );
}
require $oDirectory->getAbsolutePath( $sFilename );
}
}
}
spl_autoload_register( [ '\Cardgate\Payment\Registration', 'autoload' ] );