| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 |
* |
| 6 |
* @package WPDataAccess\Data_Dictionary |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WPDataAccess\Data_Dictionary { |
| 10 |
|
| 11 |
/** |
| 12 |
* Class WPDA_List_Columns_Cache |
| 13 |
* |
| 14 |
* This class caches the instances of class {@see WPDA_List_Columns} used during the request to prevent repeating |
| 15 |
* the same query more than once. |
| 16 |
* |
| 17 |
* @author Peter Schulz |
| 18 |
* @since 1.0.0 |
| 19 |
* |
| 20 |
* @see WPDA_List_Columns |
| 21 |
*/ |
| 22 |
class WPDA_List_Columns_Cache { |
| 23 |
|
| 24 |
/** |
| 25 |
* @var array Cached instances of WPDA_List_Columns |
| 26 |
*/ |
| 27 |
protected static $cached_list_columns = array(); |
| 28 |
|
| 29 |
/** |
| 30 |
* Get instance of WPDA_List_Columns for supplied schema and table name |
| 31 |
* |
| 32 |
* Checks if an instance of class {@see WPDA_List_Columns} for the given combination of $schema_name and |
| 33 |
* $table_name is already in cache. If an instance was found, a handle to it is returned. If not, a new |
| 34 |
* instance is created, added to the cache and a handle to it is returned. |
| 35 |
* |
| 36 |
* @param $schema_name Database schema name (= MySQL database) |
| 37 |
* @param $table_name Datable table name |
| 38 |
* |
| 39 |
* @return object Handle to instance of {@see WPDA_List_Columns} for supplied $schema_name and $table_name |
| 40 |
*/ |
| 41 |
public static function get_list_columns( $schema_name, $table_name ) { |
| 42 |
$index = "$schema_name.$table_name"; |
| 43 |
if ( ! isset( self::$cached_list_columns[ $index ] ) ) { |
| 44 |
self::$cached_list_columns[ $index ] = new WPDA_List_Columns( $schema_name, $table_name ); |
| 45 |
} |
| 46 |
|
| 47 |
return self::$cached_list_columns[ $index ]; |
| 48 |
} |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|