https://github.com/chevere/message
Strings with template tags support
https://github.com/chevere/message
chevere php php-library
Last synced: about 1 year ago
JSON representation
Strings with template tags support
- Host: GitHub
- URL: https://github.com/chevere/message
- Owner: chevere
- License: apache-2.0
- Created: 2023-11-30T18:25:33.000Z (over 2 years ago)
- Default Branch: 1.0
- Last Pushed: 2025-03-06T20:45:48.000Z (over 1 year ago)
- Last Synced: 2025-05-08T19:12:05.139Z (about 1 year ago)
- Topics: chevere, php, php-library
- Language: PHP
- Homepage: https://chevere.org/packages/message
- Size: 66.4 KB
- Stars: 6
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Message

[](https://github.com/chevere/message/actions)

[](LICENSE)
[](https://phpstan.org/)
[](https://dashboard.stryker-mutator.io/reports/github.com/chevere/message/1.0)
[](https://sonarcloud.io/dashboard?id=chevere_message)
[](https://sonarcloud.io/dashboard?id=chevere_message)
[](https://sonarcloud.io/dashboard?id=chevere_message)
[](https://sonarcloud.io/dashboard?id=chevere_message)
[](https://sonarcloud.io/dashboard?id=chevere_message)
[](https://sonarcloud.io/dashboard?id=chevere_message)
[](https://www.codefactor.io/repository/github/chevere/message)
## 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.