Example #1
0
 /**
  * @return DIContainer
  */
 public static function getConfiguredInstance()
 {
     if (self::$instance != null) {
         return self::$instance;
     }
     self::$instance = $dic = new DIContainer();
     $dic->register(VersionPressServices::VP_CONFIGURATION, function () {
         return new VersionPressConfig();
     });
     $dic->register(VersionPressServices::WPDB, function () {
         global $wpdb;
         return $wpdb;
     });
     $dic->register(VersionPressServices::STORAGE_FACTORY, function () use($dic) {
         global $wp_taxonomies;
         return new StorageFactory(VERSIONPRESS_MIRRORING_DIR, $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::WPDB), array_keys((array) $wp_taxonomies));
     });
     $dic->register(VersionPressServices::MIRROR, function () use($dic) {
         return new Mirror($dic->resolve(VersionPressServices::STORAGE_FACTORY), $dic->resolve(VersionPressServices::URL_REPLACER));
     });
     $dic->register(VersionPressServices::DB_SCHEMA, function () {
         global $table_prefix, $wp_db_version;
         return new DbSchemaInfo(VERSIONPRESS_PLUGIN_DIR . '/src/Database/wordpress-schema.neon', $table_prefix, $wp_db_version);
     });
     $dic->register(VersionPressServices::WPDB_MIRROR_BRIDGE, function () use($dic) {
         return new WpdbMirrorBridge($dic->resolve(VersionPressServices::WPDB), $dic->resolve(VersionPressServices::MIRROR), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::VPID_REPOSITORY));
     });
     $dic->register(VersionPressServices::COMMITTER, function () use($dic) {
         return new Committer($dic->resolve(VersionPressServices::MIRROR), $dic->resolve(VersionPressServices::REPOSITORY), $dic->resolve(VersionPressServices::STORAGE_FACTORY));
     });
     $dic->register(VersionPressServices::INITIALIZER, function () use($dic) {
         return new Initializer($dic->resolve(VersionPressServices::WPDB), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::STORAGE_FACTORY), $dic->resolve(VersionPressServices::SYNCHRONIZER_FACTORY), $dic->resolve(VersionPressServices::REPOSITORY), $dic->resolve(VersionPressServices::URL_REPLACER), $dic->resolve(VersionPressServices::VPID_REPOSITORY));
     });
     $dic->register(VersionPressServices::SYNCHRONIZER_FACTORY, function () use($dic) {
         return new SynchronizerFactory($dic->resolve(VersionPressServices::STORAGE_FACTORY), $dic->resolve(VersionPressServices::WPDB), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::URL_REPLACER));
     });
     $dic->register(VersionPressServices::SYNCHRONIZATION_PROCESS, function () use($dic) {
         return new SynchronizationProcess($dic->resolve(VersionPressServices::SYNCHRONIZER_FACTORY));
     });
     $dic->register(VersionPressServices::REVERTER, function () use($dic) {
         return new Reverter($dic->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS), $dic->resolve(VersionPressServices::WPDB), $dic->resolve(VersionPressServices::COMMITTER), $dic->resolve(VersionPressServices::REPOSITORY), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::STORAGE_FACTORY));
     });
     $dic->register(VersionPressServices::REPOSITORY, function () use($dic) {
         /** @var VersionPressConfig $vpConfig */
         $vpConfig = $dic->resolve(VersionPressServices::VP_CONFIGURATION);
         return new GitRepository(ABSPATH, VERSIONPRESS_TEMP_DIR, "[VP] ", $vpConfig->gitBinary);
     });
     $dic->register(VersionPressServices::VPID_REPOSITORY, function () use($dic) {
         return new VpidRepository($dic->resolve(VersionPressServices::WPDB), $dic->resolve(VersionPressServices::DB_SCHEMA));
     });
     $dic->register(VersionPressServices::URL_REPLACER, function () {
         return new AbsoluteUrlReplacer(get_site_url());
     });
     return self::$instance;
 }
 /**
  * @return DIContainer
  */
 public static function getConfiguredInstance()
 {
     if (self::$instance != null) {
         return self::$instance;
     }
     self::$instance = $dic = new DIContainer();
     $dic->register(VersionPressServices::WPDB, function () {
         global $wpdb;
         return $wpdb;
     });
     $dic->register(VersionPressServices::DATABASE, function () use($dic) {
         return new Database($dic->resolve(VersionPressServices::WPDB));
     });
     $dic->register(VersionPressServices::STORAGE_FACTORY, function () use($dic) {
         global $wp_taxonomies;
         return new StorageFactory(VP_VPDB_DIR, $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::DATABASE), array_keys((array) $wp_taxonomies), $dic->resolve(VersionPressServices::CHANGEINFO_FACTORY), $dic->resolve(VersionPressServices::TABLE_SCHEMA_STORAGE));
     });
     $dic->register(VersionPressServices::MIRROR, function () use($dic) {
         return new Mirror($dic->resolve(VersionPressServices::STORAGE_FACTORY), $dic->resolve(VersionPressServices::URL_REPLACER));
     });
     $dic->register(VersionPressServices::DB_SCHEMA, function () {
         global $table_prefix, $wp_db_version;
         return new DbSchemaInfo(new ActivePluginsVPFilesIterator('schema.yml'), $table_prefix, $wp_db_version);
     });
     $dic->register(VersionPressServices::ACTIONS_DEFINITION_REPOSITORY, function () use($dic) {
         return new ActionsDefinitionRepository(VERSIONPRESS_TEMP_DIR . '/actions', $dic->resolve(VersionPressServices::GIT_REPOSITORY));
     });
     $dic->register(VersionPressServices::ACTIONSINFO_PROVIDER_ALL_PLUGINS, function () use($dic) {
         return new ActionsInfoProvider($dic->resolve(VersionPressServices::ACTIONS_DEFINITION_REPOSITORY)->getAllDefinitionFiles());
     });
     $dic->register(VersionPressServices::ACTIONSINFO_PROVIDER_ACTIVE_PLUGINS, function () {
         return new ActionsInfoProvider(new ActivePluginsVPFilesIterator('actions.yml'));
     });
     $dic->register(VersionPressServices::CHANGEINFO_FACTORY, function () use($dic) {
         return new ChangeInfoFactory($dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::ACTIONSINFO_PROVIDER_ACTIVE_PLUGINS));
     });
     $dic->register(VersionPressServices::COMMIT_MESSAGE_PARSER, function () use($dic) {
         return new CommitMessageParser($dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::ACTIONSINFO_PROVIDER_ALL_PLUGINS));
     });
     $dic->register(VersionPressServices::WPDB_MIRROR_BRIDGE, function () use($dic) {
         return new WpdbMirrorBridge($dic->resolve(VersionPressServices::DATABASE), $dic->resolve(VersionPressServices::MIRROR), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::VPID_REPOSITORY), $dic->resolve(VersionPressServices::SHORTCODES_REPLACER));
     });
     $dic->register(VersionPressServices::COMMITTER, function () use($dic) {
         return new Committer($dic->resolve(VersionPressServices::MIRROR), $dic->resolve(VersionPressServices::GIT_REPOSITORY), $dic->resolve(VersionPressServices::STORAGE_FACTORY));
     });
     $dic->register(VersionPressServices::INITIALIZER, function () use($dic) {
         return new Initializer($dic->resolve(VersionPressServices::DATABASE), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::STORAGE_FACTORY), $dic->resolve(VersionPressServices::SYNCHRONIZER_FACTORY), $dic->resolve(VersionPressServices::GIT_REPOSITORY), $dic->resolve(VersionPressServices::URL_REPLACER), $dic->resolve(VersionPressServices::VPID_REPOSITORY), $dic->resolve(VersionPressServices::SHORTCODES_REPLACER), $dic->resolve(VersionPressServices::CHANGEINFO_FACTORY), $dic->resolve(VersionPressServices::ACTIONS_DEFINITION_REPOSITORY));
     });
     $dic->register(VersionPressServices::SYNCHRONIZER_FACTORY, function () use($dic) {
         return new SynchronizerFactory($dic->resolve(VersionPressServices::STORAGE_FACTORY), $dic->resolve(VersionPressServices::DATABASE), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::VPID_REPOSITORY), $dic->resolve(VersionPressServices::URL_REPLACER), $dic->resolve(VersionPressServices::SHORTCODES_REPLACER), $dic->resolve(VersionPressServices::TABLE_SCHEMA_STORAGE));
     });
     $dic->register(VersionPressServices::SYNCHRONIZATION_PROCESS, function () use($dic) {
         return new SynchronizationProcess($dic->resolve(VersionPressServices::SYNCHRONIZER_FACTORY));
     });
     $dic->register(VersionPressServices::REVERTER, function () use($dic) {
         return new Reverter($dic->resolve(VersionPressServices::SYNCHRONIZATION_PROCESS), $dic->resolve(VersionPressServices::DATABASE), $dic->resolve(VersionPressServices::COMMITTER), $dic->resolve(VersionPressServices::GIT_REPOSITORY), $dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::STORAGE_FACTORY), $dic->resolve(VersionPressServices::COMMIT_MESSAGE_PARSER));
     });
     $dic->register(VersionPressServices::GIT_REPOSITORY, function () {
         return new GitRepository(VP_PROJECT_ROOT, VERSIONPRESS_TEMP_DIR, VERSIONPRESS_COMMIT_MESSAGE_PREFIX, VP_GIT_BINARY);
     });
     $dic->register(VersionPressServices::VPID_REPOSITORY, function () use($dic) {
         return new VpidRepository($dic->resolve(VersionPressServices::DATABASE), $dic->resolve(VersionPressServices::DB_SCHEMA));
     });
     $dic->register(VersionPressServices::URL_REPLACER, function () {
         return new AbsoluteUrlReplacer(get_home_url());
     });
     $dic->register(VersionPressServices::SHORTCODES_REPLACER, function () use($dic) {
         return new ShortcodesReplacer($dic->resolve(VersionPressServices::SHORTCODES_INFO), $dic->resolve(VersionPressServices::VPID_REPOSITORY));
     });
     $dic->register(VersionPressServices::SHORTCODES_INFO, function () {
         return new ShortcodesInfo(new ActivePluginsVPFilesIterator('shortcodes.yml'));
     });
     $dic->register(VersionPressServices::SQL_QUERY_PARSER, function () use($dic) {
         return new SqlQueryParser($dic->resolve(VersionPressServices::DB_SCHEMA), $dic->resolve(VersionPressServices::DATABASE));
     });
     $dic->register(VersionPressServices::TABLE_SCHEMA_STORAGE, function () use($dic) {
         return new TableSchemaStorage($dic->resolve(VersionPressServices::DATABASE), VP_VPDB_DIR . '/.schema');
     });
     return self::$instance;
 }