56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
namespace DatabaseHelper;
 | 
						|
 | 
						|
use DatabaseHelper\beans\Schema;
 | 
						|
 | 
						|
class Database
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Creates a new TableBlueprint instance for the specified table name.
 | 
						|
     * @param string $tableName The name of the table to create.
 | 
						|
     * @return Table instance supporting method chaining
 | 
						|
     */
 | 
						|
    public static function makeTable(string $tableName): Table {
 | 
						|
        return new Table($tableName);
 | 
						|
    }
 | 
						|
 | 
						|
    public static function makeMigration(Schema $table): Migration {
 | 
						|
        // TODO: Implement makeMigration() method.
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Creates a new QueryBuilder instance for the specified table.
 | 
						|
     * @param Schema $table The table to query on.
 | 
						|
     * @return Query instance supporting method chaining.
 | 
						|
     */
 | 
						|
    public static function makeQuery(Schema $table): Query {
 | 
						|
        return new Query($table);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public static function makeDeletion(Schema $table): Deletion {
 | 
						|
        // TODO: Implement makeDeletion() method.
 | 
						|
    }
 | 
						|
 | 
						|
    public static function makeInsertion(Schema $table): Insertion {
 | 
						|
        return new Insertion($table);
 | 
						|
    }
 | 
						|
 | 
						|
    public static function makeUpdate(Schema $table): Update {
 | 
						|
        return new Update($table);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Adds the WordPress database prefix to table names if not already present.
 | 
						|
     * @param string ...$tableName Array of table names to process
 | 
						|
     * @return void
 | 
						|
     */
 | 
						|
    public static function standardizeTableNames(string &...$tableName): void {
 | 
						|
        global $wpdb;
 | 
						|
        $dbPrefix = $wpdb->prefix;
 | 
						|
 | 
						|
        foreach ($tableName as &$name)
 | 
						|
            if (!str_starts_with($name, $dbPrefix))
 | 
						|
                $name = $dbPrefix . $name;
 | 
						|
    }
 | 
						|
} |