PluginProbe ʕ •ᴥ•ʔ
Search Regex / trunk
Search Regex vtrunk
trunk 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 2.0 2.0.1 2.1 2.2 2.2.1 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1 3.1.1 3.1.2 3.2 3.3 3.3.0 3.3.1 3.4 3.4.1 3.4.2
search-regex / includes / context / class-value-type.php
search-regex / includes / context Last commit date
type 5 months ago class-context.php 5 months ago class-value-type.php 6 months ago
class-value-type.php
36 lines
1 <?php
2
3 namespace SearchRegex\Context;
4
5 /**
6 * Represents the type of a particular value
7 */
8 class Value_Type {
9 const VALUE_TEXT = 'text';
10 const VALUE_PHP = 'php';
11 const VALUE_JSON = 'json';
12 const VALUE_BLOCKS = 'blocks';
13 const VALUE_HTML = 'html';
14
15 /**
16 * Get the type for the value
17 *
18 * @param string $value Value.
19 * @return string
20 */
21 public static function get( $value ) {
22 // Detect type
23 if ( is_serialized( $value ) ) {
24 return self::VALUE_PHP;
25 } elseif ( preg_match( '/^[\[\|\{]/', $value ) > 0 ) {
26 return self::VALUE_JSON;
27 } elseif ( strpos( $value, '<!-- wp:' ) !== false ) {
28 return self::VALUE_BLOCKS;
29 } elseif ( preg_match( '@</.*?>@', $value ) > 0 ) {
30 return self::VALUE_HTML;
31 }
32
33 return self::VALUE_TEXT;
34 }
35 }
36