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