This function is case sensitive by default.
public static any_match ( string $value, array $patterns ) : boolean | ||
$value | string | A string value to check against, potentially with parameters (E.g. 'Varchar(1023)') |
$patterns | array | A list of strings, some of which may be regular expressions |
Résultat | boolean | True if this $value is present in any of the $patterns |
/** * Determines the fields to translate on the given class * * @return array List of field names and data types */ public static function translated_fields_for($class) { if (isset(self::$translated_fields_for_cache[$class])) { return self::$translated_fields_for_cache[$class]; } return self::$translated_fields_for_cache[$class] = self::without_fluent_fields(function () use($class) { $db = DataObject::custom_database_fields($class); $filter = Config::inst()->get($class, 'translate', Config::UNINHERITED); if ($filter === 'none') { return array(); } // Data and field filters $fieldsInclude = Fluent::config()->field_include; $fieldsExclude = Fluent::config()->field_exclude; $dataInclude = Fluent::config()->data_include; $dataExclude = Fluent::config()->data_exclude; // filter out DB if ($db) { foreach ($db as $field => $type) { if (!empty($filter)) { // If given an explicit field name filter, then remove non-presented fields if (!in_array($field, $filter)) { unset($db[$field]); } } else { // Without a name filter then check against each filter type if ($fieldsInclude && !Fluent::any_match($field, $fieldsInclude) || $fieldsExclude && Fluent::any_match($field, $fieldsExclude) || $dataInclude && !Fluent::any_match($type, $dataInclude) || $dataExclude && Fluent::any_match($type, $dataExclude)) { unset($db[$field]); } } } } return $db; }); }