Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/library/Fiktiv/Model/Abstract.php
2010-10-02 15:35:34 +02:00

59 lines
No EOL
1.2 KiB
PHP

<?php
abstract class Fiktiv_Model_Abstract
{
protected $_default = array();
public function __construct($data = array())
{
$data = (array)$data;
$data = array_merge($this->_default, array_intersect_key($data, $this->_default));
$this->setAttribs($data);
}
public function __call($name, $args)
{
// getX methods
if ('get' == substr($name,0,3)) {
$property = substr($name, 3);
$property[0] = strtolower($property[0]);
if (isset($this->_data[$property]))
return $this->_data[$property];
}
}
public function __set($name, $value)
{
$methodName = 'set' . ucfirst($name);
if (method_exists($this, $methodName)) {
return $this->$methodName($value);
}
if (array_key_exists($name, $this->_data))
return $this->_data[$name] = $value;
}
// Direct access to read data fields
public function __get($name)
{
if (isset($this->_data[$name])) {
return $this->_data[$name];
}
}
public function setAttribs(array $data)
{
foreach ($data as $key => $value) {
$this->$key = $value;
}
}
}