<?php
 
/**
 
 * @author Thomas Schaefer
 
 * @mail [email protected]
 
*/
 
class TypedStruct
 
{
 
 
    private $activeClass = "";
 
 
    /**
 
     * TypedStructProperties
 
     * @var static array
 
     */
 
    private static $TypedStructProperties = array();
 
 
 
    /**
 
     * hasProperty
 
     *
 
     * @param string $k
 
     * @return bool
 
     *
 
     */
 
    public function hasProperty($k) {
 
        $r = new ReflectionClass($this);
 
        $this->activeClass = $r->name;
 
        if(!isset(TypedStruct::$TypedStructProperties[$this->activeClass])){
 
            foreach($r->getProperties() as $p){
 
                $a=substr($p->name,strpos($p->name,"_")+1);
 
                $b=substr($p->name,0,strpos($p->name,"_"));
 
                if(strlen($b)) TypedStruct::$TypedStructProperties[$this->activeClass][$a] = $b;
 
            }
 
        }
 
        return array_key_exists( $k, TypedStruct::$TypedStructProperties[$this->activeClass] );
 
    }
 
 
 
    /**
 
     * getPropertyType
 
     *
 
     * @param string $k
 
     * @return string return type of object property type
 
     *
 
     */
 
    public function getPropertyType($k) {
 
 
        if (!array_key_exists( $k, TypedStruct::$TypedStructProperties[$this->activeClass] )) {
 
            return false;
 
        }
 
        return TypedStruct::$TypedStructProperties[$this->activeClass][$k];
 
    }
 
 
 
    /**
 
     * getProperties
 
     * @desc used by SerializeTypedStruct
 
     * @return array
 
     */
 
    public function getProperties(){
 
        return TypedStruct::$TypedStructProperties[$this->activeClass];
 
    }
 
 
    protected function __set($key,$value) {
 
        $this->{$key} = $value;
 
    }
 
 
    protected function __get($key) {
 
        return $this->{$key};
 
    }
 
 
}
 
 
 |