From 400159973f76091e307c78105ff1655470a8114b Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Sun, 27 Oct 2019 13:51:17 +0100 Subject: [PATCH 1/7] Update versioning constraints to symfony versions --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43c9ba8..78eadb2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ Uses a range of +-7 days, after that, the actual date is returned. ## Install Composer (Packagist): ```sh -composer require eschmar/time-ago-bundle ~v1.0 # Symfony ^4.1 +composer require eschmar/time-ago-bundle ~v1.0.0 # Symfony 4.1 +composer require eschmar/time-ago-bundle ^v1.1.0 # Symfony ^4.3 ``` or for older symfony versions: From 46df7247c9ccdb93d382f72719f6d5a8082e0331 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Sun, 27 Oct 2019 13:52:02 +0100 Subject: [PATCH 2/7] Simplify versions --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 78eadb2..63655aa 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ Uses a range of +-7 days, after that, the actual date is returned. ## Install Composer (Packagist): ```sh -composer require eschmar/time-ago-bundle ~v1.0.0 # Symfony 4.1 -composer require eschmar/time-ago-bundle ^v1.1.0 # Symfony ^4.3 +composer require eschmar/time-ago-bundle ^v1.1.0 # Symfony ^4.x ``` or for older symfony versions: From f4d8b92e233456eb21652fd501d624f4bdd55048 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 4 Jun 2020 14:01:45 +0200 Subject: [PATCH 3/7] Update to new twig namespaces --- DependencyInjection/Configuration.php | 16 ++++++++-------- Twig/TimeAgoExtension.php | 6 +++--- composer.json | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3e0c5b1..8edbdae 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -6,9 +6,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; /** - * This is the class that validates and merges configuration from your app/config files. - * - * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html} + * {@inheritDoc} */ class Configuration implements ConfigurationInterface { @@ -17,14 +15,16 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigiBuilder() { $treeBuilder = new TreeBuilder(static::ROOT_NODE); - // Symfony 4.2+ - if (method_exists($treeBuilder, 'getRootNode')) $rootNode = $treeBuilder->getRootNode(); - // Symfony 4.1 and below - else $rootNode = $treeBuilder->root(static::ROOT_NODE); + // BC layer for symfony/config 4.1 and older + if (! \method_exists($treeBuilder, 'getRootNode')) { + $rootNode = $treeBuilder->root(static::ROOT_NODE); + } else { + $rootNode = $treeBuilder->getRootNode(); + } $treeBuilder->getRootNode() ->children() diff --git a/Twig/TimeAgoExtension.php b/Twig/TimeAgoExtension.php index 381f8a8..6497797 100644 --- a/Twig/TimeAgoExtension.php +++ b/Twig/TimeAgoExtension.php @@ -9,7 +9,7 @@ * * @author Marcel Eschmann, @eschmar **/ -class TimeAgoExtension extends \Twig_Extension +class TimeAgoExtension extends \Twig\Extension\AbstractExtension { const TRANSLATION_NAMESPACE = 'time_ago'; @@ -43,7 +43,7 @@ public function getName() public function getFilters() { return [ - new \Twig_SimpleFilter('ago', [$this, 'agoFilter']), + new \Twig\TwigFilter('ago', [$this, 'agoFilter']), ]; } @@ -80,4 +80,4 @@ public function agoFilter(\DateTime $date, $format = null) return $date->format($format); } -} // END class TimeAgoExtension extends \Twig_Extension +} // END class TimeAgoExtension extends \Twig\Extension\AbstractExtension diff --git a/composer.json b/composer.json index 206aa23..fcfddd5 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "target-dir": "Eschmar/TimeAgoBundle", "require": { "php": ">=7.1.0", + "twig/twig": "^3.0.0", "symfony/flex": "*" } } \ No newline at end of file From f4329cce534f4a5dcf595f3f6edbdf2ed9c68278 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 4 Jun 2020 14:04:42 +0200 Subject: [PATCH 4/7] Update to new naming scheme --- DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 8edbdae..301a1b1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -15,7 +15,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigiBuilder() + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(static::ROOT_NODE); From ca93815bf6bb4c7b991921d495557fb66ff53e0d Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 4 Jun 2020 14:06:14 +0200 Subject: [PATCH 5/7] Switch to new di contract --- Twig/TimeAgoExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Twig/TimeAgoExtension.php b/Twig/TimeAgoExtension.php index 6497797..14154df 100644 --- a/Twig/TimeAgoExtension.php +++ b/Twig/TimeAgoExtension.php @@ -2,7 +2,7 @@ namespace Eschmar\TimeAgoBundle\Twig; -use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Provides a simple twig filter for expressing time difference in words. From 81c00bc255cecabbe509c0aff1d24efa2f951b8f Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 4 Jun 2020 14:19:06 +0200 Subject: [PATCH 6/7] Migrate to new Translator::trans() interface --- Twig/TimeAgoExtension.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Twig/TimeAgoExtension.php b/Twig/TimeAgoExtension.php index 14154df..50d0bd5 100644 --- a/Twig/TimeAgoExtension.php +++ b/Twig/TimeAgoExtension.php @@ -65,17 +65,17 @@ public function agoFilter(\DateTime $date, $format = null) $days = floor($diff / 86400); if ($days >= 7) return $date->format($format); - if ($days >= 1) return $this->translator->transChoice($prefix . '.days', $days, ['#' => $days]); + if ($days >= 1) return $this->translator->trans($prefix . '.days', ['#' => $days, '%count%' => $days]); if ($diff < 60) return $this->translator->trans($prefix . '.now'); - + $m = floor($diff / 60); - if ($diff < 120) return $this->translator->transChoice($prefix . '.minutes', 1); - if ($diff < 3600) return $this->translator->transChoice($prefix . '.minutes', $m, ['#' => $m]); + if ($diff < 120) return $this->translator->trans($prefix . '.minutes', ['%count%' => 1]); + if ($diff < 3600) return $this->translator->trans($prefix . '.minutes', ['#' => $m, '%count%' => $m]); $h = floor($diff / 3600); - if ($diff < 7200) return $this->translator->transChoice($prefix . '.hours', 1); - if ($diff < 86400) return $this->translator->transChoice($prefix . '.hours', $h, ['#' => $h]); + if ($diff < 7200) return $this->translator->trans($prefix . '.hours', ['%count%' => 1]); + if ($diff < 86400) return $this->translator->trans($prefix . '.hours', ['#' => $h, '%count%' => $h]); return $date->format($format); } From 67e853a3dcf946b2fb3cf51c1b5e8b53ad772231 Mon Sep 17 00:00:00 2001 From: Marcel Eschmann Date: Thu, 4 Jun 2020 14:23:31 +0200 Subject: [PATCH 7/7] Update readme for symfony 5.0 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63655aa..b391aaa 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,17 @@ Uses a range of +-7 days, after that, the actual date is returned. ## Install Composer (Packagist): ```sh -composer require eschmar/time-ago-bundle ^v1.1.0 # Symfony ^4.x +composer require eschmar/time-ago-bundle ^v2.0.0 # Symfony ^5.0 ``` or for older symfony versions: ```sh +composer require eschmar/time-ago-bundle ^v1.1.0 # Symfony ^4.x composer require eschmar/time-ago-bundle ~v0.4.0 # Symfony ^2.8 composer require eschmar/time-ago-bundle ~v0.5.0 # Symfony ^3.4 ``` -app/Appkernel.php: +app/Appkernel.php (Symfony <4): ```php new Eschmar\TimeAgoBundle\EschmarTimeAgoBundle(), ```