/var/www/p4ela.net/www/wp-content/plugins/image-optimization/classes
Edit: /var/www/p4ela.net/www/wp-content/plugins/image-optimization/classes/module-base.php (7270B)
reflection ) {
try {
$this->reflection = new \ReflectionClass( $this );
} catch ( \ReflectionException $e ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( $e->getMessage() );
}
}
}
return $this->reflection;
}
/**
* Add module component.
*
* Add new component to the current module.
* @access public
*
* @param string $id Component ID.
* @param mixed $instance An instance of the component.
*/
public function add_component( string $id, $instance ) {
$this->components[ $id ] = $instance;
}
/**
* Add module route.
*
* Add new route to the current module.
* @access public
*
* @param string $id Route ID.
* @param mixed $instance An instance of the route.
*/
public function add_route( string $id, $instance ) {
$this->routes[ $id ] = $instance;
}
/**
* @access public
* @return string[]
*/
public function get_components(): array {
return $this->components;
}
/**
* Get module component.
*
* Retrieve the module component.
* @access public
*
* @param string $id Component ID.
*
* @return mixed An instance of the component, or `false` if the component
* doesn't exist.
* @codeCoverageIgnore
*/
public function get_component( string $id ) {
if ( isset( $this->components[ $id ] ) ) {
return $this->components[ $id ];
}
return false;
}
/**
* Retrieve the namespace of the class
*
* @access public
* @static
*/
public static function namespace_name() {
$class_name = static::class_name();
return substr( $class_name, 0, strrpos( $class_name, '\\' ) );
}
/**
* Get assets url.
*
* @param string $file_name
* @param string $file_extension
* @param string $relative_url Optional. Default is null.
*
* @return string
*/
final protected function get_assets_url( $file_name, $file_extension, $relative_url = null ): string {
static $is_test_mode = null;
if ( null === $is_test_mode ) {
$is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
}
if ( ! $relative_url ) {
$relative_url = $this->get_assets_relative_url();
}
$url = $this->get_assets_base_url() . $relative_url . $file_name;
return $url . '.' . $file_extension;
}
/**
* Get js assets url
*
* @param string $file_name
* @param string $relative_url Optional. Default is null.
* @param string $add_min_suffix Optional. Default is 'default'.
*
* @return string
*/
final protected function get_js_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default' ): string {
return $this->get_assets_url( $file_name, 'js', $relative_url, $add_min_suffix );
}
/**
* Get css assets url
*
* @param string $file_name
* @param string $relative_url Optional. Default is null.
* @param string $add_min_suffix Optional. Default is 'default'.
* @param bool $add_direction_suffix Optional. Default is `false`
*
* @return string
*/
final protected function get_css_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default', $add_direction_suffix = false ): string {
static $direction_suffix = null;
if ( ! $direction_suffix ) {
$direction_suffix = is_rtl() ? '-rtl' : '';
}
if ( $add_direction_suffix ) {
$file_name .= $direction_suffix;
}
return $this->get_assets_url( $file_name, 'css', $relative_url, $add_min_suffix );
}
/**
* Get assets base url
*
* @return string
*/
protected function get_assets_base_url(): string {
return IMAGE_OPTIMIZATION_URL;
}
/**
* Get assets relative url
*
* @return string
*/
protected function get_assets_relative_url(): string {
return 'assets/build/';
}
public static function routes_list() : array {
return [];
}
public static function component_list() : array {
return [];
}
/**
* Adds an array of components.
* Assumes namespace structure contains `\Components\`
*/
public function register_components() {
$namespace = static::namespace_name();
$components_ids = static::component_list();
foreach ( $components_ids as $component_id ) {
$class_name = $namespace . '\\Components\\' . $component_id;
$this->add_component( $component_id, new $class_name() );
}
}
/**
* Adds an array of routes.
* Assumes namespace structure contains `\Rest\`
*/
public function register_routes() {
$namespace = static::namespace_name();
$routes_ids = static::routes_list();
foreach ( $routes_ids as $route_id ) {
$class_name = $namespace . '\\Rest\\' . $route_id;
$this->add_route( $route_id, new $class_name() );
}
}
}