Template with placeholders that may be filled by real data

This commit is contained in:
Meritoo
2019-04-02 20:18:23 +02:00
parent 8a94241eb8
commit 0b74f8da6f
8 changed files with 645 additions and 3 deletions

View File

@@ -0,0 +1,36 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Meritoo\Common\Exception\ValueObject\Template;
use Exception;
/**
* An exception used while content of template is invalid
*
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class InvalidContentException extends Exception
{
/**
* Creates an exception
*
* @param string $content Invalid content of template
* @return InvalidContentException
*/
public static function create(string $content): InvalidContentException
{
$template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
$message = sprintf($template, $content);
return new static($message);
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* (c) Meritoo.pl, http://www.meritoo.pl
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Meritoo\Common\Exception\ValueObject\Template;
use Exception;
/**
* An exception used while there is not enough values to fill all placeholders in template
*
* @author Meritoo <github@meritoo.pl>
* @copyright Meritoo <http://www.meritoo.pl>
*/
class NotEnoughValuesException extends Exception
{
/**
* Creates an exception
*
* @param string $content Invalid content of template
* @param int $valuesCount Count of values
* @param int $placeholdersCount Count of placeholders
* @return NotEnoughValuesException
*/
public static function create(string $content, int $valuesCount, int $placeholdersCount): NotEnoughValuesException
{
$template = 'Not enough values (%d) to fill all placeholders (%d) in template \'%s\'. Did you provide all'
. ' required values?';
$message = sprintf($template, $valuesCount, $placeholdersCount, $content);
return new static($message);
}
}