Parse Java properties files in PHP.
This class allows you to parse Java properties files or strings in PHP. It should be completely compliant with [the parsing rules of java.util.Properties](http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader).
<?php
class Classmarkets\JavaProperties implements \ArrayAccess
{
void loadResource($url, $streamContext = null);
void loadString($string);
array getAll();
}
<?php
$properties = new Classmarkets\JavaProperties;
$properties->loadString("foo: bar");
// OR: $properties->loadResource("http://mysite/legacy/app.properties");
var_export($properties->getAll());
var_export($properties['foo']);
yields:
array (
'foo' => 'bar',
)
loadResource
accepts any URL for which there is a supported protocol wrapper, including of course you're own registered streamWrappers. It takes a stream context as an optional second argument.
- PHP has to be compiled
--with-pcre-regex
allow_url_fopen = on
for network streams. This is implied by fopen. Refer to the docs for details.
Here are the required entries in your composer.json:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/classmarkets/JavaProperties.php"
}
],
"require": {
"classmarkets/javaproperties.php": "*"
}
}
After you have added them just run composer.phar update
. We currently do not have plans to publish this package on packagist, sorry.
- Escaped key-value-delimiters are not supported, e. g.
foo\:bar = baz
will not result in[ 'foo:bar' => 'baz' ]
, but[ 'foo\' => 'bar = baz' ]
. - Lines ending with multiple backslashes are not handled properly. They are treated as if they ended with exactly one backslash.
Patches welcome :)