Skip to content

Commit 23c1596

Browse files
authored
Merge pull request #30 from danhunsaker/feature/register-formats
Added registerFormat Method
2 parents 776ba4a + 405032d commit 23c1596

24 files changed

+292
-195
lines changed

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ matrix:
1313
- php: 5.4
1414
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
1515

16-
addons:
17-
apt:
18-
packages:
19-
- php5-msgpack
20-
2116
before_script:
2217
- travis_retry composer self-update
2318
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ $parser = new Parser();
307307
$parsed = $parser->parse('RAW PAYLOAD DATA', new CustomFormatter());
308308
```
309309

310+
##### Register the CustomFormatter
311+
312+
```php
313+
use Acme\Formatters\CustomFormatter;
314+
315+
$parser = new Parser();
316+
$parser->registerFormat('application/x-custom-format', 'Acme\Formatters\CustomFormatter');
317+
$parser->payload('application/x-custom-format');
318+
```
319+
310320
Testing
311321
-------
312322

examples/MSGPack.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
echo "<pre>";
2121
print_r($parsed);
22-
echo "</pre>";
22+
echo "</pre>";

examples/XML.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "../vendor/autoload.php";
44

55
use Nathanmac\Utilities\Parser\Parser;
6+
67
$parser = new Parser();
78

89
echo "<h1>XML Example</h1>";

src/Exceptions/ParserException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
* @author Nathan Macnamara <nathan.macnamara@outlook.com>
1212
* @license https://github.com/nathanmac/Parser/blob/master/LICENSE.md MIT
1313
*/
14-
class ParserException extends Exception {}
14+
class ParserException extends Exception
15+
{
16+
}

src/Facades/Parser.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ class Parser extends Facade
1818
*
1919
* @return string
2020
*/
21-
protected static function getFacadeAccessor() { return 'Parser'; }
22-
}
21+
protected static function getFacadeAccessor()
22+
{
23+
return 'Parser';
24+
}
25+
}

src/Formats/BSON.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ class BSON implements FormatInterface
1818
*
1919
* @param string $payload
2020
*
21+
* @throws ParserException
2122
* @return array
2223
*
23-
* @throws ParserException
2424
*/
2525
public function parse($payload)
2626
{
2727
if (function_exists('bson_decode')) {
2828
if ($payload) {
2929
$bson = bson_decode(trim($payload));
30-
if (! $bson)
30+
if ( ! $bson) {
3131
throw new ParserException('Failed To Parse BSON');
32+
}
3233
return $bson;
3334
}
34-
return array();
35+
return [];
3536
}
3637

3738
throw new ParserException('Failed To Parse BSON - Supporting Library Not Available');

src/Formats/JSON.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ class JSON implements FormatInterface
1818
*
1919
* @param string $payload
2020
*
21+
* @throws ParserException
2122
* @return array
2223
*
23-
* @throws ParserException
2424
*/
2525
public function parse($payload)
2626
{
2727
if ($payload) {
2828
$json = json_decode(trim($payload), true);
29-
if (! $json)
29+
if ( ! $json) {
3030
throw new ParserException('Failed To Parse JSON');
31+
}
3132
return $json;
3233
}
33-
34-
return array();
34+
35+
return [];
3536
}
3637
}

src/Formats/MSGPack.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ class MSGPack implements FormatInterface
1818
*
1919
* @param string $payload
2020
*
21+
* @throws ParserException
2122
* @return array
2223
*
23-
* @throws ParserException
2424
*/
2525
public function parse($payload)
2626
{
2727
if (function_exists('msgpack_unpack')) {
2828
if ($payload) {
2929
$msg = msgpack_unpack(trim($payload));
30-
if (! $msg)
30+
if ( ! $msg) {
3131
throw new ParserException('Failed To Parse MSGPack');
32+
}
3233
return $msg;
3334
}
34-
return array();
35+
return [];
3536
}
3637

3738
throw new ParserException('Failed To Parse MSGPack - Supporting Library Not Available');

src/Formats/QueryStr.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function parse($payload)
2424
parse_str(trim($payload), $querystr);
2525
return $querystr;
2626
}
27-
28-
return array();
27+
28+
return [];
2929
}
3030
}

0 commit comments

Comments
 (0)