Skip to content

Commit 10d9b7d

Browse files
authored
Merge pull request #4 from php-etl/feature/adding-expressions
Adding some ucfirst, substr and strtolower expressions
2 parents 7049893 + 40ca2db commit 10d9b7d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public function getFunctions(): array
1212
return [
1313
ExpressionFunction::fromPhp('sprintf', 'format'),
1414
ExpressionFunction::fromPhp('trim', 'trim'),
15-
ExpressionFunction::fromPhp('str_replace', 'replace'),
15+
ExpressionFunction::fromPhp('ucfirst', 'capitalize'),
16+
ExpressionFunction::fromPhp('strtolower', 'toLowerCase'),
17+
ExpressionFunction::fromPhp('substr', 'search'),
18+
ExpressionFunction::fromPhp('strtoupper', 'toUpperCase'),
1619
new FileName('fileName'),
1720
new DateTime('dateTime'),
1821
new FormatDate('formatDate'),

0 commit comments

Comments
 (0)