Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*.php]
charset = utf-8

indent_style = tab
indent_size = 4

end_of_line = lf
insert_final_newline = true
4 changes: 4 additions & 0 deletions .mddoc.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ DotNotationParser is a simple parser that will parse `foo.bar.baz` into `[ 'foo'
<section title="Installing">
<composer-install/>
</section>
<section title="Example">
<source name="example/example.php" lang="php"/>
<exec cmd="php example/example.php" format="code-block"/>
</section>
<section title="Documentation">
<file name="src/DotNotationParser.php"/>
</section>
Expand Down
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,58 @@ Install the latest version with:
composer require 'quorum/dot-notation'
```

## Example

```php
<?php

use Quorum\DotNotation\DotNotationParser;

require __DIR__ . '/../vendor/autoload.php';
Comment thread
donatj marked this conversation as resolved.

$parser = new DotNotationParser;

$tests = [
'foo',
'foo.bar',
'spaces are allowed' => '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
Expand Down Expand Up @@ -53,4 +105,4 @@ quoted keys.

##### Returns:

- ***string[]***
- ***string[]***
28 changes: 28 additions & 0 deletions example/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Quorum\DotNotation\DotNotationParser;

require __DIR__ . '/../vendor/autoload.php';
Comment thread
donatj marked this conversation as resolved.

$parser = new DotNotationParser;

$tests = [
'foo',
'foo.bar',
'spaces are allowed' => '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";
}