Skip to content

Commit 40ca2db

Browse files
committed
Added a documentation for functions
1 parent d9031f4 commit 40ca2db

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# String Expression Language
2+
This package extends the [ExpressionLanguage](https://symfony.com/doc/current/components/expression_language.html) component of Symfony to compile and evaluate arrays with custom functions.
3+
4+
# Installation
5+
```
6+
composer require php-etl/string-expression-language
7+
```
8+
9+
# Usage
10+
You can use these expressions in your configuration files as in the following example :
11+
```yaml
12+
foo: '@=format("%s", "output")'
13+
```
14+
15+
# List of available functions
16+
17+
## Generic functions
18+
* `format(string $format, mixed ...$values) : string` => Return a formatted string
19+
* `trim(string $string, string $characters = " \n\r\t\v\x00") : string` => Strip whitespace (or other characters) from the beginning and end of a string
20+
* `capitalize(string $string) : string` => Make a string's first character uppercase
21+
* `toLowerCase(string $string) : string` => Make a string lowercase
22+
* `search(string $string, int $offset, ?int $length = null) : string` => Return part of a string
23+
* `toUpperCase(string $string) : string` => Make a string uppercase
24+
* `fileName(string $string) : string` => Returns information about a file path
25+
* `dateTime(string $string) : string` => Returns new DateTimeImmutable object formatted according to the specified format
26+
* `formatDate(string $string) : string` => Returns date formatted according to given format

src/StringExpressionLanguageProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public function getFunctions(): array
1212
return [
1313
ExpressionFunction::fromPhp('sprintf', 'format'),
1414
ExpressionFunction::fromPhp('trim', 'trim'),
15-
ExpressionFunction::fromPhp('ucfirst'),
16-
ExpressionFunction::fromPhp('strtolower'),
17-
ExpressionFunction::fromPhp('substr'),
18-
ExpressionFunction::fromPhp('strtoupper'),
15+
ExpressionFunction::fromPhp('ucfirst', 'capitalize'),
16+
ExpressionFunction::fromPhp('strtolower', 'toLowerCase'),
17+
ExpressionFunction::fromPhp('substr', 'search'),
18+
ExpressionFunction::fromPhp('strtoupper', 'toUpperCase'),
1919
new FileName('fileName'),
2020
new DateTime('dateTime'),
2121
new FormatDate('formatDate'),

0 commit comments

Comments
 (0)