t by which to switch the active processor. * * @return int The change in processor number. */ public function switch_active_processor( $w3tc_offset ) { $new_processor_number = $this->active_processor_number + $w3tc_offset; if ( $new_processor_number <= 0 ) { $new_processor_number = 0; } elseif ( $new_processor_number >= count( $this->processors ) ) { $new_processor_number = count( $this->processors ) - 1; } $offset_made = $new_processor_number - $this->active_processor_number; $this->active_processor_number = $new_processor_number; $this->active_processor = $this->processors[ $new_processor_number ]; return $offset_made; } } /** * Class _CallUnderlying * * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore * phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound * phpcs:disable PEAR.NamingConventions.ValidClassName.StartWithCapital */ class _CallUnderlying { /** * WPDB mixin. * * @var object */ private $wpdb_mixin; /** * Constructor for initializing the _CallUnderlying class. * * @param object $manager Database access mediator. * * @return void */ public function __construct( $manager ) { $this->wpdb_mixin = $manager; } /** * Initializes the WPDB manager. * * @return mixed Result of the initialization process. * * @throws \Exception If initialization fails. */ public function initialize() { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->initialize(); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Flushes the WPDB manager's internal cache or other relevant resources. * * @return mixed Result of the flush operation. * * @throws \Exception If flushing fails. */ public function flush() { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->flush(); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Executes a database query. * * @param string $query SQL query to be executed. * * @return mixed Result of the query execution. * * @throws \Exception If the query fails. */ public function query( $query ) { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->query( $query ); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Escapes data for use in a database query. * * @param mixed $w3tc_data Data to be escaped. * * @return mixed Escaped data. * * @throws \Exception If escaping fails. */ public function _escape( $w3tc_data ) { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->_escape( $w3tc_data ); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Prepares an SQL query for execution. * * @param string $query SQL query to be prepared. * @param array $args Parameters to include in the query. * * @return string Prepared SQL query. * * @throws \Exception If query preparation fails. */ public function prepare( $query, $args ) { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->prepare( $query, ...$args ); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Inserts a row into a database table. * * @param string $table Name of the table. * @param array $w3tc_data Associative array of data to insert. * @param mixed $format Optional. Data format. * * @return mixed Result of the insertion. * * @throws \Exception If insertion fails. */ public function insert( $table, $w3tc_data, $format = null ) { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->insert( $table, $w3tc_data, $format ); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Replaces a row in a database table. * * @param string $table Name of the table. * @param array $w3tc_data Associative array of data to replace. * @param mixed $format Optional. Data format. * * @return mixed Result of the replacement. * * @throws \Exception If replacement fails. */ public function replace( $table, $w3tc_data, $format = null ) { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->replace( $table, $w3tc_data, $format ); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Updates rows in a database table. * * @param string $table Name of the table. * @param array $w3tc_data Associative array of data to update. * @param array $where Associative array of conditions for the update. * @param mixed $format Optional. Data format. * @param mixed $where_format Optional. Format for where clause. * * @return mixed Result of the update. * * @throws \Exception If update fails. */ public function update( $table, $w3tc_data, $where, $format = null, $where_format = null ) { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->update( $table, $w3tc_data, $where, $format, $where_format ); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } /** * Deletes rows from a database table. * * @param string $table Name of the table. * @param array $where Associative array of conditions for deletion. * @param mixed $where_format Optional. Format for where clause. * * @return mixed Result of the deletion. * * @throws \Exception If deletion fails. */ public function delete( $table, $where, $where_format = null ) { $switched = $this->wpdb_mixin->switch_active_processor( 1 ); try { $w3tc_r = $this->wpdb_mixin->delete( $table, $where, $where_format ); $this->wpdb_mixin->switch_active_processor( -$switched ); return $w3tc_r; } catch ( \Exception $e ) { $this->wpdb_mixin->switch_active_processor( -$switched ); throw $e; } } }