signUpGroups( 'org\wplake\advanced_views\Groups', __DIR__ . '/src/Groups' ); } protected function primary(bool $isAdmin): void { $this->groupCreator = new Creator(); $this->viewData = $this->groupCreator->create(ViewData::class); $this->cardData = $this->groupCreator->create(CardData::class); $this->options = new Options(); $this->html = new Html(); $this->cardsDataStorage = new CardsDataStorage($this->cardData); $this->viewsDataStorage = new ViewsDataStorage($this->viewData); $this->settings = new Settings($this->options); $this->plugin = new Plugin($this->options, $this->settings); $this->twig = new Twig($this->settings, $this->plugin); $this->item = $this->groupCreator->create(ItemData::class); $this->dataVendors = new DataVendors(); $this->frontAssets = new FrontAssets($this->plugin, $this->dataVendors); // it's a hack, but there is no other way to pass data (constructor is always called automatically) FieldData::setDataVendors($this->dataVendors); // load right here, as used everywhere $this->settings->load(); $this->plugin->setHooks($isAdmin); $this->twig->setHooks($isAdmin, __FILE__); $this->frontAssets->setHooks($isAdmin); $this->dataVendors->setHooks($isAdmin); $this->viewsDataStorage->setHooks($isAdmin); $this->cardsDataStorage->setHooks($isAdmin); } protected function views(bool $isAdmin): void { $fieldMarkup = new FieldMarkup($this->dataVendors, $this->frontAssets); $this->viewMarkup = new ViewMarkup($this->html, $fieldMarkup, $this->dataVendors); $this->viewFactory = new ViewFactory( $this->frontAssets, $this->viewsDataStorage, $this->viewMarkup, $this->twig, $fieldMarkup, $this->dataVendors ); $acfViewMetaBoxes = new ViewsMetaBoxes($this->html, $this->viewsDataStorage, $this->dataVendors); $this->viewsSaveActions = new ViewsSaveActions( $this->viewsDataStorage, $this->plugin, $this->viewData, $this->frontAssets, $this->viewMarkup, $acfViewMetaBoxes, $this->html, $this->viewFactory ); $this->viewsCpt = new ViewsCpt( $this->viewsDataStorage, $this->viewsSaveActions, $this->html, $acfViewMetaBoxes ); $this->viewShortcode = new ViewShortcode($this->settings, $this->viewsDataStorage, $this->viewFactory); $acfViewMetaBoxes->setHooks($isAdmin); $this->viewsCpt->setHooks($isAdmin); $this->viewsSaveActions->setHooks($isAdmin); $this->viewShortcode->setHooks($isAdmin); } protected function cards(bool $isAdmin): void { $this->queryBuilder = new QueryBuilder($this->dataVendors); $this->cardMarkup = new CardMarkup($this->queryBuilder, $this->frontAssets); $this->cardFactory = new CardFactory( $this->frontAssets, $this->queryBuilder, $this->cardMarkup, $this->twig, $this->cardsDataStorage ); $acfCardsMetaBoxes = new CardsMetaBoxes($this->html, $this->cardsDataStorage, $this->viewsDataStorage); $this->cardsSaveActions = new CardsSaveActions( $this->cardsDataStorage, $this->plugin, $this->cardData, $this->frontAssets, $this->cardMarkup, $this->queryBuilder, $this->html, $acfCardsMetaBoxes, $this->cardFactory ); $this->cardsCpt = new CardsCpt( $this->cardsDataStorage, $this->cardsSaveActions, $this->html, $acfCardsMetaBoxes ); $acfCardsViewIntegration = new CardsViewIntegration( $this->cardsDataStorage, $this->viewsDataStorage, $this->cardsSaveActions ); $this->cardShortcode = new CardShortcode($this->settings, $this->cardsDataStorage, $this->cardFactory); $this->cardsCpt->setHooks($isAdmin); $acfCardsMetaBoxes->setHooks($isAdmin); $this->cardsSaveActions->setHooks($isAdmin); $acfCardsViewIntegration->setHooks($isAdmin); $this->cardShortcode->setHooks($isAdmin); } protected function integration(bool $isAdmin): void { $this->acfDependency = new AcfDependency($this->plugin, $this->viewsCpt, $this->cardsCpt); $this->fieldIntegration = new FieldDataIntegration($this->dataVendors, $this->viewsDataStorage); $cardDataIntegration = new CardDataIntegration($this->dataVendors, $this->viewsDataStorage); $itemIntegration = new ItemDataIntegration($this->dataVendors); $metaFieldIntegration = new MetaFieldDataIntegration($this->dataVendors); $mountPointIntegration = new MountPointDataIntegration(); $taxFieldIntegration = new TaxFieldDataIntegration(); $toolsDataIntegration = new ToolsDataIntegration($this->viewsDataStorage, $this->cardsDataStorage); $this->acfDependency->setHooks($isAdmin); $this->fieldIntegration->setHooks($isAdmin); $cardDataIntegration->setHooks($isAdmin); $itemIntegration->setHooks($isAdmin); $metaFieldIntegration->setHooks($isAdmin); $mountPointIntegration->setHooks($isAdmin); $taxFieldIntegration->setHooks($isAdmin); $toolsDataIntegration->setHooks($isAdmin); // only now, when views() are called $this->dataVendors->makeIntegrationInstances( $isAdmin, $this->item, $this->viewsDataStorage, $this->viewsSaveActions, $this->viewFactory, $this->groupCreator->create(RepeaterFieldData::class), $this->viewShortcode ); } protected function others(bool $isAdmin): void { $demoImport = new DemoImport( $this->cardsSaveActions, $this->viewsSaveActions, $this->cardsDataStorage, $this->viewsDataStorage, $this->settings, $this->item ); $acfIntegration = new AcfIntegration(); $dashboard = new Dashboard($this->plugin, $this->html, $demoImport, $acfIntegration); $acfPro = new AcfPro($this->plugin, $this->viewsCpt, $this->cardsCpt); $upgrades = new Upgrades( $this->plugin, $this->settings, $this->viewsDataStorage, $this->cardsDataStorage, $this->viewsSaveActions, $this->cardsSaveActions, $this->twig ); $activeInstallations = new ActiveInstallations($this->plugin, $this->settings, $this->options); $tools = new Tools( new ToolsData($this->groupCreator), $this->cardsDataStorage, $this->viewsDataStorage, $this->plugin, $this->viewData, $this->cardData ); $settings = new SettingsPage( new SettingsData($this->groupCreator), $this->settings, $this->viewsDataStorage, $this->cardsDataStorage ); $adminAssets = new AdminAssets( $this->plugin, $this->cardsDataStorage, $this->viewsDataStorage, $this->viewFactory, $this->cardFactory, $this->settings ); $dashboard->setHooks($isAdmin); $demoImport->setHooks($isAdmin); $acfPro->setHooks($isAdmin); $upgrades->setHooks($isAdmin); $activeInstallations->setHooks($isAdmin); $tools->setHooks($isAdmin); $adminAssets->setHooks($isAdmin); $settings->setHooks($isAdmin); } protected function bridge(): void { AdvancedViews::$innerViewShortcode = $this->viewShortcode; AdvancedViews::$innerCardShortcode = $this->cardShortcode; } public function init(): void { // skip initialization if PRO already active if (class_exists(Plugin::class)) { return; } require_once __DIR__ . '/prefixed_vendors/vendor/scoper-autoload.php'; $requestUri = $_SERVER['REQUEST_URI'] ?? ''; $isAdmin = is_admin() || false !== strpos($requestUri, '/wp-json/'); $this->acfGroups($isAdmin); $this->primary($isAdmin); $this->views($isAdmin); $this->cards($isAdmin); $this->integration($isAdmin); $this->others($isAdmin); $this->bridge(); } }; $acfViews->init();