plugin updates
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Automattic\WooCommerce\Utilities;
|
||||
|
||||
use Automattic\WooCommerce\Internal\Admin\Logging\{ PageController, Settings };
|
||||
use Automattic\WooCommerce\Internal\Admin\Logging\FileV2\File;
|
||||
|
||||
/**
|
||||
* A class of utilities for dealing with logging.
|
||||
*/
|
||||
final class LoggingUtil {
|
||||
/**
|
||||
* Get the canonical URL for the Logs tab of the Status admin page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_logs_tab_url(): string {
|
||||
return wc_get_container()->get( PageController::class )->get_logs_tab_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the current value of the logging_enabled setting.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function logging_is_enabled(): bool {
|
||||
return wc_get_container()->get( Settings::class )->logging_is_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the current value of the default_handler setting.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_default_handler(): string {
|
||||
return wc_get_container()->get( Settings::class )->get_default_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the current value of the retention_period_days setting.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_retention_period(): int {
|
||||
return wc_get_container()->get( Settings::class )->get_retention_period();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the current value of the level_threshold setting.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_level_threshold(): string {
|
||||
return wc_get_container()->get( Settings::class )->get_level_threshold();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a public ID for a log file based on its properties.
|
||||
*
|
||||
* The file ID is the basename of the file without the hash part. It allows us to identify a file without revealing
|
||||
* its full name in the filesystem, so that it's difficult to access the file directly with an HTTP request.
|
||||
*
|
||||
* @param string $source The source of the log entries contained in the file.
|
||||
* @param int|null $rotation Optional. The 0-based incremental rotation marker, if the file has been rotated.
|
||||
* Should only be a single digit.
|
||||
* @param int $created Optional. The date the file was created, as a Unix timestamp.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generate_log_file_id( string $source, ?int $rotation = null, int $created = 0 ): string {
|
||||
return File::generate_file_id( $source, $rotation, $created );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a hash to use as the suffix on a log filename.
|
||||
*
|
||||
* @param string $file_id A file ID (file basename without the hash).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generate_log_file_hash( string $file_id ): string {
|
||||
return File::generate_hash( $file_id );
|
||||
}
|
||||
}
|
||||
48
wp/wp-content/plugins/woocommerce/src/Utilities/TimeUtil.php
Normal file
48
wp/wp-content/plugins/woocommerce/src/Utilities/TimeUtil.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Automattic\WooCommerce\Utilities;
|
||||
|
||||
use \DateTime;
|
||||
use \DateTimeZone;
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* Class with date and time utilities.
|
||||
*/
|
||||
class TimeUtil {
|
||||
|
||||
/**
|
||||
* Instance of a DateTimeZone object representing UTC.
|
||||
*
|
||||
* @var DateTimeZone
|
||||
*/
|
||||
private static DateTimeZone $utc_date_time_zone;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
self::$utc_date_time_zone = new DateTimeZone( 'UTC' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance of the DateTimeZone object representing UTC.
|
||||
*
|
||||
* @return DateTimeZone DateTimeZone object representing UTC.
|
||||
*/
|
||||
public static function get_utc_date_time_zone(): DateTimeZone {
|
||||
return self::$utc_date_time_zone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string represents a valid date in a given format.
|
||||
*
|
||||
* @param string $date The date string to check.
|
||||
* @param string $format The format to verify the date string against.
|
||||
* @return bool True if $date represents a valid date/time according to $format, false otherwise.
|
||||
*/
|
||||
public static function is_valid_date( string $date, string $format = 'Y-m-d H:i:s' ): bool {
|
||||
$d = DateTime::createFromFormat( $format, $date );
|
||||
return $d && $d->format( $format ) === $date;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user