Acf
3 months ago
Admin
3 months ago
Ajax
3 months ago
ApplyFilter
3 months ago
Asset
3 months ago
Capabilities
3 months ago
Check
3 months ago
Collection
3 months ago
Column
3 months ago
ColumnFactories
3 months ago
ColumnFactory
3 months ago
ColumnIterator
3 months ago
ColumnRepository
3 months ago
ColumnSize
3 months ago
DI
3 months ago
Deprecated
3 months ago
Entity
3 months ago
Exception
3 months ago
Expression
3 months ago
Form
3 months ago
Formatter
3 months ago
Helper
3 months ago
Integration
3 months ago
ListScreenRepository
3 months ago
ListTable
3 months ago
Message
3 months ago
Meta
3 months ago
Nonce
3 months ago
Notice
3 months ago
Plugin
3 months ago
Preferences
3 months ago
Promo
3 months ago
Request
3 months ago
RequestHandler
3 months ago
Response
3 months ago
Sanitize
3 months ago
Service
3 months ago
Setting
3 months ago
Settings
3 months ago
Storage
3 months ago
Table
3 months ago
TableIdsFactory
3 months ago
TableScreen
3 months ago
TableScreenFactory
3 months ago
ThirdParty
3 months ago
Type
3 months ago
Value
3 months ago
View
3 months ago
AdminColumns.php
3 months ago
ArrayIterator.php
3 months ago
Capabilities.php
3 months ago
Collection.php
3 months ago
CollectionFormatter.php
3 months ago
Column.php
3 months ago
ColumnCollection.php
3 months ago
ColumnFactoryCollectionFactory.php
3 months ago
ColumnFactoryDefinitionCollection.php
3 months ago
ColumnGroups.php
3 months ago
ColumnIterator.php
3 months ago
ColumnNamesTrait.php
3 months ago
ColumnRepository.php
3 months ago
ColumnTypeRepository.php
3 months ago
Config.php
3 months ago
Container.php
3 months ago
DateFormats.php
3 months ago
Expirable.php
3 months ago
Formatter.php
3 months ago
FormatterCollection.php
3 months ago
Helper.php
3 months ago
ListScreen.php
3 months ago
ListScreenCollection.php
3 months ago
ListScreenRepository.php
3 months ago
ListScreenRepositoryWritable.php
3 months ago
ListTable.php
3 months ago
ListTableFactory.php
3 months ago
Loader.php
3 months ago
Message.php
3 months ago
MetaType.php
3 months ago
Middleware.php
3 months ago
OpCacheInvalidateTrait.php
3 months ago
PluginActionLinks.php
3 months ago
PluginActionUpgrade.php
3 months ago
PostType.php
3 months ago
PostTypeRepository.php
3 months ago
Registerable.php
3 months ago
Registry.php
3 months ago
Renderable.php
3 months ago
Request.php
3 months ago
RequestAjaxHandler.php
3 months ago
RequestAjaxHandlers.php
3 months ago
RequestAjaxParser.php
3 months ago
RequestHandler.php
3 months ago
RequestHandlerFactory.php
3 months ago
Screen.php
3 months ago
Services.php
3 months ago
TableIdsFactory.php
3 months ago
TableScreen.php
3 months ago
TableScreenFactory.php
3 months ago
Taxonomy.php
3 months ago
Transient.php
3 months ago
TypedArrayIterator.php
3 months ago
View.php
3 months ago
WpListTableFactory.php
3 months ago
Loader.php
248 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\Admin\MenuGroupFactory; |
| 9 | use AC\Admin\MenuGroupFactory\DefaultGroups; |
| 10 | use AC\Admin\PageFactory; |
| 11 | use AC\Admin\PageRequestHandler; |
| 12 | use AC\Admin\PageRequestHandlers; |
| 13 | use AC\ListScreenRepository\Storage; |
| 14 | use AC\Plugin\SetupFactory; |
| 15 | use AC\RequestHandler\Ajax; |
| 16 | use AC\Service\View; |
| 17 | use AC\Table\ManageHeading; |
| 18 | use AC\Table\ManageValue\ListScreenServiceFactory; |
| 19 | use AC\Table\SaveHeading; |
| 20 | use AC\Value\Extended\MediaPreview; |
| 21 | use AC\Value\Extended\Posts; |
| 22 | use AC\Value\ExtendedValueRegistry; |
| 23 | |
| 24 | class Loader |
| 25 | { |
| 26 | |
| 27 | private bool $is_pro_active; |
| 28 | |
| 29 | public function __construct(AC\DI\Container $container, bool $is_pro_active = false) |
| 30 | { |
| 31 | $this->is_pro_active = $is_pro_active; |
| 32 | |
| 33 | Container::set_container($container); |
| 34 | |
| 35 | $this->load($container); |
| 36 | } |
| 37 | |
| 38 | protected function load(AC\DI\Container $container): void |
| 39 | { |
| 40 | $this->register_factories($container); |
| 41 | $this->register_page_handlers($container); |
| 42 | $this->register_services($container); |
| 43 | |
| 44 | // Setup Registry for API |
| 45 | Registry::set(Storage::class, static function () use ($container) { |
| 46 | return $container->get(Storage::class); |
| 47 | }); |
| 48 | |
| 49 | $plugin = $container->get(AdminColumns::class); |
| 50 | |
| 51 | /** |
| 52 | * @param AC\DI\Container $container A PSR-11 dependency injection container. |
| 53 | * @param AdminColumns $plugin The plugin instance. |
| 54 | */ |
| 55 | do_action('ac/init', $container, $plugin); |
| 56 | } |
| 57 | |
| 58 | private function register_factories(AC\DI\Container $container): void |
| 59 | { |
| 60 | foreach ($this->get_table_screen_factory_classes() as $class) { |
| 61 | TableScreenFactory\Aggregate::add($container->get($class)); |
| 62 | } |
| 63 | |
| 64 | foreach ($this->get_column_factory_classes() as $class) { |
| 65 | ColumnFactories\Aggregate::add($container->get($class)); |
| 66 | } |
| 67 | |
| 68 | ExtendedValueRegistry::add($container->get(MediaPreview::class)); |
| 69 | ExtendedValueRegistry::add($container->get(Posts::class)); |
| 70 | |
| 71 | MenuGroupFactory\Aggregate::add($container->get(DefaultGroups::class)); |
| 72 | |
| 73 | foreach ($this->get_menu_group_factory_classes() as $class) { |
| 74 | MenuGroupFactory\Aggregate::add(new $class(), 5); |
| 75 | } |
| 76 | TableIdsFactory\Aggregate::add($container->get(TableIdsFactory\BaseFactory::class)); |
| 77 | TableScreen\TableRowsFactory\Aggregate::add(new TableScreen\TableRowsFactory\BaseFactory()); |
| 78 | |
| 79 | foreach ($this->get_manage_value_factory_classes() as $class) { |
| 80 | Service\ManageValue::add( |
| 81 | $container->make(ListScreenServiceFactory::class, ['factory' => $container->get($class)]) |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | Service\ManageHeadings::add($container->get(ManageHeading\WpListTableFactory::class)); |
| 86 | Service\SaveHeadings::add($container->get(SaveHeading\WpListTableFactory::class)); |
| 87 | } |
| 88 | |
| 89 | private function get_table_screen_factory_classes(): array |
| 90 | { |
| 91 | return [ |
| 92 | TableScreenFactory\CommentFactory::class, |
| 93 | TableScreenFactory\MediaFactory::class, |
| 94 | TableScreenFactory\PostFactory::class, |
| 95 | TableScreenFactory\UserFactory::class, |
| 96 | ]; |
| 97 | } |
| 98 | |
| 99 | private function get_column_factory_classes(): array |
| 100 | { |
| 101 | $classes = [ |
| 102 | ColumnFactories\OriginalFactory::class, |
| 103 | ColumnFactories\PostFactory::class, |
| 104 | ColumnFactories\CommentFactory::class, |
| 105 | ColumnFactories\MediaFactory::class, |
| 106 | ColumnFactories\UserFactory::class, |
| 107 | ]; |
| 108 | |
| 109 | if ( ! $this->is_pro_active) { |
| 110 | $classes[] = ColumnFactories\ThirdPartyFactory::class; |
| 111 | $classes[] = ColumnFactories\IntegrationFactory::class; |
| 112 | } |
| 113 | |
| 114 | return $classes; |
| 115 | } |
| 116 | |
| 117 | private function get_manage_value_factory_classes(): array |
| 118 | { |
| 119 | return [ |
| 120 | TableScreen\ManageValue\PostServiceFactory::class, |
| 121 | TableScreen\ManageValue\UserServiceFactory::class, |
| 122 | TableScreen\ManageValue\MediaServiceFactory::class, |
| 123 | TableScreen\ManageValue\CommentServiceFactory::class, |
| 124 | ]; |
| 125 | } |
| 126 | |
| 127 | private function get_menu_group_factory_classes(): array |
| 128 | { |
| 129 | return [ |
| 130 | MenuGroupFactory\WooCommerceGroups::class, |
| 131 | MenuGroupFactory\BuddyPressGroups::class, |
| 132 | MenuGroupFactory\EventsCalendarGroups::class, |
| 133 | MenuGroupFactory\GravityFormsGroups::class, |
| 134 | MenuGroupFactory\JetEngineGroups::class, |
| 135 | MenuGroupFactory\MediaLibraryAssistantGroups::class, |
| 136 | MenuGroupFactory\MetaBoxGroups::class, |
| 137 | MenuGroupFactory\BeaverBuilderGroups::class, |
| 138 | ]; |
| 139 | } |
| 140 | |
| 141 | private function register_page_handlers(AC\DI\Container $container): void |
| 142 | { |
| 143 | $page_handler = new PageRequestHandler(); |
| 144 | $page_handler |
| 145 | ->add('columns', $container->get(PageFactory\Columns::class)) |
| 146 | ->add('settings', $container->get(PageFactory\Settings::class)) |
| 147 | ->add('addons', $container->get(PageFactory\Addons::class)) |
| 148 | ->add('help', $container->get(PageFactory\Help::class)); |
| 149 | |
| 150 | PageRequestHandlers::add_handler($page_handler); |
| 151 | } |
| 152 | |
| 153 | private function get_ajax_handler_classes(): array |
| 154 | { |
| 155 | return [ |
| 156 | 'ac-list-screen-settings' => Ajax\ListScreenSettings::class, |
| 157 | 'ac-list-screen-save' => Ajax\ListScreenSave::class, |
| 158 | 'ac-list-screen-add-column' => Ajax\ListScreenAddColumn::class, |
| 159 | 'ac-number-format' => Ajax\NumberFormat::class, |
| 160 | 'ac-list-screen-default-columns' => Ajax\ListScreenOriginalColumns::class, |
| 161 | 'ac-list-screen-select-column' => Ajax\ListScreenSelectColumn::class, |
| 162 | 'ac-editor-menu-status' => Ajax\EditorMenuStatus::class, |
| 163 | 'ac-editor-menu-favorites' => Ajax\EditorMenuFavorites::class, |
| 164 | 'ac-custom-field-keys' => Ajax\CustomFieldKeys::class, |
| 165 | 'ac-get-network-post-statuses' => Ajax\NetworkPostStati::class, |
| 166 | 'ac-admin-screen-options' => Ajax\ScreenOptions::class, |
| 167 | 'ac-extended-value' => Ajax\ExtendedValue::class, |
| 168 | 'ac-persist-admin-general-option' => Ajax\AdminGeneralOptionsPersist::class, |
| 169 | 'ac-get-admin-general-option' => Ajax\AdminGeneralOptionsGet::class, |
| 170 | 'ac-restore-settings' => Ajax\RestoreSettingsRequest::class, |
| 171 | 'ac-integration-toggle' => Ajax\IntegrationToggle::class, |
| 172 | 'ac-integrations' => Ajax\Integrations::class, |
| 173 | 'ac-list-screen-delete' => Ajax\ListScreenDelete::class, |
| 174 | 'ac-acf-add-column' => AC\Acf\RequestHandler\FieldSettingsAddColumn::class, |
| 175 | ]; |
| 176 | } |
| 177 | |
| 178 | private function get_service_classes(): array |
| 179 | { |
| 180 | $classes = [ |
| 181 | PluginActionLinks::class, |
| 182 | Screen::class, |
| 183 | Admin\Admin::class, |
| 184 | Admin\Scripts::class, |
| 185 | Admin\Notice\DatabaseMissing::class, |
| 186 | ThirdParty\AdvancedCustomFields::class, |
| 187 | ThirdParty\NinjaForms::class, |
| 188 | ThirdParty\MediaLibraryAssistant\MediaLibraryAssistant::class, |
| 189 | ThirdParty\WooCommerce::class, |
| 190 | ThirdParty\WPML::class, |
| 191 | Capabilities\Manage::class, |
| 192 | Service\QuickEdit::class, |
| 193 | Service\CurrentTable::class, |
| 194 | Service\CommonAssets::class, |
| 195 | Service\Colors::class, |
| 196 | Service\TableRows::class, |
| 197 | Service\ManageValue::class, |
| 198 | Service\ManageHeadings::class, |
| 199 | Service\SaveHeadings::class, |
| 200 | Service\AdminBarEditColumns::class, |
| 201 | Service\PluginUpdate::class, |
| 202 | Service\Tooltips::class, |
| 203 | AC\Acf\Service\DateSaveFormat::class, |
| 204 | ]; |
| 205 | |
| 206 | if ( ! $this->is_pro_active) { |
| 207 | $classes[] = Service\PromoChecks::class; |
| 208 | $classes[] = Service\NoticeChecks::class; |
| 209 | $classes[] = PluginActionUpgrade::class; |
| 210 | $classes[] = AC\Acf\Service\FieldSettings::class; |
| 211 | } |
| 212 | |
| 213 | return $classes; |
| 214 | } |
| 215 | |
| 216 | private function register_services(AC\DI\Container $container): void |
| 217 | { |
| 218 | $services = []; |
| 219 | |
| 220 | foreach ($this->get_service_classes() as $class) { |
| 221 | $services[] = $container->get($class); |
| 222 | } |
| 223 | |
| 224 | $plugin = $container->get(AdminColumns::class); |
| 225 | $setup_factory = $container->get(SetupFactory\AdminColumns::class); |
| 226 | |
| 227 | $services[] = new View($plugin->get_location()); |
| 228 | $services[] = new Service\Setup($setup_factory->create(SetupFactory::SITE)); |
| 229 | |
| 230 | if ($plugin->is_network_active()) { |
| 231 | $services[] = new Service\Setup($setup_factory->create(SetupFactory::NETWORK)); |
| 232 | } |
| 233 | |
| 234 | $request_ajax_handlers = new RequestAjaxHandlers(); |
| 235 | |
| 236 | foreach ($this->get_ajax_handler_classes() as $key => $class) { |
| 237 | $request_ajax_handlers->add($key, $container->get($class)); |
| 238 | } |
| 239 | |
| 240 | $services[] = new RequestAjaxParser($request_ajax_handlers); |
| 241 | |
| 242 | foreach ($services as $service) { |
| 243 | $service->register(); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | } |
| 248 |