From 2853cd363778005df069a5d92f27ae3938633971 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Wed, 3 Jun 2026 10:35:45 -0500 Subject: [PATCH] Adds a basic example --- .editorconfig | 8 +++++++ .mddoc.xml.dist | 4 ++++ README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++- example/example.php | 28 +++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 example/example.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..493b519 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +[*.php] +charset = utf-8 + +indent_style = tab +indent_size = 4 + +end_of_line = lf +insert_final_newline = true diff --git a/.mddoc.xml.dist b/.mddoc.xml.dist index 9447d1e..67176d1 100644 --- a/.mddoc.xml.dist +++ b/.mddoc.xml.dist @@ -15,6 +15,10 @@ DotNotationParser is a simple parser that will parse `foo.bar.baz` into `[ 'foo'
+
+ + +
diff --git a/README.md b/README.md index 589a07e..ecea5bc 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,58 @@ Install the latest version with: composer require 'quorum/dot-notation' ``` +## Example + +```php + 'foo bar.baz', + 'dots are accepted in quotes' => '"foo.bar".baz', + 'quotes are escaped with backslashes' => '"foo\"bar\"".baz', +]; + +foreach( $tests as $descr => $test ) { + echo sprintf("Parsing '%s'%s\n", + $test, + is_numeric($descr) ? '' : ' - ' . $descr); + + $parts = $parser->parse($test); + + echo sprintf("[ %s ]\n", implode(", ", array_map( + function ( $a ) { return var_export($a, true); }, + $parts))); + echo "\n"; +} + +``` + +``` +Parsing 'foo' +[ 'foo' ] + +Parsing 'foo.bar' +[ 'foo', 'bar' ] + +Parsing 'foo bar.baz' - spaces are allowed +[ 'foo bar', 'baz' ] + +Parsing '"foo.bar".baz' - dots are accepted in quotes +[ 'foo.bar', 'baz' ] + +Parsing '"foo\"bar\"".baz' - quotes are escaped with backslashes +[ 'foo"bar"', 'baz' ] + +``` + ## Documentation ### Class: Quorum\DotNotation\DotNotationParser @@ -53,4 +105,4 @@ quoted keys. ##### Returns: -- ***string[]*** +- ***string[]*** \ No newline at end of file diff --git a/example/example.php b/example/example.php new file mode 100644 index 0000000..731080d --- /dev/null +++ b/example/example.php @@ -0,0 +1,28 @@ + 'foo bar.baz', + 'dots are accepted in quotes' => '"foo.bar".baz', + 'quotes are escaped with backslashes' => '"foo\"bar\"".baz', +]; + +foreach( $tests as $descr => $test ) { + echo sprintf("Parsing '%s'%s\n", + $test, + is_numeric($descr) ? '' : ' - ' . $descr); + + $parts = $parser->parse($test); + + echo sprintf("[ %s ]\n", implode(", ", array_map( + function ( $a ) { return var_export($a, true); }, + $parts))); + echo "\n"; +}