:class)) return; /** @var Transformable $data */ $result[] = $factory; }); return $result; } /** * Invalidate all post detail factory instances * * @since 1.8.0 */ public function invalidateFactoryInstances(): void { BasePostDetailFactory::invalidateInstances(); } /* * PRIVATE METHODS */ /** * @param callable $callbackGetMetaKeys Provide the meta keys to be merged using the detail settings. Returns a * string array. For example: function(BasePostDetailSettings $settings) { * return $settings->getSingleMetaKeys() } * @param array $metaKeys Already-existing meta keys to which the meta keys retrieved from the * settings will be added. * @return array $metaKeys with the meta keys retrieved from the settings added * @since 1.8.0 */ private function addMetaKeys($callbackGetMetaKeys, $metaKeys = []) { $this->walkRegisteredFactories(function($factory) use (&$callbackGetMetaKeys, &$metaKeys) { /** @var BasePostDetailFactory $factory */ $settings = $factory->getSettings(null); if (!$settings || !is_a($settings, BasePostDetailSettings::class)) return; $detailMetaKeys = $callbackGetMetaKeys($settings); if (!$detailMetaKeys) return; $metaKeys = array_merge($metaKeys, $detailMetaKeys); }); return $metaKeys; } /** * Walks registered and available factories and calls the given callback. * * @param callable|null $callback A callback that will be called for each registered detail factory if it is available. * It takes only one parameter $factory, which is a BasePostDetailFactory, and returns * nothing. E.g. function($factory) {} * @param null|PostBot $postBot See {@link BasePostDetailFactory::getRegisteredFactoryInstances()} * @since 1.8.0 */ private function walkRegisteredFactories($callback, $postBot = null): void { if (!$callback) return; foreach(BasePostDetailFactory::getRegisteredFactoryInstances($postBot) as $factory) { if (!$factory->isAvailable()) continue; $callback($factory); } } /** * Get a post settings instance using a post bot * * @param PostBot|null $postBot * @since 1.8.0 * @return SettingsImpl */ private function getPostSettingsImplInstanceFromPostBot($postBot): SettingsImpl { if ($postBot) return $postBot->getSettingsImpl(); return $this->getPostSettingsImplInstance(null); } /** * @param SettingsImpl|array|null $postSettings * @param bool $prepare True if the settings should be prepared. Otherwise, false. * @return SettingsImpl * @since 1.8.0 */ private function getPostSettingsImplInstance($postSettings, $prepare = true): SettingsImpl { // If this is an instance, use it directly. if (is_object($postSettings) && is_a($postSettings, SettingsImpl::class)) { return $postSettings; } // Otherwise, make sure it is an array. if (!$postSettings || !is_array($postSettings)) { $postSettings = []; } // Create an instance return new SettingsImpl($postSettings, Factory::postService()->getSingleMetaKeys(), $prepare); } }