This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/Rails/ArrayHelper/GlobalVar.php

31 lines
708 B
PHP
Raw Normal View History

2013-10-02 08:12:58 +02:00
<?php
namespace Rails\ArrayHelper;
class GlobalVar extends Base
{
protected
$_var_name,
$_key_name;
public function __construct($values, $var_name, $key_name)
{
$this->_var_name = $var_name;
$this->_key_name = $key_name;
$this->merge($values);
}
public function offsetSet($offset, $value)
{
global ${$this->_var_name};
if ($offset === null)
${$this->_var_name}[$this->_key_name][] = $value;
else
${$this->_var_name}[$this->_key_name][$offset] = $value;
}
protected function _get_array()
{
global ${$this->_var_name};
return ${$this->_var_name};
}
}