# depicter/1.5.2/app/src/Database/DatabaseServiceProvider.php

Depicter — Popup &amp; Slider Builder, version 1.5.2. 79 lines.

- Page: https://pluginprobe.com/plugins/depicter/1.5.2/code/app/src/Database/DatabaseServiceProvider.php
- Raw: https://pluginprobe.com/plugins/depicter/1.5.2/raw/app/src/Database/DatabaseServiceProvider.php
- Modified: 2022-11-01T06:06:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/depicter/1.5.2/code/app/src/Database/DatabaseServiceProvider.php#L10-L20`.

```php
<?php

namespace Depicter\Database;

use Depicter\Database\Repository\DocumentRepository;
use WPEmerge\ServiceProviders\ServiceProviderInterface;

/**
 * Load document data manager.
 */
class DatabaseServiceProvider implements ServiceProviderInterface {

	/**
	 * {@inheritDoc}
	 */
	/**
	 * {@inheritDoc}
	 */
	public function register( $container ) {
		$container[ 'depicter.database.migration' ] = function () {
			return new Migration();
		};

		$container[ 'depicter.database.repository.document' ] = function () {
			return new DocumentRepository();
		};

		$app = $container[ WPEMERGE_APPLICATION_KEY ];
		$app->alias( 'documentRepository', 'depicter.database.repository.document' );
	}

	/**
	 * {@inheritDoc}
	 */
	public function bootstrap( $container ) {
		register_activation_hook( DEPICTER_PLUGIN_FILE, [ $this, 'activate' ] );
		add_action( 'wp_insert_site', [ $this, 'activateSingle' ] );
	}

	/**
	 * Plugin activation.
	 *
	 * @return void
	 */
	public function activate( $network_wide ) {
		if ( $network_wide ) {
			$sites = get_sites();
			foreach( $sites as $site ) {
				$this->activateSingle( $site );
			}
		} else {
			$this->migrate();
		}
	}

	/**
	 * Plugin activation on a site
	 *
	 * @param \WP_Site $site
	 *
	 * @return void
	 */
	public function activateSingle( $site ) {
		switch_to_blog( $site->blog_id );
        $this->migrate();
		restore_current_blog();
	}

	/**
	 * Create or update plugin tables
	 *
	 * @return void
	 */
	public function migrate() {
		\Depicter::resolve( 'depicter.database.migration' )->migrate(true);
	}

}

```
