Compare commits

..

1 Commits

Author SHA1 Message Date
Simon Wisselink 1150fc5ecd Add PHP8.3 support for Smarty 4.3. 2024-01-23 10:44:44 +01:00
29 changed files with 30 additions and 469 deletions
-13
View File
@@ -6,22 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Using unregistered static class methods in expressions now also triggers a deprecation notice because we will drop support for this in the next major release [#813](https://github.com/smarty-php/smarty/issues/813)
## [4.4.1] - 2024-02-26
- Fixed internal release-tooling
## [4.4.0] - 2024-02-26
### Changed
- Using the `|implode`, `|json_encode` and `|substr` modifiers does not generate a deprecation warning anymore as they will continue to be supported in v5 [#939](https://github.com/smarty-php/smarty/issues/939)
### Added
- PHP8.3 support [#925](https://github.com/smarty-php/smarty/issues/925)
### Fixed
- Incorrect compilation of expressions when escape_html=true [#930](https://github.com/smarty-php/smarty/pull/930)
## [4.3.4] - 2023-09-14
## [4.3.3] - 2023-09-14
+1 -1
View File
@@ -7,7 +7,7 @@ Smarty is a template engine for PHP, facilitating the separation of presentation
Read the [documentation](https://smarty-php.github.io/smarty/) to find out how to use it.
## Requirements
Smarty can be run with PHP 7.1 to PHP 8.3.
Smarty can be run with PHP 7.1 to PHP 8.2.
## Installation
Smarty versions 3.1.11 or later can be installed with [Composer](https://getcomposer.org/).
View File
+1 -1
View File
@@ -1,7 +1,7 @@
# Getting started
## Requirements
Smarty can be run with PHP 7.1 to PHP 8.3.
Smarty can be run with PHP 7.1 to PHP 8.2.
## Installation
Smarty can be installed with [Composer](https://getcomposer.org/).
-38
View File
@@ -1,38 +0,0 @@
# Upgrading from an older version
## Upgrading from v3 to v4
Smarty 4 is mostly identical to Smarty 3. Most notably, it adds support for PHP8 and drops support for PHP7.0 and below.
Additionally, some deprecated features that have long been discouraged have been dropped from the language.
### Muting PHP8 warnings
If you simultaneously upgrade Smarty to v4 van PHP to v8, you may notice your error logs filling up with warnings about undefined or null template vars
due to a change in how PHP handles these. This may be helpful to spot errors, but if you find this annoying, you can use
`$smarty->muteUndefinedOrNullWarnings()` to make Smarty convert these warnings into notices.
### ASP tags
You can no longer user ASP-style tags like `<% %>` and `<%= %>` in your templates.
Replace them with `{...}` tags.
### SmartyBC
Check your codebase for `SmartyBC`.
We have dropped deprecated API calls that where only accessible through the SmartyBC class.
### No more embedded PHP
We have completely dropped support for `{php}` and `{include_php}` tags and embedded PHP in templates.
Check your templates for this, and rewrite any embedded PHP blocks, by moving logic to your PHP files or by
creating a [plugin function](./programmers/plugins/plugins-functions.md).
### Other changes
Search your code for the following changes:
- `SMARTY_RESOURCE_CHAR_SET` and `SMARTY_RESOURCE_DATE_FORMAT` constants have been removed
- `Smarty::muteExpectedErrors` and `Smarty::unmuteExpectedErrors` API methods have been removed
- `Smarty::getVariable` method has been removed. Use [Smarty::getTemplateVars](programmers/api-functions/api-get-template-vars.md) instead.
- [Smarty::registerResource](programmers/api-functions/api-register-resource.md) no longer accepts an array of callback functions
-3
View File
@@ -785,9 +785,6 @@ value(res) ::= ns1(c)DOUBLECOLON static_class_access(s). {
if (isset($this->smarty->registered_classes[c])) {
res = $this->smarty->registered_classes[c].'::'.s[0].s[1];
} else {
trigger_error('Using unregistered static method "' . c.'::'.s[0] . '" in a template is deprecated and will be ' .
'removed in a future release. Use Smarty::registerClass to explicitly register ' .
'a class for access.', E_USER_DEPRECATED);
res = c.'::'.s[0].s[1];
}
} else {
+1 -1
View File
@@ -107,7 +107,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '4.4.1';
const SMARTY_VERSION = '4.3.4';
/**
* define variable scopes
*/
-15
View File
@@ -1,15 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
function smarty_modifier_implode($values, $separator = '')
{
if (is_array($separator)) {
return implode((string) ($values ?? ''), (array) $separator);
}
return implode((string) ($separator ?? ''), (array) $values);
}
@@ -1,11 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
function smarty_modifiercompiler_json_encode($params) {
return 'json_encode(' . $params[0] . (isset($params[1]) ? ', (int) ' . $params[1] : '') . ')';
}
-12
View File
@@ -1,12 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
function smarty_modifiercompiler_substr($params) {
return 'substr((string) ' . $params[0] . ', (int) ' . $params[1] .
(isset($params[2]) ? ', (int) ' . $params[2] : '') . ')';
}
@@ -109,11 +109,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
if (!in_array($modifier, ['time', 'join', 'is_array', 'in_array'])) {
trigger_error('Using unregistered function "' . $modifier . '" in a template is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
}
trigger_error('Using php-function "' . $modifier . '" as a modifier is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
$output = "{$modifier}({$params})";
}
$compiler->known_modifier_type[ $modifier ] = $type;
@@ -93,7 +93,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
// autoescape html
if ($compiler->template->smarty->escape_html) {
$output = "htmlspecialchars((string) ({$output}), ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
$output = "htmlspecialchars((string) {$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
}
// loop over registered filters
if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
@@ -640,17 +640,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
return $func_name . '(' . $parameter[ 0 ] . ')';
}
} else {
$first_param = array_shift($parameter);
$modifier = array_merge(array($name), $parameter);
// Now, compile the function call as a modifier
return $this->compileTag(
'private_modifier',
array(),
array(
'modifierlist' => array($modifier),
'value' => $first_param
)
);
return $name . '(' . implode(',', $parameter) . ')';
}
} else {
$this->trigger_template_error("unknown function '{$name}'");
@@ -2425,9 +2425,6 @@ public static $yy_action = array(
if (isset($this->smarty->registered_classes[$this->yystack[$this->yyidx + -2]->minor])) {
$this->_retvalue = $this->smarty->registered_classes[$this->yystack[$this->yyidx + -2]->minor].'::'.$this->yystack[$this->yyidx + 0]->minor[0].$this->yystack[$this->yyidx + 0]->minor[1];
} else {
trigger_error('Using unregistered static method "' . $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor[0] . '" in a template is deprecated and will be ' .
'removed in a future release. Use Smarty::registerClass to explicitly register ' .
'a class for access.', E_USER_DEPRECATED);
$this->_retvalue = $this->yystack[$this->yyidx + -2]->minor.'::'.$this->yystack[$this->yyidx + 0]->minor[0].$this->yystack[$this->yyidx + 0]->minor[1];
}
} else {
+1 -1
View File
@@ -253,7 +253,7 @@ class Smarty_Security
*
* @param string $function_name
* @param object $compiler compiler object
* @deprecated
*
* @return boolean true if function is trusted
*/
public function isTrustedPhpFunction($function_name, $compiler)
+3 -4
View File
@@ -8,11 +8,10 @@ else
fi
git checkout -b "release/$1"
sed -i "s/## \\[Unreleased\\]/## \\[Unreleased\\]\\n\\n## \\[$1\\] - $(date +%Y-%m-%d)/" CHANGELOG.md
sed -i "s/const SMARTY_VERSION = '[^']\+';/const SMARTY_VERSION = '$1';/" libs/Smarty.class.php
php utilities/update-changelog.php $1
php utilities/update-smarty-version-number.php $1
git add changelog CHANGELOG.md libs/Smarty.class.php
git add CHANGELOG.md libs/Smarty.class.php
git commit -m "version bump"
git checkout support/4.3
+1 -3
View File
@@ -26,9 +26,7 @@ markdown_extensions:
nav:
- Home: 'index.md'
- 'Getting started':
- Introduction: 'getting-started.md'
- 'Upgrading from an older version': 'upgrading.md'
- 'Getting started': 'getting-started.md'
- 'Designers':
- 'Basic Syntax':
- Introduction: 'designers/language-basic-syntax/index.md'
+1 -5
View File
@@ -15,11 +15,7 @@
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true">
verbose="false">
<testsuites>
<testsuite name="foo">
<directory>./tests/UnitTests/</directory>
+8 -10
View File
@@ -5,13 +5,11 @@
# - ./run-tests-for-all-php-versions.sh --group 20221124
# - ./run-tests-for-all-php-versions.sh --exclude-group slow
COMPOSE_CMD="mutagen-compose"
$COMPOSE_CMD run --rm php71 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php72 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php73 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php74 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php80 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php81 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php82 ./run-tests.sh $@ && \
$COMPOSE_CMD run --rm php83 ./run-tests.sh $@
docker-compose run php71 ./run-tests.sh $@ && \
docker-compose run php72 ./run-tests.sh $@ && \
docker-compose run php73 ./run-tests.sh $@ && \
docker-compose run php74 ./run-tests.sh $@ && \
docker-compose run php80 ./run-tests.sh $@ && \
docker-compose run php81 ./run-tests.sh $@ && \
docker-compose run php82 ./run-tests.sh $@ && \
docker-compose run php83 ./run-tests.sh $@
+1 -1
View File
@@ -149,7 +149,7 @@ class PHPUnit_Smarty extends PHPUnit\Framework\TestCase
$this->smarty->setCacheDir(__DIR__ . '/cache');
}
$this->smarty->setErrorReporting(E_ALL &~ E_USER_DEPRECATED);
$this->getSmartyObj();
}
/**
@@ -49,6 +49,6 @@ class LoadPluginTest extends PHPUnit_Smarty
*/
public function testLoadPluginSmartyPluginCounter()
{
$this->assertTrue($this->smarty->loadPlugin('Smarty_function_counter') == true);
$this->assertTrue($this->smarty->loadPlugin('Smarty_Function_Counter') == true);
}
}
@@ -52,7 +52,7 @@ class SecurityTest extends PHPUnit_Smarty
*/
public function testTrustedPHPFunction()
{
$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{count($foo)}'));
$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}'));
}
/**
@@ -75,7 +75,7 @@ class SecurityTest extends PHPUnit_Smarty
{
$this->smarty->security_policy->php_functions = array('null');
$this->smarty->disableSecurity();
$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{count($foo)}'));
$this->assertEquals("5", $this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{sizeof($foo)}'));
}
/**
@@ -46,7 +46,7 @@ class ClearAllAssignTest extends PHPUnit_Smarty
*/
public function testClearAllAssignInTemplate()
{
$this->smarty->setErrorReporting($this->smarty->error_reporting & ~(E_NOTICE | E_USER_NOTICE | E_WARNING));
error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)));
$this->_tpl->clearAllAssign();
$this->assertEquals('foobar', $this->smarty->fetch($this->_tpl));
}
@@ -56,7 +56,7 @@ class ClearAllAssignTest extends PHPUnit_Smarty
*/
public function testClearAllAssignInData()
{
$this->smarty->setErrorReporting($this->smarty->error_reporting & ~(E_NOTICE | E_USER_NOTICE | E_WARNING));
error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)));
$this->_data->clearAllAssign();
$this->assertEquals('fooblar', $this->smarty->fetch($this->_tpl));
}
@@ -66,7 +66,7 @@ class ClearAllAssignTest extends PHPUnit_Smarty
*/
public function testClearAllAssignInSmarty()
{
$this->smarty->setErrorReporting($this->smarty->error_reporting & ~(E_NOTICE | E_USER_NOTICE | E_WARNING));
error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)));
$this->smarty->clearAllAssign();
$this->assertEquals('barblar', $this->smarty->fetch($this->_tpl));
}
@@ -1,44 +0,0 @@
<?php
/**
* Smarty PHPunit tests of modifier
*/
/**
* class for modifier tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class PluginModifierImplodeTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
}
public function testDefault()
{
$tpl = $this->smarty->createTemplate('string:{""|implode:$v}');
$tpl->assign("v", ["1", "2"]);
$this->assertEquals("12", $this->smarty->fetch($tpl));
}
public function testWithSeparator()
{
$tpl = $this->smarty->createTemplate('string:{","|implode:$v}');
$tpl->assign("v", ["a", "b"]);
$this->assertEquals("a,b", $this->smarty->fetch($tpl));
}
public function testInConditional()
{
$tpl = $this->smarty->createTemplate('string:{if implode("", $v) == "abc"}good{else}bad{/if}');
$tpl->assign("v", ['a','b','c']);
$this->assertEquals("good", $this->smarty->fetch($tpl));
}
public function testInConditionalWithSeparator()
{
$tpl = $this->smarty->createTemplate('string:{if implode("-", $v) == "a-b-c"}good{else}bad{/if}');
$tpl->assign("v", ['a','b','c']);
$this->assertEquals("good", $this->smarty->fetch($tpl));
}
}
@@ -1,76 +0,0 @@
<?php
/**
* Smarty PHPunit tests of modifier
*/
/**
* class for modifier tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class PluginModifierJsonEncodeTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
}
/**
* @dataProvider dataForDefault
*/
public function testDefault($value, $expected)
{
$tpl = $this->smarty->createTemplate('string:{$v|json_encode}');
$tpl->assign("v", $value);
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
/**
* @dataProvider dataForDefault
*/
public function testDefaultAsFunction($value, $expected)
{
$tpl = $this->smarty->createTemplate('string:{json_encode($v)}');
$tpl->assign("v", $value);
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function dataForDefault() {
return [
["abc", '"abc"'],
[["abc"], '["abc"]'],
[["abc",["a"=>2]], '["abc",{"a":2}]'],
];
}
/**
* @dataProvider dataForForceObject
*/
public function testForceObject($value, $expected)
{
$tpl = $this->smarty->createTemplate('string:{$v|json_encode:16}');
$tpl->assign("v", $value);
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
/**
* @dataProvider dataForForceObject
*/
public function testForceObjectAsFunction($value, $expected)
{
$tpl = $this->smarty->createTemplate('string:{json_encode($v,16)}');
$tpl->assign("v", $value);
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function dataForForceObject() {
return [
["abc", '"abc"'],
[["abc"], '{"0":"abc"}'],
[["abc",["a"=>2]], '{"0":"abc","1":{"a":2}}'],
];
}
}
@@ -1,48 +0,0 @@
<?php
/**
* Smarty PHPunit tests of modifier
*/
/**
* class for modifier tests
*
* @runTestsInSeparateProcess
* @preserveGlobalState disabled
* @backupStaticAttributes enabled
*/
class PluginModifierSubstrTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
}
public function testDefault()
{
$tpl = $this->smarty->createTemplate('string:{$v|substr:1}');
$tpl->assign("v", "abc");
$this->assertEquals("bc", $this->smarty->fetch($tpl));
}
public function testTwoArguments()
{
$tpl = $this->smarty->createTemplate('string:{$v|substr:1:1}');
$tpl->assign("v", "abc");
$this->assertEquals("b", $this->smarty->fetch($tpl));
}
public function testNegativeOffset()
{
$tpl = $this->smarty->createTemplate('string:{$v|substr:-1}');
$tpl->assign("v", "abc");
$this->assertEquals("c", $this->smarty->fetch($tpl));
}
public function testInConditional()
{
$tpl = $this->smarty->createTemplate('string:{if substr($v, -1) == "c"}good{else}bad{/if}');
$tpl->assign("v", "abc");
$this->assertEquals("good", $this->smarty->fetch($tpl));
}
}
@@ -57,7 +57,6 @@ class PhpFunctionTest extends PHPUnit_Smarty
public function testEmpty2()
{
$this->smarty->disableSecurity();
$this->smarty->registerPlugin('modifier', 'pass', 'pass');
$this->smarty->assign('var', array(null,
false,
(int) 0,
@@ -79,7 +78,6 @@ class PhpFunctionTest extends PHPUnit_Smarty
public function testEmpty3()
{
$this->smarty->disableSecurity();
$this->smarty->registerPlugin('modifier', 'pass', 'pass');
$this->smarty->assign('var', array(true,
(int) 1,
(float) 0.1,
@@ -116,7 +114,6 @@ class PhpFunctionTest extends PHPUnit_Smarty
public function testIsset1()
{
$this->smarty->disableSecurity();
$this->smarty->registerPlugin('modifier', 'pass', 'pass');
$this->smarty->assign('isNull', null);
$this->smarty->assign('isSet', 1);
$this->smarty->assign('arr', array('isNull' => null, 'isSet' => 1));
@@ -158,7 +155,7 @@ class PhpFunctionTest extends PHPUnit_Smarty
public function testIsset3($strTemplate, $result)
{
$this->smarty->disableSecurity();
$this->smarty->registerPlugin('modifier', 'intval', 'intval');
$this->smarty->assign('varobject', new TestIsset());
$this->smarty->assign('vararray', $vararray = array(
'keythatexists' => false,
@@ -199,105 +196,6 @@ class PhpFunctionTest extends PHPUnit_Smarty
array('{if isset($_varsimple{$key})}true{else}false{/if}', 'true'),
);
}
/**
* Tests various PHP functions (deprecated)
* @dataProvider dataVariousPHPFunctions
*/
public function testVariousPHPFunctions($strTemplate, $value, $expected) {
$this->smarty->disableSecurity();
$this->cleanDirs();
$this->smarty->assign('value', $value);
$this->assertEquals($expected, $this->smarty->fetch('string:' . $strTemplate));
}
/**
* Data provider for testIsset3
*/
public function dataVariousPHPFunctions()
{
return array(
array('{$a = count($value)}{$a}', array(1,2,3), '3'),
array('{$a = in_array("b", $value)}{$a}', array(1,'b',3), true),
array('{$a = strlen(uniqid())}{$a}', '', 13),
array('{$a = date("Y", $value)}{$a}', strtotime("01-01-2030"), 2030),
array('{$a = PhpFunctionTest::sayHi($value)}{$a}', 'mario', 'hi mario'),
array('{$a = pass($value)}{$a}', 'mario', 'mario'),
array('{$a = 1}{$b = Closure::fromCallable($value)}{$a}', 'strlen', 1),
);
}
public static function sayHi($value) {
return 'hi ' . $value;
}
/**
* Tests that each function that will not be supported in Smarty 5 does throw an E_USER_DEPRECATED notice.
* @dataProvider dataDeprecationNoticesForSmarty5
* @deprecated
*/
public function testDeprecationNoticesForSmarty5($strTemplateSource, $expected = '', $shouldTriggerDeprecationNotice = false) {
// this overrides the error reporting level set in \PHPUnit_Smarty::setUpSmarty
$previousErrorReporting = $this->smarty->error_reporting;
$this->smarty->setErrorReporting($previousErrorReporting | E_USER_DEPRECATED);
$this->smarty->assign('a', 'a');
$this->smarty->assign('ar', [1,2]);
$this->smarty->assign('f', 3.14);
$errorMessage = '';
try {
$output = $this->smarty->fetch('string:' . $strTemplateSource);
} catch (Exception $e) {
$errorMessage = $e->getMessage();
}
if ($shouldTriggerDeprecationNotice) {
$this->assertStringContainsString('Using unregistered function', $errorMessage);
} else {
$this->assertEquals($expected, $output);
$this->assertEquals('', $errorMessage);
}
$this->smarty->setErrorReporting($previousErrorReporting);
}
public function dataDeprecationNoticesForSmarty5()
{
return [
['{if empty($a)}{else}b{/if}', 'b', false],
['{json_encode($a)}', '"a"', false],
['{nl2br($a)}', 'a', false],
['{$a|nl2br}', 'a', false],
['{round($f, 1)}', '3.1', false],
['{$f|round}', '3', false],
['{str_repeat($a, 2)}', 'aa', false],
['{$a|str_repeat:3}', 'aaa', false],
['{$a|strip_tags}', 'a', false],
['{$a|strlen}', '1', false],
['{$a|substr:-1}', 'a', false],
['{$f|substr:-1}', '4', false],
['{$ar|count}', '2', false],
['{foreach "."|explode:$f as $n}{$n}{/foreach}', '314', false],
['{"-"|implode:$ar}', '1-2', false],
['{"-"|join:$ar}', '1-2', false],
['{$f|wordwrap:2:"k":true}', "3.k14", false],
['{$f|number_format:1:","}', "3,1", false],
['{if in_array(1, $ar)}yes{/if}', "yes", false],
['{if is_array($ar)}yes{/if}', "yes", false],
['{if time() gt 0}yes{/if}', "yes", false],
['{if array_chunk($ar, 2)}x{else}y{/if}', '', true],
['{$a|addslashes}', '', true],
['{$a|sha1}', '', true],
['{$a|get_parent_class}', '', true],
];
}
}
/**
-42
View File
@@ -1,42 +0,0 @@
<?php
// This takes the *.md files in changelog/ dir and inserts them
// right below the '## [Unreleased]' marker in CHANGELOG.md
$path_to_main_changelog = 'CHANGELOG.md';
$marker = '## [Unreleased]';
$changelog_files_pattern = 'changelog/*.md';
$new_version = $argv[1];
$file_contents = file_get_contents($path_to_main_changelog);
foreach (glob($changelog_files_pattern) as $filename) {
$content_to_insert = file_get_contents($filename);
if (!endsWithNewline($content_to_insert)) {
$content_to_insert .= "\n";
}
$file_contents = str_replace(
$marker,
$marker . $content_to_insert,
$file_contents
);
unlink($filename);
}
// add the version number and date
$file_contents = str_replace(
$marker,
$marker . sprintf("\n\n## [%s] - %s\n", $new_version, date('Y-m-d')),
$file_contents
);
file_put_contents($path_to_main_changelog, $file_contents);
function endsWithNewline($str): bool
{
return preg_match('/[\r\n]$/', $str) === 1;
}
@@ -1,11 +0,0 @@
<?php
// This takes the Smarty class file and updates the SMARTY_VERSION constant
$path_to_smarty_class = 'libs/Smarty.class.php';
$pattern = "/const SMARTY_VERSION = '[^']+'/";
$replacement = "const SMARTY_VERSION = '" . $argv[1] . "'";
$file_contents = preg_replace($pattern, $replacement, file_get_contents($path_to_smarty_class));
file_put_contents($path_to_smarty_class, $file_contents);