Automattic\WooCommerce\Internal\Admin\Logging\FileV2
FileController::get_file_rotations()
Get File instances for a given file ID and all of its related rotations.
Метод класса: FileController{}
Хуков нет.
Возвращает
File[]|WP_Error
. An associative array where the rotation integer of the file is the key, and a "current" key for the iteration of the file that hasn't been rotated (if it exists).
Использование
$FileController = new FileController(); $FileController->get_file_rotations( $file_id );
- $file_id(строка) (обязательный)
- A file ID (file basename without the hash).
Код FileController::get_file_rotations() FileController::get file rotations WC 9.7.1
public function get_file_rotations( string $file_id ) { $file = $this->get_file_by_id( $file_id ); if ( is_wp_error( $file ) ) { return $file; } $current = array(); $rotations = array(); $source = $file->get_source(); $created = 0; if ( $file->has_standard_filename() ) { $created = $file->get_created_timestamp(); } if ( is_null( $file->get_rotation() ) ) { $current['current'] = $file; } else { $current_file_id = File::generate_file_id( $source, null, $created ); $result = $this->get_file_by_id( $current_file_id ); if ( ! is_wp_error( $result ) ) { $current['current'] = $result; } } $rotations_pattern = sprintf( '.[%s]', implode( '', range( 0, self::MAX_FILE_ROTATIONS - 1 ) ) ); $created_pattern = $created ? '-' . gmdate( 'Y-m-d', $created ) . '-' : ''; $rotation_pattern = Settings::get_log_directory() . $source . $rotations_pattern . $created_pattern . '*.log'; $rotation_paths = glob( $rotation_pattern ); $rotation_files = $this->convert_paths_to_objects( $rotation_paths ); foreach ( $rotation_files as $rotation_file ) { if ( $rotation_file->is_readable() ) { $rotations[ $rotation_file->get_rotation() ] = $rotation_file; } } ksort( $rotations ); return array_merge( $current, $rotations ); }