}; $this->container['redux'] = function ($c) { return new WPML_Redux_Framework_config( $c['plugin-meta'] ); }; $this->container['logRotation'] = function ($c) { return new WPML_LogRotation( $c['plugin-meta'] ); }; $this->container['privacyController'] = function ($c) { return new WPML_PrivacyController($c['plugin-meta']); }; $this->container['mailRendererAjaxHandler'] = function ($c) { return new WPML_MailRenderer_AJAX_Handler($c['mailRenderer']); }; $this->container['mailRenderer'] = function ($c) { return new WPML_MailRenderer( new DefaultMailService() ); }; $this->container->addActionsAndFilters(); add_filter( 'wpml_get_di_container', function() { return $this->container; } ); add_filter( 'wpml_get_di_service', function( $service ) { return $this->getService( $service ); } ); /* * Install the plugin * NOTE: this file gets run each time you *activate* the plugin. * So in WP when you "install" the plugin, all that does it dump its files in the plugin-templates directory * but it does not call any of its code. * So here, the plugin tracks whether or not it has run its install operation, and we ensure it is run only once * on the first activation */ if ( ! $this->container['plugin']->isInstalled() ) { $this->container['plugin']->install(); } else { // Perform any version-upgrade activities prior to activation (e.g. database changes). $this->container['plugin']->upgrade(); } if ( $file ) { // Register the Plugin Activation Hook. register_activation_hook( $file, array( &$this->container['plugin'], 'activate' ) ); // Register the Plugin Deactivation Hook. register_deactivation_hook( $file, array( &$this->container['plugin'], 'deactivate' ) ); } } public function getService( $key ) { if( in_array( $key, $this->container->keys() ) ) { return $this->container[ $key ]; } throw new \Exception("Service '{$key}' is not registered"); } }