1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carbon_Fields; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Field proxy factory class. |
7
|
|
|
* Used for shorter namespace access when creating a field. |
8
|
|
|
* |
9
|
|
|
* @method static \Carbon_Fields\Field\Association_Field make_association( string $name, string $label = null ) |
10
|
|
|
* @method static \Carbon_Fields\Field\Checkbox_Field make_checkbox( string $name, string $label = null ) |
11
|
|
|
* @method static \Carbon_Fields\Field\Color_Field make_color( string $name, string $label = null ) |
12
|
|
|
* @method static \Carbon_Fields\Field\Complex_Field make_complex( string $name, string $label = null ) |
13
|
|
|
* @method static \Carbon_Fields\Field\Date_Field make_date( string $name, string $label = null ) |
14
|
|
|
* @method static \Carbon_Fields\Field\Date_Time_Field make_date_time( string $name, string $label = null ) |
15
|
|
|
* @method static \Carbon_Fields\Field\File_Field make_file( string $name, string $label = null ) |
16
|
|
|
* @method static \Carbon_Fields\Field\Footer_Scripts_Field make_footer_scripts( string $name, string $label = null ) |
17
|
|
|
* @method static \Carbon_Fields\Field\Gravity_Form_Field make_gravity_form( string $name, string $label = null ) |
18
|
|
|
* @method static \Carbon_Fields\Field\Header_Scripts_Field make_header_scripts( string $name, string $label = null ) |
19
|
|
|
* @method static \Carbon_Fields\Field\Hidden_Field make_hidden( string $name, string $label = null ) |
20
|
|
|
* @method static \Carbon_Fields\Field\Html_Field make_html( string $name, string $label = null ) |
21
|
|
|
* @method static \Carbon_Fields\Field\Image_Field make_image( string $name, string $label = null ) |
22
|
|
|
* @method static \Carbon_Fields\Field\Map_Field make_map( string $name, string $label = null ) |
23
|
|
|
* @method static \Carbon_Fields\Field\Media_Gallery_Field make_media_gallery( string $name, string $label = null ) |
24
|
|
|
* @method static \Carbon_Fields\Field\Multiselect_Field make_multiselect( string $name, string $label = null ) |
25
|
|
|
* @method static \Carbon_Fields\Field\OEmbed_Field make_oembed( string $name, string $label = null ) |
26
|
|
|
* @method static \Carbon_Fields\Field\Radio_Field make_radio( string $name, string $label = null ) |
27
|
|
|
* @method static \Carbon_Fields\Field\Radio_Image_Field make_radio_image( string $name, string $label = null ) |
28
|
|
|
* @method static \Carbon_Fields\Field\Rich_Text_Field make_rich_text( string $name, string $label = null ) |
29
|
|
|
* @method static \Carbon_Fields\Field\Select_Field make_select( string $name, string $label = null ) |
30
|
|
|
* @method static \Carbon_Fields\Field\Separator_Field make_separator( string $name, string $label = null ) |
31
|
|
|
* @method static \Carbon_Fields\Field\Set_Field make_set( string $name, string $label = null ) |
32
|
|
|
* @method static \Carbon_Fields\Field\Sidebar_Field make_sidebar( string $name, string $label = null ) |
33
|
|
|
* @method static \Carbon_Fields\Field\Text_Field make_text( string $name, string $label = null ) |
34
|
|
|
* @method static \Carbon_Fields\Field\Textarea_Field make_textarea( string $name, string $label = null ) |
35
|
|
|
* @method static \Carbon_Fields\Field\Time_Field make_time( string $name, string $label = null ) |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
class Field { |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* A proxy for the abstract field factory method. |
41
|
|
|
* |
42
|
|
|
* @see \Carbon_Fields\Field\Field::factory() |
43
|
|
|
* @return \Carbon_Fields\Field\Field |
44
|
|
|
*/ |
45
|
|
|
public static function factory() { |
46
|
|
|
return call_user_func_array( array( '\Carbon_Fields\Field\Field', 'factory' ), func_get_args() ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* An alias of factory(). |
51
|
|
|
* |
52
|
|
|
* @see \Carbon_Fields\Field\Field::factory() |
53
|
|
|
* @return \Carbon_Fields\Field\Field |
54
|
|
|
*/ |
55
|
|
|
public static function make() { |
56
|
|
|
return call_user_func_array( array( get_class(), 'factory' ), func_get_args() ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $method |
61
|
|
|
* @param array $arguments |
62
|
|
|
* |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
|
|
public static function __callStatic( $method, $arguments ) { |
66
|
|
|
if ( strpos( $method, 'make_' ) === 0 ) { |
67
|
|
|
$raw_type = substr_replace( $method, '', 0, 5 ); |
68
|
|
|
array_unshift( $arguments, $raw_type ); |
69
|
|
|
return call_user_func_array( array( get_class(), 'factory' ), $arguments ); |
70
|
|
|
} else { |
71
|
|
|
trigger_error( sprintf( 'Call to undefined function: %s::%s().', get_class(), $method ), E_USER_ERROR ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.