'\\Fields\\User' */ $namespace = implode( '/', array_map( 'ucfirst', explode( '/', $path ) ) ); $namespace = str_replace( '/', '\\', $namespace ); static::include_classes_from_folder_recursive( $full_path, $namespace, $type_class ); } /** * @param $path * @param $namespace * @param $type_class */ public static function include_classes_from_folder_recursive( $path, $namespace, $type_class ) { $items = array_diff( scandir( $path ), [ '.', '..' ] ); foreach ( $items as $item ) { $item_path = $path . '/' . $item; /* if the item is a folder, enter it and do recursion */ if ( is_dir( $item_path ) ) { static::include_classes_from_folder_recursive( $item_path, $namespace, $type_class ); } /* if the item is a file, include it */ if ( is_file( $item_path ) && substr( $item_path, - 3 ) === 'php' ) { require_once $item_path; /* for each file, dynamically call the init function of the class */ if ( preg_match( '/class-(.*).php/m', $item, $m ) && ! empty( $m[1] ) ) { $class_name = \TCB_ELEMENTS::capitalize_class_name( $m[1] ); $class = __NAMESPACE__ . '\\' . $namespace . '\\' . $class_name; $type_class::register( $class ); } } } } /** * Get all the data that we want to localize for Conditional Display - the rest is fetched on demand through REST * * @return array */ public static function get_localized_data() { return [ 'entities' => Entity::get_data_to_localize(), ]; } }