| 1 |
<?php |
| 2 |
|
| 3 |
class VP_Util_Reflection |
| 4 |
{ |
| 5 |
|
| 6 |
public static function is_multiselectable($object) |
| 7 |
{ |
| 8 |
if(is_object($object)) |
| 9 |
{ |
| 10 |
if($object instanceof VP_MultiSelectable) |
| 11 |
return true; |
| 12 |
} |
| 13 |
elseif(is_string($object)) |
| 14 |
{ |
| 15 |
$class = self::field_class_from_type($object); |
| 16 |
if(function_exists('class_implements')) |
| 17 |
{ |
| 18 |
if(class_exists($class)) |
| 19 |
{ |
| 20 |
$interfaces = class_implements($class); |
| 21 |
if(isset($interfaces['VP_MultiSelectable'])) |
| 22 |
return true; |
| 23 |
} |
| 24 |
else |
| 25 |
{ |
| 26 |
return false; |
| 27 |
} |
| 28 |
} |
| 29 |
else |
| 30 |
{ |
| 31 |
$dummy = new $class; |
| 32 |
if($dummy instanceof VP_MultiSelectable) |
| 33 |
return true; |
| 34 |
unset($dummy); |
| 35 |
} |
| 36 |
} |
| 37 |
return false; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
public static function field_type_from_class($class) |
| 42 |
{ |
| 43 |
$prefix = apply_filters('vp_field_type_from_class_prefix', array('VP_Control_Field_', 'VP_Option_Control_Field_')); |
| 44 |
return strtolower(str_replace($prefix, '', $class)); |
| 45 |
} |
| 46 |
|
| 47 |
public static function field_class_from_type($type) |
| 48 |
{ |
| 49 |
// default prefix |
| 50 |
$prefix = 'VP_Control_Field_'; |
| 51 |
|
| 52 |
// special case |
| 53 |
if($type === 'impexp') |
| 54 |
$prefix = 'VP_Option_Control_Field_'; |
| 55 |
|
| 56 |
$prefix = apply_filters( 'vp_field_class_from_type_prefix', $prefix, $type ); |
| 57 |
|
| 58 |
$class = $prefix . $type; |
| 59 |
return $class; |
| 60 |
} |
| 61 |
|
| 62 |
} |