| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/enairehub/wp-content/plugins/webp-converter-for-media/src/Settings/ |
Upload File : |
<?php
namespace WebpConverter\Settings;
use WebpConverter\Conversion\Directory\DirectoryFactory;
use WebpConverter\Conversion\Format\FormatFactory;
use WebpConverter\Conversion\Method\MethodFactory;
use WebpConverter\Repository\TokenRepository;
use WebpConverter\Service\OptionsAccessManager;
use WebpConverter\Settings\Option\OptionIntegrator;
use WebpConverter\Settings\Option\OptionsAggregator;
/**
* Allows to integration with plugin settings by providing list of settings fields and saved values.
*/
class OptionsManager {
/**
* @var OptionsAggregator
*/
private $options_aggregator;
public function __construct(
TokenRepository $token_repository,
MethodFactory $method_factory,
FormatFactory $format_factory,
DirectoryFactory $directory_factory
) {
$this->options_aggregator = new OptionsAggregator( $token_repository, $method_factory, $format_factory, $directory_factory );
}
/**
* @param string|null $form_name .
* @param bool $is_debug Is debugging?
* @param mixed[]|null $posted_settings Settings submitted in form.
*
* @return mixed[] Options of plugin settings.
*/
public function get_options( string $form_name = null, bool $is_debug = false, array $posted_settings = null ): array {
$is_save = ( $posted_settings !== null );
$settings = ( $is_save ) ? $posted_settings : OptionsAccessManager::get_option( SettingsManager::SETTINGS_OPTION, [] );
$options = [];
foreach ( $this->options_aggregator->get_options( $form_name ) as $option_object ) {
$options[] = ( new OptionIntegrator( $option_object ) )->get_option_data( $settings, $is_debug, $is_save );
}
return $options;
}
/**
* @param bool $is_debug Is debugging?
*
* @return mixed[] Values of plugin settings.
*/
public function get_values( bool $is_debug = false ): array {
$settings = OptionsAccessManager::get_option( SettingsManager::SETTINGS_OPTION, [] );
$values = [];
foreach ( $this->options_aggregator->get_options() as $option_object ) {
$values[ $option_object->get_name() ] = $option_object->sanitize_value(
( ! $is_debug )
? ( $settings[ $option_object->get_name() ] ?? $option_object->get_default_value( $settings ) )
: $option_object->get_debug_value( $settings )
);
}
return $values;
}
/**
* @return mixed[] Values of plugin settings.
*/
public function get_public_values(): array {
$settings = $this->get_values();
$values = [];
foreach ( $this->options_aggregator->get_options() as $option_object ) {
$values[ $option_object->get_name() ] = $option_object->get_public_value(
$settings[ $option_object->get_name() ]
);
}
return $values;
}
/**
* @param mixed[]|null $posted_settings Settings submitted in form.
* @param string|null $form_name .
*
* @return mixed[] Values of plugin settings.
*/
public function get_validated_values( array $posted_settings = null, string $form_name = null ): array {
$values = [];
foreach ( $this->get_options( $form_name, false, $posted_settings ) as $option ) {
$values[ $option['name'] ] = $option['value'];
}
return $values;
}
}