PluginProbe
WooCommerce / 11.1.0
WooCommerce v11.1.0
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Admin / RemoteSpecs / RuleProcessors / Transformers / PrepareUrl.php
PrepareUrl.php
56 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers;
4
5 use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface;
6 use stdClass;
7
8 /**
9 * Prepare site URL for comparison.
10 *
11 * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers
12 */
13 class PrepareUrl implements TransformerInterface {
14 /**
15 * Prepares the site URL by removing the protocol and trailing slash.
16 *
17 * @param string $value a value to transform.
18 * @param stdClass|null $arguments arguments.
19 * @param string|null $default_value default value.
20 *
21 * @return mixed|null
22 */
23 public function transform( $value, ?stdClass $arguments = null, $default_value = null ) {
24 if ( ! is_string( $value ) ) {
25 return $default_value;
26 }
27
28 $url_parts = wp_parse_url( rtrim( $value, '/' ) );
29
30 if ( ! $url_parts ) {
31 return $default_value;
32 }
33
34 if ( ! isset( $url_parts['host'] ) ) {
35 return $default_value;
36 }
37
38 if ( isset( $url_parts['path'] ) ) {
39 return $url_parts['host'] . $url_parts['path'];
40 }
41
42 return $url_parts['host'];
43 }
44
45 /**
46 * Validate Transformer arguments.
47 *
48 * @param stdClass|null $arguments arguments to validate.
49 *
50 * @return mixed
51 */
52 public function validate( ?stdClass $arguments = null ) {
53 return true;
54 }
55 }
56