PluginProbe ʕ •ᴥ•ʔ
Presto Player / trunk
Presto Player vtrunk
4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / inc / Factory.php
presto-player / inc Last commit date
Blocks 1 week ago Contracts 2 years ago Database 1 week ago Integrations 3 weeks ago Libraries 2 months ago Models 1 week ago Seeds 1 week ago Services 1 week ago Support 2 months ago config 1 week ago lib 3 months ago Activator.php 1 week ago Attachment.php 2 months ago Controller.php 2 years ago Core.php 2 years ago Deactivator.php 1 week ago Factory.php 1 week ago Files.php 2 months ago Playlist.php 2 years ago Plugin.php 3 months ago Requirements.php 2 years ago support.php 2 months ago
Factory.php
149 lines
1 <?php
2 /**
3 * DI container factory and rules.
4 *
5 * @package PrestoPlayer
6 */
7
8 namespace PrestoPlayer;
9
10 use PrestoPlayer\Plugin;
11 use PrestoPlayer\Attachment;
12 use PrestoPlayer\Controller;
13 use PrestoPlayer\Support\Block;
14 use PrestoPlayer\Services\Scripts;
15 // Disabled import: PrestoPlayer\Services\BunnyCDN class does not exist.
16 // Reference only: use PrestoPlayer\Services\BunnyCDN.
17 use PrestoPlayer\Services\Settings;
18 use PrestoPlayer\Services\AdminNotices;
19 use PrestoPlayer\Services\Usage;
20
21 /**
22 * Builds the DICE container rules and the plugin component list.
23 */
24 class Factory {
25
26 const SHARED = array( 'shared' => true );
27
28 /**
29 * DICE container instance (provides the INSTANCE marker).
30 *
31 * @var mixed
32 */
33 public $instance;
34
35 /**
36 * Constructor.
37 *
38 * @param mixed $instance DICE container instance.
39 */
40 public function __construct( $instance ) {
41 $this->instance = $instance;
42 }
43
44 /**
45 * Whether the Pro plugin is active.
46 *
47 * @return bool
48 */
49 public function isPro() {
50 return Plugin::isPro();
51 }
52
53 /**
54 * Retrieves the rules for setting up the plugin.
55 *
56 * @since 2.1.0
57 *
58 * @return array
59 */
60 public function getRules() {
61 return array(
62 Visits::class => self::SHARED,
63 ReusableVideos::class => self::SHARED,
64 AdminNotices::class => self::SHARED,
65 Usage::class => self::SHARED,
66
67 Settings::class => array(
68 'constructParams' => array(
69 $this->isPro(),
70 ),
71 ),
72
73 Attachment::class => array(
74 'constructParams' => array(
75 $this->isPro(),
76 ),
77 ),
78
79 // Blocks.
80 Block::class => array(
81 'constructParams' => array(
82 $this->isPro(),
83 $this->getPluginVersion( PRESTO_PLAYER_PLUGIN_FILE ),
84 ),
85 ),
86
87 // Plugin controller.
88 Controller::class => array(
89 'constructParams' => array( $this->getComponents() ),
90 ),
91
92 Scripts::class => array(
93 'shared' => true,
94 'constructParams' => array(
95 $this->isPro(),
96 $this->getPluginVersion( PRESTO_PLAYER_PLUGIN_FILE ),
97 ),
98 ),
99 );
100 }
101
102 /**
103 * Retrieves the plugin version.
104 *
105 * @param string $plugin_file The full plugin path.
106 *
107 * @return string
108 */
109 protected function getPluginVersion( $plugin_file ) {
110 // Load version from plugin data.
111 if ( ! \function_exists( 'get_plugin_data' ) ) {
112 require_once \ABSPATH . 'wp-admin/includes/plugin.php';
113 }
114
115 return \get_plugin_data( $plugin_file, false, false )['Version'];
116 }
117
118 /**
119 * Retrieves the list of plugin components run during normal operations
120 * (i.e. not including the Uninstallation component).
121 */
122 public function getComponents() {
123 $config = require_once 'config/app.php';
124 $components = $config['components'];
125 $components = array_merge( $components, $config['pro_components'] );
126
127 return $this->formatComponents( $components );
128 }
129
130 /**
131 * Formats components to use in DICE.
132 *
133 * @param array $components Component class names.
134 * @return array
135 */
136 public function formatComponents( $components = array() ) {
137 $formatted = array();
138
139 if ( ! $components ) {
140 return array();
141 }
142
143 foreach ( array_filter( $components ) as $component ) {
144 $formatted[] = array( $this->instance::INSTANCE => $component );
145 }
146 return $formatted;
147 }
148 }
149