File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/Formatters.tar
CurrencyFormatter.php 0000644 00000002506 15155572466 0010756 0 ustar 00 <?php
namespace Automattic\WooCommerce\StoreApi\Formatters;
/**
* Currency Formatter.
*
* Formats an array of monetary values by inserting currency data.
*/
class CurrencyFormatter implements FormatterInterface {
/**
* Format a given value and return the result.
*
* @param array $value Value to format.
* @param array $options Options that influence the formatting.
* @return array
*/
public function format( $value, array $options = [] ) {
$position = get_option( 'woocommerce_currency_pos' );
$symbol = html_entity_decode( get_woocommerce_currency_symbol() );
$prefix = '';
$suffix = '';
switch ( $position ) {
case 'left_space':
$prefix = $symbol . ' ';
break;
case 'left':
$prefix = $symbol;
break;
case 'right_space':
$suffix = ' ' . $symbol;
break;
case 'right':
$suffix = $symbol;
break;
}
return array_merge(
(array) $value,
[
'currency_code' => get_woocommerce_currency(),
'currency_symbol' => $symbol,
'currency_minor_unit' => wc_get_price_decimals(),
'currency_decimal_separator' => wc_get_price_decimal_separator(),
'currency_thousand_separator' => wc_get_price_thousand_separator(),
'currency_prefix' => $prefix,
'currency_suffix' => $suffix,
]
);
}
}
DefaultFormatter.php 0000644 00000000633 15155572466 0010547 0 ustar 00 <?php
namespace Automattic\WooCommerce\StoreApi\Formatters;
/**
* Default Formatter.
*/
class DefaultFormatter implements FormatterInterface {
/**
* Format a given value and return the result.
*
* @param mixed $value Value to format.
* @param array $options Options that influence the formatting.
* @return mixed
*/
public function format( $value, array $options = [] ) {
return $value;
}
}
FormatterInterface.php 0000644 00000000557 15155572466 0011070 0 ustar 00 <?php
namespace Automattic\WooCommerce\StoreApi\Formatters;
/**
* FormatterInterface.
*/
interface FormatterInterface {
/**
* Format a given value and return the result.
*
* @param mixed $value Value to format.
* @param array $options Options that influence the formatting.
* @return mixed
*/
public function format( $value, array $options = [] );
}
HtmlFormatter.php 0000644 00000001602 15155572466 0010064 0 ustar 00 <?php
namespace Automattic\WooCommerce\StoreApi\Formatters;
/**
* Html Formatter.
*
* Formats HTML in API responses.
*
* @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions.
*/
class HtmlFormatter implements FormatterInterface {
/**
* Format a given value and return the result.
*
* The wptexturize, convert_chars, and trim functions are also used in the `the_title` filter.
* The function wp_kses_post removes disallowed HTML tags.
*
* @param string|array $value Value to format.
* @param array $options Options that influence the formatting.
* @return string
*/
public function format( $value, array $options = [] ) {
if ( is_array( $value ) ) {
return array_map( [ $this, 'format' ], $value );
}
return is_scalar( $value ) ? wp_kses_post( trim( convert_chars( wptexturize( $value ) ) ) ) : $value;
}
}
MoneyFormatter.php 0000644 00000001402 15155572466 0010245 0 ustar 00 <?php
namespace Automattic\WooCommerce\StoreApi\Formatters;
/**
* Money Formatter.
*
* Formats monetary values using store settings.
*/
class MoneyFormatter implements FormatterInterface {
/**
* Format a given value and return the result.
*
* @param mixed $value Value to format.
* @param array $options Options that influence the formatting.
* @return mixed
*/
public function format( $value, array $options = [] ) {
$options = wp_parse_args(
$options,
[
'decimals' => wc_get_price_decimals(),
'rounding_mode' => PHP_ROUND_HALF_UP,
]
);
return (string) intval(
round(
( (float) wc_format_decimal( $value ) ) * ( 10 ** absint( $options['decimals'] ) ),
0,
absint( $options['rounding_mode'] )
)
);
}
}