Skip to content

Commit

Permalink
Clean up Twig config and AppExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaszGasior committed May 15, 2020
1 parent 8d180bf commit 575b2ed
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 30 deletions.
8 changes: 0 additions & 8 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
exception_controller: null
date:
format: 'j F Y'
form_themes:
- 'common/form/overwritten_types.html.twig'
- 'common/form/custom_types.html.twig'
globals:
locales: '%app.locales%'
version: '%app.version%'

# number_format defaults for radiostation frequency and power.
number_format:
decimals: 2
decimal_point: ','
thousands_separator: ''
22 changes: 0 additions & 22 deletions src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Extension\CoreExtension;
use Twig\Extension\EscaperExtension;
use Twig\Extra\Intl\IntlExtension;
use Twig\TwigFilter;
Expand All @@ -27,9 +26,6 @@ public function getFilters(): array
new TwigFilter('format_date_html', [$this, 'formatDateHTML'], [
'needs_environment' => true, 'is_safe' => ['html']
]),
new TwigFilter('soft_number_format', [$this, 'softNumberFormat'], [
'needs_environment' => true
]),
];
}

Expand All @@ -47,24 +43,6 @@ public function formatDateHTML(Environment $twig, $date, ?string $dateFormat = '
);
}

public function softNumberFormat(Environment $twig, $number, int $decimal = null,
string $decimalPoint = null, string $thousandSep = null): string
{
if (null === $decimal) {
/** @var CoreExtension */
$coreExtension = $twig->getExtension(CoreExtension::class);
$decimal = $coreExtension->getNumberFormat()[0];
}

// Don't round values with precision bigger than preferred.
$sourceDecimal = strlen(strstr((float)(string)$number, '.')) - 1;
if ($sourceDecimal > $decimal) {
$decimal = $sourceDecimal;
}

return twig_number_format_filter($twig, $number, $decimal, $decimalPoint, $thousandSep);
}

public function escapeCSV(Environment $twig, $data): string
{
$handle = fopen('php://temp', 'w');
Expand Down

0 comments on commit 575b2ed

Please sign in to comment.