WC_Autoloader::load_rest_v4_controller_recursivelyprivateWC 1.0

Recursively load REST API V4 controllers from subdirectories.

Method of the class: WC_Autoloader{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->load_rest_v4_controller_recursively( $file ): bool;
$file(string) (required)
File name to search for.

WC_Autoloader::load_rest_v4_controller_recursively() code WC 10.7.0

private function load_rest_v4_controller_recursively( $file ): bool {
	$v4_base_path = $this->include_path . 'rest-api/Controllers/Version4/';

	// Use RecursiveDirectoryIterator to search subdirectories.
	if ( is_dir( $v4_base_path ) ) {
		$iterator = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator( $v4_base_path, RecursiveDirectoryIterator::SKIP_DOTS ),
			RecursiveIteratorIterator::SELF_FIRST
		);

		foreach ( $iterator as $dir_info ) {
			if ( $dir_info->isDir() ) {
				$subdir_path = $dir_info->getPathname() . '/';
				if ( $this->load_file( $subdir_path . $file ) ) {
					return true;
				}
			}
		}
	}
	return false;
}