Skip to content

Commit 1182800

Browse files
lmsssrtab
authored andcommitted
Added support for php8 removing package from project. This package is no longer needed, its functionality has been replaced by native php code.
1 parent 155b48f commit 1182800

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [2.1.6] - 2019-10-04
7+
## [3.0.0] - 2022-11-23
8+
### Added
9+
- Added support for php8 removing package `fleshgrinder/format` from project. This package is no longer needed, its functionality has been replaced by native php code.
810
### Fixed
9-
- Changed validation to check if empty instead of null.
11+
- Fixed Twig class paths
1012

1113
## [2.1.5] - 2019-10-04
1214
### Fixed

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
},
2020
"require": {
2121
"php": ">=7.0.0",
22-
"fleshgrinder/format": "^1.1",
2322
"twig/twig": ">=1.35"
2423
},
2524
"require-dev": {

src/Messages.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*/
55
namespace PHPForm;
66

7-
use Fleshgrinder\Core\Formatter;
8-
97
class Messages
108
{
119
/**
@@ -48,7 +46,9 @@ public static function format(string $id, array $context = null)
4846
$message = array_key_exists($id, self::$messages) ? self::$messages[$id] : $id;
4947

5048
if (!is_null($context)) {
51-
$message = Formatter::format($message, $context);
49+
foreach ($context as $key => $value) {
50+
$message = str_replace("{{$key}}", $value, $message);
51+
}
5252
}
5353

5454
return $message;

src/Renderers/TwigRenderer.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
namespace PHPForm\Renderers;
66

77
use Twig\Loader\ChainLoader;
8-
use Twig\Environment;
9-
use Twig\Loader\FilesystemLoader;
10-
use Twig\TwigFilter;
118

129
class TwigRenderer implements Renderer
1310
{
@@ -32,8 +29,8 @@ public function __construct(array $templates_dirs, array $options = array())
3229
$class = 'Twig_Loader_Filesystem';
3330
$envClass = 'Twig_Environment';
3431
} else {
35-
$class = 'FilesystemLoader';
36-
$envClass = 'Environment';
32+
$class = 'Twig\Loader\FilesystemLoader';
33+
$envClass = 'Twig\Environment';
3734
}
3835

3936
foreach ($templates_dirs as $template_dir) {
@@ -50,7 +47,7 @@ public function setFilters()
5047
if (class_exists('Twig_SimpleFilter')) {
5148
$class = 'Twig_SimpleFilter';
5249
} else {
53-
$class = 'TwigFilter';
50+
$class = 'Twig\TwigFilter';
5451
}
5552

5653
$filter_merge_str = new $class('merge_str', function ($attrs, array $options = array()) {

tests/unit/MessagesTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public function testFormat()
2323
public function testFormatWithContext()
2424
{
2525
$this->assertEquals("String unit", Messages::format("String {name}", ["name" => "unit"]));
26+
$this->assertEquals(
27+
"String unit test",
28+
Messages::format("String {name} {test}", ["name" => "unit", "test" => "test"])
29+
);
2630
$this->assertEquals(
2731
"Ensure this value is greater than or equal to 10.",
2832
Messages::format("INVALID_MIN_VALUE", ["limit" => 10])

0 commit comments

Comments
 (0)