PHP Classes

File: TypedStruct.class.php

Recommend this page to a friend!
  Classes of Tom Schaefer   TypeSafeStruct   TypedStruct.class.php   Download  
File: TypedStruct.class.php
Role: Class source
Content type: text/plain
Description: Base class
Class: TypeSafeStruct
Manipulate type safe objects
Author: By
Last change: chg
Date: 15 years ago
Size: 1,537 bytes
 

Contents

Class file image Download
<?php
/**
 * @author Thomas Schaefer
 * @mail scaphare@gmail.com
*/
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};
    }

}