<?php
/**
* PWF Properties object
* The object is generated throught the given file and the file should be in the format of
* key:value
* or
* key:key1=value1&key2=value2
* comments are lines started with //
* @copyright Copyright (c) 2012, PWF
* @license http://phpwebframework.com/License
* @version PWF_0.3.0
*/
class _Properties
{
private $properties = array();
public function __construct($propertiesFile)
{
$fileLines = _File::linesToArray($propertiesFile);
if(count($fileLines > 0))
{
foreach ($fileLines as $line)
{
$specialReplacement = false;
if(_String::contains($line, "\&") || _String::contains($line, "\=") || _String::contains($line, "\:"))
{
$line = _Core_FrontController::internalReplacement($line);
$specialReplacement = true;
}
if(_String::contains($line, ":") && !_String::startsWith($line, "//"))
{
$key = _String::trim(_String::beforeFirst($line, ":"));
$value = _String::trim(_String::afterFirst($line, ":"));
if(_String::contains($value, "="))
{
mb_parse_str($value,$result);
if($specialReplacement)
{
foreach ($result as $id => $val)
{
$this->properties[_Core_FrontController::internalRestoration($key)][_Core_FrontController::internalRestoration($id)] = _Core_FrontController::internalRestoration($val);
}
}
else
{
$this->properties[$key] = $result;
}
}
else
{
if($specialReplacement)
{
$this->properties[_Core_FrontController::internalRestoration($key)] = _Core_FrontController::internalRestoration($value);
}
else
{
$this->properties[$key] = $value;
}
}
}
}
}
}
/**
* Returns if there is a property with the given key
* @param string $key
*/
public function containsKey($key)
{
return isset($this->properties[$key]);
}
/**
* Retruns the value of the property with the given key or null if the key don't exists
* @param string $key
* @return string,null
*/
public function get($key)
{
if($this->containsKey($key))
{
return $this->properties[$key];
}
else
{
return null;
}
}
/**
* Sets the value of the property with the given key
* @param string $key
* @param string $value
*/
public function set($key,$value)
{
$this->properties[$key] = $value;
}
}
?>