first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

View File

@ -0,0 +1,57 @@
# ChangeLog
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [3.0.1] - 2023-08-31
### Changed
* Warnings from `file_put_contents()` are now suppressed
## [3.0.0] - 2023-02-03
### Removed
* This component is no longer supported on PHP 7.3, PHP 7.4 and PHP 8.0
## [2.0.4] - 2020-10-26
### Fixed
* `SebastianBergmann\Template\Exception` now correctly extends `\Throwable`
## [2.0.3] - 2020-09-28
### Changed
* Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3`
## [2.0.2] - 2020-06-26
### Added
* This component is now supported on PHP 8
## [2.0.1] - 2020-06-15
### Changed
* Tests etc. are now ignored for archive exports
## [2.0.0] - 2020-02-07
### Changed
* The `Text_Template` class was renamed to `SebastianBergmann\Template\Template`
### Removed
* Removed support for PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6, PHP 7.0, PHP 7.1, and PHP 7.2
[3.0.1]: https://github.com/sebastianbergmann/php-text-template/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/sebastianbergmann/php-text-template/compare/2.0.4...3.0.0
[2.0.4]: https://github.com/sebastianbergmann/php-text-template/compare/2.0.3...2.0.4
[2.0.3]: https://github.com/sebastianbergmann/php-text-template/compare/2.0.2...2.0.3
[2.0.2]: https://github.com/sebastianbergmann/php-text-template/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/sebastianbergmann/php-text-template/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/sebastianbergmann/php-text-template/compare/1.2.1...2.0.0

View File

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2009-2023, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,17 @@
[![Latest Stable Version](https://poser.pugx.org/phpunit/php-text-template/v/stable.png)](https://packagist.org/packages/phpunit/php-text-template)
[![CI Status](https://github.com/sebastianbergmann/php-text-template/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/php-text-template/actions)
[![Type Coverage](https://shepherd.dev/github/sebastianbergmann/php-text-template/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/php-text-template)
[![codecov](https://codecov.io/gh/sebastianbergmann/php-text-template/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/php-text-template)
# php-text-template
## Installation
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
composer require phpunit/php-text-template
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
composer require --dev phpunit/php-text-template

View File

@ -0,0 +1,30 @@
# Security Policy
If you believe you have found a security vulnerability in the library that is developed in this repository, please report it to us through coordinated disclosure.
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
Instead, please email `sebastian@phpunit.de`.
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
* The type of issue
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
## Web Context
The library that is developed in this repository was either extracted from [PHPUnit](https://github.com/sebastianbergmann/phpunit) or developed specifically as a dependency for PHPUnit.
The library is developed with a focus on development environments and the command-line. No specific testing or hardening with regard to using the library in an HTTP or web context or with untrusted input data is performed. The library might also contain functionality that intentionally exposes internal application data for debugging purposes.
If the library is used in a web application, the application developer is responsible for filtering inputs or escaping outputs as necessary and for verifying that the used functionality is safe for use within the intended context.
Vulnerabilities specific to the use outside a development context will be fixed as applicable, provided that the fix does not have an averse effect on the primary use case for development purposes.

View File

@ -0,0 +1,45 @@
{
"name": "phpunit/php-text-template",
"description": "Simple template engine.",
"type": "library",
"keywords": [
"template"
],
"homepage": "https://github.com/sebastianbergmann/php-text-template/",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-text-template/issues",
"security": "https://github.com/sebastianbergmann/php-text-template/security/policy"
},
"config": {
"platform": {
"php": "8.1.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"prefer-stable": true,
"require": {
"php": ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^10.0"
},
"autoload": {
"classmap": [
"src/"
]
},
"extra": {
"branch-alias": {
"dev-main": "3.0-dev"
}
}
}

View File

@ -0,0 +1,108 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-text-template.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Template;
use function array_keys;
use function array_merge;
use function file_get_contents;
use function file_put_contents;
use function is_file;
use function sprintf;
use function str_replace;
final class Template
{
private string $template = '';
private string $openDelimiter;
private string $closeDelimiter;
/**
* @psalm-var array<string,string>
*/
private array $values = [];
/**
* @throws InvalidArgumentException
*/
public function __construct(string $file = '', string $openDelimiter = '{', string $closeDelimiter = '}')
{
$this->setFile($file);
$this->openDelimiter = $openDelimiter;
$this->closeDelimiter = $closeDelimiter;
}
/**
* @throws InvalidArgumentException
*/
public function setFile(string $file): void
{
if (is_file($file)) {
$this->template = file_get_contents($file);
return;
}
$distFile = $file . '.dist';
if (is_file($distFile)) {
$this->template = file_get_contents($distFile);
return;
}
throw new InvalidArgumentException(
sprintf(
'Failed to load template "%s"',
$file
)
);
}
/**
* @psalm-param array<string,string> $values
*/
public function setVar(array $values, bool $merge = true): void
{
if (!$merge || empty($this->values)) {
$this->values = $values;
return;
}
$this->values = array_merge($this->values, $values);
}
public function render(): string
{
$keys = [];
foreach (array_keys($this->values) as $key) {
$keys[] = $this->openDelimiter . $key . $this->closeDelimiter;
}
return str_replace($keys, $this->values, $this->template);
}
/**
* @codeCoverageIgnore
*/
public function renderTo(string $target): void
{
if (!@file_put_contents($target, $this->render())) {
throw new RuntimeException(
sprintf(
'Writing rendered result to "%s" failed',
$target
)
);
}
}
}

View File

@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-text-template.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Template;
use Throwable;
interface Exception extends Throwable
{
}

View File

@ -0,0 +1,14 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-text-template.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Template;
final class InvalidArgumentException extends \InvalidArgumentException implements Exception
{
}

View File

@ -0,0 +1,16 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-text-template.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Template;
use InvalidArgumentException;
final class RuntimeException extends InvalidArgumentException implements Exception
{
}