# Message

> 🔔 Subscribe to the [newsletter](https://chv.to/chevere-newsletter) to don't miss any update regarding Chevere.

![Chevere](chevere.svg)

[![Build](https://img.shields.io/github/actions/workflow/status/chevere/message/test.yml?branch=1.0&style=flat-square)](https://github.com/chevere/message/actions)
![Code size](https://img.shields.io/github/languages/code-size/chevere/message?style=flat-square)
[![Apache-2.0](https://img.shields.io/github/license/chevere/message?style=flat-square)](LICENSE)
[![PHPStan](https://img.shields.io/badge/PHPStan-level%209-blueviolet?style=flat-square)](https://phpstan.org/)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchevere%2Fmessage%2F1.0)](https://dashboard.stryker-mutator.io/reports/github.com/chevere/message/1.0)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=chevere_message&metric=alert_status)](https://sonarcloud.io/dashboard?id=chevere_message)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=chevere_message&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=chevere_message)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=chevere_message&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=chevere_message)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=chevere_message&metric=security_rating)](https://sonarcloud.io/dashboard?id=chevere_message)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=chevere_message&metric=coverage)](https://sonarcloud.io/dashboard?id=chevere_message)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=chevere_message&metric=sqale_index)](https://sonarcloud.io/dashboard?id=chevere_message)
[![CodeFactor](https://www.codefactor.io/repository/github/chevere/message/badge)](https://www.codefactor.io/repository/github/chevere/message)

![Message](.github/banner/message-logo.svg)

## Summary

Message enables to create strings with template tags support.

## Installing

Message is available through [Packagist](https://packagist.org/packages/chevere/message) and the repository source is at [chevere/message](https://github.com/chevere/message).

```sh
composer require chevere/message
```

## Creating a Message

Use function `message` to create a Message by passing the message template. Use named named arguments to define replacement pairs.

```php
use function Chevere\Message\message;

$message = message(
    'Hello, **%tag%**!',
    tag: 'World'
);
```

🪄 Message supports `%tag%`, `{{tag}}` and `{{ tag }}` replacement template tags.

## To string

The `__toString` method return the message with translated placeholders.

```php
$message->__toString();
// Hello, **World**!
```

## Utility methods

### Template

Use `template` method to return the message template.

```php
$message->replacements();
// Hello, **%tag%**!
```

### Replacements

Use `replacements` method to read message replacement pairs.

```php
$message->replacements();
// ['tag' => 'World']
```

## Documentation

Documentation is available at [chevere.org](https://chevere.org/packages/message).

## License

Copyright [Rodolfo Berrios A.](https://rodolfoberrios.com/)

Chevere is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
