| 1 |
<?php |
| 2 |
/** |
| 3 |
* The module factory class. |
| 4 |
* |
| 5 |
* @package ThemeIsleSDK |
| 6 |
* @subpackage Loader |
| 7 |
* @copyright Copyright (c) 2017, Marius Cristea |
| 8 |
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License |
| 9 |
* @since 3.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace ThemeisleSDK\Common; |
| 13 |
|
| 14 |
use ThemeisleSDK\Product; |
| 15 |
|
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Class Job_Factory |
| 22 |
* |
| 23 |
* @package ThemeisleSDK\Common |
| 24 |
*/ |
| 25 |
class Module_Factory { |
| 26 |
/** |
| 27 |
* Partners slugs. |
| 28 |
* |
| 29 |
* @var array $SLUGS Partners product slugs. |
| 30 |
*/ |
| 31 |
public static $slugs = [ |
| 32 |
'zermatt' => true, |
| 33 |
'neto' => true, |
| 34 |
'olsen' => true, |
| 35 |
'benson' => true, |
| 36 |
'romero' => true, |
| 37 |
'carmack' => true, |
| 38 |
'puzzle' => true, |
| 39 |
'broadsheet' => true, |
| 40 |
'girlywp' => true, |
| 41 |
'veggie' => true, |
| 42 |
'zeko' => true, |
| 43 |
'maishawp' => true, |
| 44 |
'didi' => true, |
| 45 |
'liber' => true, |
| 46 |
'medicpress-pt' => true, |
| 47 |
'adrenaline-pt' => true, |
| 48 |
'consultpress-pt' => true, |
| 49 |
'legalpress-pt' => true, |
| 50 |
'gympress-pt' => true, |
| 51 |
'readable-pt' => true, |
| 52 |
'bolts-pt' => true, |
| 53 |
]; |
| 54 |
/** |
| 55 |
* Partners domains. |
| 56 |
* |
| 57 |
* @var array $DOMAINS Partners domains. |
| 58 |
*/ |
| 59 |
public static $domains = [ |
| 60 |
'proteusthemes.com', |
| 61 |
'anarieldesign.com', |
| 62 |
'prothemedesign.com', |
| 63 |
'cssigniter.com', |
| 64 |
]; |
| 65 |
/** |
| 66 |
* Map which contains all the modules loaded for each product. |
| 67 |
* |
| 68 |
* @var array Mapping array. |
| 69 |
*/ |
| 70 |
private static $modules_attached = []; |
| 71 |
|
| 72 |
/** |
| 73 |
* Load availabe modules for the selected product. |
| 74 |
* |
| 75 |
* @param Product $product Loaded product. |
| 76 |
* @param array $modules List of modules. |
| 77 |
*/ |
| 78 |
public static function attach( $product, $modules ) { |
| 79 |
|
| 80 |
if ( ! isset( self::$modules_attached[ $product->get_slug() ] ) ) { |
| 81 |
self::$modules_attached[ $product->get_slug() ] = []; |
| 82 |
} |
| 83 |
|
| 84 |
foreach ( $modules as $module ) { |
| 85 |
$class = 'ThemeisleSDK\\Modules\\' . ucwords( $module, '_' ); |
| 86 |
/** |
| 87 |
* Module object. |
| 88 |
* |
| 89 |
* @var Abstract_Module $module_object Module instance. |
| 90 |
*/ |
| 91 |
$module_object = new $class( $product ); |
| 92 |
|
| 93 |
if ( ! $module_object->can_load( $product ) ) { |
| 94 |
continue; |
| 95 |
} |
| 96 |
self::$modules_attached[ $product->get_slug() ][ $module ] = $module_object->load( $product ); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Products/Modules loaded map. |
| 102 |
* |
| 103 |
* @return array Modules map. |
| 104 |
*/ |
| 105 |
public static function get_modules_map() { |
| 106 |
return self::$modules_attached; |
| 107 |
} |
| 108 |
} |
| 109 |
|