Blocks
4 years ago
Contracts
5 years ago
Database
3 years ago
Integrations
3 years ago
Libraries
5 years ago
Models
3 years ago
Seeds
4 years ago
Services
3 years ago
Support
3 years ago
config
3 years ago
Activator.php
5 years ago
Attachment.php
4 years ago
Controller.php
5 years ago
Core.php
5 years ago
Deactivator.php
3 years ago
Factory.php
5 years ago
Files.php
5 years ago
Plugin.php
5 years ago
Requirements.php
4 years ago
support.php
4 years ago
Factory.php
129 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PrestoPlayer; |
| 4 | |
| 5 | use PrestoPlayer\Plugin; |
| 6 | use PrestoPlayer\Attachment; |
| 7 | use PrestoPlayer\Controller; |
| 8 | use PrestoPlayer\Support\Block; |
| 9 | use PrestoPlayer\Services\Scripts; |
| 10 | use PrestoPlayer\Services\BunnyCDN; |
| 11 | use PrestoPlayer\Services\Settings; |
| 12 | use PrestoPlayer\Services\AdminNotices; |
| 13 | |
| 14 | class Factory |
| 15 | { |
| 16 | const SHARED = ['shared' => true]; |
| 17 | |
| 18 | public function __construct($instance) |
| 19 | { |
| 20 | $this->instance = $instance; |
| 21 | } |
| 22 | |
| 23 | public function isPro() |
| 24 | { |
| 25 | return Plugin::isPro(); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Retrieves the rules for setting up the plugin. |
| 30 | * |
| 31 | * @since 2.1.0 |
| 32 | * |
| 33 | * @return array |
| 34 | */ |
| 35 | public function getRules() |
| 36 | { |
| 37 | return [ |
| 38 | BunnyCDN::class => self::SHARED, |
| 39 | Visits::class => self::SHARED, |
| 40 | ReusableVideos::class => self::SHARED, |
| 41 | AdminNotices::class => self::SHARED, |
| 42 | |
| 43 | Settings::class => [ |
| 44 | 'constructParams' => [ |
| 45 | $this->isPro(), |
| 46 | ] |
| 47 | ], |
| 48 | |
| 49 | |
| 50 | Attachment::class => [ |
| 51 | 'constructParams' => [ |
| 52 | $this->isPro(), |
| 53 | ] |
| 54 | ], |
| 55 | |
| 56 | // blocks |
| 57 | Block::class => [ |
| 58 | 'constructParams' => [ |
| 59 | $this->isPro(), |
| 60 | $this->getPluginVersion(PRESTO_PLAYER_PLUGIN_FILE) |
| 61 | ] |
| 62 | ], |
| 63 | |
| 64 | // plugin controller |
| 65 | Controller::class => [ |
| 66 | 'constructParams' => [$this->getComponents()] |
| 67 | ], |
| 68 | |
| 69 | Scripts::class => [ |
| 70 | 'shared' => true, |
| 71 | 'constructParams' => [ |
| 72 | $this->isPro(), |
| 73 | $this->getPluginVersion(PRESTO_PLAYER_PLUGIN_FILE) |
| 74 | ] |
| 75 | ] |
| 76 | ]; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Retrieves the plugin version. |
| 81 | * |
| 82 | * @param string $plugin_file The full plugin path. |
| 83 | * |
| 84 | * @return string |
| 85 | */ |
| 86 | protected function getPluginVersion($plugin_file) |
| 87 | { |
| 88 | // Load version from plugin data. |
| 89 | if (!\function_exists('get_plugin_data')) { |
| 90 | require_once \ABSPATH . 'wp-admin/includes/plugin.php'; |
| 91 | } |
| 92 | |
| 93 | return \get_plugin_data($plugin_file, false, false)['Version']; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Retrieves the list of plugin components run during normal operations |
| 98 | * (i.e. not including the Uninstallation component). |
| 99 | */ |
| 100 | public function getComponents() |
| 101 | { |
| 102 | $config = require_once 'config/app.php'; |
| 103 | $components = $config['components']; |
| 104 | $components = array_merge($components, $config['pro_components']); |
| 105 | |
| 106 | return $this->formatComponents($components); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Formats components to use in DICE |
| 111 | * |
| 112 | * @param array $components |
| 113 | * @return array |
| 114 | */ |
| 115 | public function formatComponents($components = []) |
| 116 | { |
| 117 | $formatted = []; |
| 118 | |
| 119 | if (!$components) { |
| 120 | return []; |
| 121 | } |
| 122 | |
| 123 | foreach (array_filter($components) as $component) { |
| 124 | $formatted[] = [$this->instance::INSTANCE => $component]; |
| 125 | } |
| 126 | return $formatted; |
| 127 | } |
| 128 | } |
| 129 |