StorageFactory.php
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace ACA\MetaBox\Editing;
use AC\MetaType;
use ACA\MetaBox\Column;
use ACA\MetaBox\Editing\Storage\CustomTable;
use ACA\MetaBox\Editing\Storage\Field;
use ACA\MetaBox\Editing\Storage\TermField;
use ACA\MetaBox\StorageAware;
use ACP;
final class StorageFactory {
public function create( Column $column, $single = true ): ACP\Editing\Storage {
switch ( $column->get_storage() ) {
case StorageAware::CUSTOM_TABLE:
return $this->create_table_storage( $column );
case StorageAware::META_BOX:
default:
return $this->create_field_storage( $column, $single );
}
}
public function create_table_storage( Column $column ): ACP\Editing\Storage {
return new CustomTable( $column->get_field_setting( 'storage' ), $column->get_storage_table(), $column->get_meta_key() );
}
private function create_field_storage( Column $column, $single ) {
switch ( true ) {
case get_class( $column ) === Column\Taxonomies::class:
case get_class( $column ) === Column\Taxonomy::class:
return new TermField( $column->get_meta_key(), new MetaType( $column->get_meta_type() ), $column->get_field_settings(), $single );
default:
return new Field( $column->get_meta_key(), new MetaType( $column->get_meta_type() ), $column->get_field_settings(), $single );
}
}
}