Logging_Endpoints_Config::class, ); public function register( Service_Container $container ) { parent::register( $container ); $this->container->add( Connector_Service_Provider::DATA_STORE_CONST, function () { return new Const_Data_Store(); } ); $this->container->add( Connector_Service_Provider::DATA_STORE_OPTS, function () { return new Opts_Data_Store(); } ); $this->container->add( Connector_Service_Provider::DATA_STORE_PLUGIN_OPTS, function () { return new Plugin_Opts_Data_Store(); } ); $this->container->add( Connector_Service_Provider::DATA_STORE_ROUTER, function () use ( $container ) { return new Data_Store_Router( $container->get( Connector_Service_Provider::DATA_STORE_CONST ), $container->get( Connector_Service_Provider::DATA_STORE_OPTS ), $container->get( Connector_Service_Provider::DATA_STORE_PLUGIN_OPTS ) ); } ); $this->container->add( self::LOGGER, function () use ( $container ) { return new Logger( $container->get( Connector_Service_Provider::LOG_DETAILS_MODEL ) ); } ); $this->container->add( self::WP_MAIL_LOGGER, function () use ( $container ) { return new WP_Mail_Logger( $container->get( self::LOGGER ), $container->get( Connector_Service_Provider::EVENT_MODEL ), $container->get( Utils_Service_Provider::SOURCE_PARSER ), $container->get( Utils_Service_Provider::HEADER_PARSER ) ); } ); $this->container->add( self::DEBUG_LOG_MODEL, function () use ( $container ) { return new Debug_Log_Model(); } ); $this->container->add( self::GET_PAGINATED_ITEMS_ENDPOINT, function () use ( $container ) { return new Get_Paginated_Items_Endpoint( $container->get( Connector_Service_Provider::EVENT_MODEL ), $container->get( Utils_Service_Provider::RECIPIENT_PARSER ) ); } ); $this->container->add( self::GET_PAGINATED_DEBUG_LOG_ITEMS_ENDPOINT, function () use ( $container ) { return new Get_Paginated_Debug_Log_Items_Endpoint( $container->get( self::DEBUG_LOG_MODEL ) ); } ); $this->container->add( self::DELETE_DEBUG_LOGS_ENDPOINT, function () use ( $container ) { return new Delete_Debug_Logs_Endpoint( $container->get( self::DEBUG_LOG_MODEL ) ); } ); $this->container->add( self::DELETE_EMAIL_ENDPOINT, function () use ( $container ) { return new Delete_Email_Endpoint( $container->get( Connector_Service_Provider::EVENT_MODEL ) ); } ); $this->container->add( self::DELETE_EVENTS_ENDPOINT, function () use ( $container ) { return new Delete_Events_Endpoint( $container->get( Connector_Service_Provider::EVENT_MODEL ) ); } ); $this->container->add( self::GET_EMAIL_MESSAGE_ENDPOINT, function () use ( $container ) { return new Get_Email_Message_Endpoint( $container->get( Connector_Service_Provider::EVENT_MODEL ) ); } ); $this->container->add( self::SCHEDULING_HANDLER, function () use ( $container ) { return new Handler( $container->get( Connector_Service_Provider::DATA_STORE_ROUTER ), $container->get( Connector_Service_Provider::EVENT_MODEL ), $container->get( Connector_Service_Provider::LOG_DETAILS_MODEL ) ); } ); $this->container->add( self::DB_LOGGING_PROVIDER, function () use ( $container ) { return new DB_Logging_Provider( $container->get( self::DEBUG_LOG_MODEL ) ); } ); $this->container->add( self::DEBUG_LOGGER, function () use ( $container ) { $data = $container->get( Connector_Service_Provider::DATA_STORE_ROUTER ); $log_level = $data->get_plugin_setting( Tools_Config::SETTING_DEBUG_LOG_LEVEL, DB_Logging_Provider::DEBUG ); return new Debug_Logger( $container->get( self::DB_LOGGING_PROVIDER ), $log_level ); } ); $this->container->add( self::LOG_ITEM_ENDPOINT, function () use ( $container ) { return new Log_Item_Endpoint( $container->get( self::DEBUG_LOGGER ) ); } ); $this->container->add( self::VIEW_DEBUG_LOG_ENDPOINT, function () use ( $container ) { $debug_logger = $container->get( self::DEBUG_LOGGER ); $debug_model = $container->get( self::DEBUG_LOG_MODEL ); return new View_Log_Endpoint( $container->get( Connector_Service_Provider::DATA_STORE_ROUTER ), $debug_logger, $debug_model ); } ); $this->container->add( self::DEBUG_LOG_EVENT_HANDLER, function () use ( $container ) { return new Debug_Log_Event_Handler( $container->get( self::DEBUG_LOGGER ), $container->get( Connector_Service_Provider::DATA_STORE_ROUTER ) ); } ); $this->container->add( Utils_Service_Provider::ATTACHMENTS_SAVER, function () use ( $container ) { return new Attachments_Saver( $container->get( Logging_Service_Provider::DEBUG_LOGGER ) ); } ); } public function init( Service_Container $container ) { add_action( 'wp_ajax_' . Get_Paginated_Items_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::GET_PAGINATED_ITEMS_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_' . Get_Paginated_Debug_Log_Items_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::GET_PAGINATED_DEBUG_LOG_ITEMS_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_' . Delete_Debug_Logs_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::DELETE_DEBUG_LOGS_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_' . Delete_Email_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::DELETE_EMAIL_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_' . Delete_Events_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::DELETE_EVENTS_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_' . Get_Email_Message_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::GET_EMAIL_MESSAGE_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_' . Log_Item_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::LOG_ITEM_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_' . View_Log_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::VIEW_DEBUG_LOG_ENDPOINT )->handle(); } ); add_action( 'wp_ajax_nopriv_' . View_Log_Endpoint::ACTION_NAME, function () use ( $container ) { $container->get( self::VIEW_DEBUG_LOG_ENDPOINT )->handle(); } ); add_action( self::RETENTION_ACTION_NAME, function () use ( $container ) { return $container->get( self::SCHEDULING_HANDLER )->run_log_retention(); } ); if ( ! Mail_Handler::is_minimally_configured() ) { add_filter( 'wp_mail', function ( $mail_info ) use ( $container ) { $container->get( self::WP_MAIL_LOGGER )->create_log( $mail_info ); return $mail_info; } ); add_action( 'wp_mail_failed', function ( $wp_error ) use ( $container ) { $container->get( self::WP_MAIL_LOGGER )->handle_failed( $wp_error ); } ); } if ( ! wp_next_scheduled( self::RETENTION_ACTION_NAME ) ) { wp_schedule_event( time(), 'daily', self::RETENTION_ACTION_NAME ); } add_action( 'gravitysmtp_save_plugin_setting', function ( $setting, $value ) use ( $container ) { $container->get( self::DEBUG_LOG_EVENT_HANDLER )->on_setting_update( $setting, $value ); }, 10, 2 ); if ( ! wp_next_scheduled( self::DEBUG_LOG_RETENTION_CRON_HOOK ) ) { wp_schedule_event( time(), 'daily', self::DEBUG_LOG_RETENTION_CRON_HOOK ); } add_action( self::DEBUG_LOG_RETENTION_CRON_HOOK, function () use ( $container ) { $container->get( self::DEBUG_LOG_EVENT_HANDLER )->on_retention_cron(); } ); } }