Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

classmarkets/JavaProperties.php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaProperties.php

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

About

Parse Java properties files in PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages