ArrayColumn.php
1 year ago
ArrayFlatten.php
1 year ago
ArrayKeys.php
1 year ago
ArraySearch.php
1 year ago
ArrayValues.php
1 year ago
Count.php
1 year ago
DotNotation.php
1 year ago
PrepareUrl.php
1 year ago
TransformerInterface.php
1 year ago
TransformerService.php
1 year ago
PrepareUrl.php
56 lines
| 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 |