<?php
/**
*
* QParameter
* @package
* @subpackage
* @author Thomas Schäfer
* @since 26.07.2008 13:30:48
* @desc
*/
class QParameter {
const GET = 1;
const POST = 2;
private $register = array("has"=>true, "add"=>true, "set"=>true, "get"=>true, "merge"=>true);
/**
* holder of the properties
* @var $properties
*/
private $properties;
public static function getMethodType($word) {
$tmp = explode("_", QBaseClass::underscore($word));
$methodType = new stdClass();
$methodType->length = strlen($tmp[0]);
$methodType->type = $tmp[0];
$methodType->name = substr($word, $methodType->length);
return $methodType;
}
public function addRegister($methodType) {
$this->register[$methodType] = true;
}
/**
* does the magic
*/
public function __call($funcName, $args) {
$method = self::getMethodType($funcName);
if(empty($this->register[$method->type])) {
throw new QCoreException("Unsupported method type ".$method->type." for ".$funcName.". Supported methods: ".implode(", ", array_keys($this->register)));
return false;
}
switch ($method->type)
{
case "has":
$num = count($args);
switch($num) {
case 1:
return (isset($this->properties[$method->name][$args[0]])?true:false);
default:
return (isset($this->properties[$method->name])?true:false);
}
break;
case "add":
$this->properties[$method->name][] = $args[0];
return $this;
case "merge":
foreach($args[0] as $key => $value) {
$this->properties[$method->name][$key] = $value;
}
return $this;
case "set":
$num = count($args);
switch($num){
case 1:
$this->properties[$method->name] = $args[0];
break;
case 2:
$this->properties[$method->name][$args[0]] = $args[1];
break;
case 3:
$this->properties[$method->name][$args[0]][$args[1]] = $args[2];
break;
}
return $this;
case "get":
if(empty($args) and isset($this->properties[$method->name])) {
return $this->properties[$method->name];
} elseif(isset($args) and isset($this->properties[$method->name][$args[0]]) ) {
return $this->properties[$method->name][$args[0]];
} else {
return $this->properties[$method->name];
}
break;
}
}
}