classmarkets/javaproperties.php

This package is abandoned and no longer maintained. No replacement package was suggested.

A class for loading Java properties files in PHP

dev-master 2012-11-07 13:26 UTC

This package is auto-updated.

Last update: 2020-02-26 12:17:53 UTC


README

Build Status

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).

INTERFACE

<?php
class Classmarkets\JavaProperties implements \ArrayAccess
{
    void loadResource($url, $streamContext = null);
    void loadString($string);
    array getAll();
}

SYNOPSIS

<?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.

REQUIREMENTS

  • 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.

INSTALLATION WITH COMPOSER

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.

KNOWN LIMITATIONS

  • 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 :)