Oto moje skrypty (init.php):
<?php
require_once(dirname(__FILE__).'/PhpType.class.php'); require_once(dirname(__FILE__).'/ArrayType.class.php'); require_once(dirname(__FILE__).'/BooleanType.class.php'); require_once(dirname(__FILE__).'/CallableType.class.php'); require_once(dirname(__FILE__).'/FloatType.class.php'); require_once(dirname(__FILE__).'/IntType.class.php'); require_once(dirname(__FILE__).'/NullType.class.php'); require_once(dirname(__FILE__).'/ObjectType.class.php'); require_once(dirname(__FILE__).'/ResourceType.class.php'); require_once(dirname(__FILE__).'/ScalarType.class.php'); require_once(dirname(__FILE__).'/StringType.class.php'); require_once(dirname(__FILE__).'/EBadType.class.php');
?>
PhpType.class.php
<?php
abstract class PhpType
{
protected $_var;
abstract protected function _check();
public function __construct($_var)
{
$this->_var=$_var;
if(!$this->_check()) throw new EBadType('Bad Type');
}
public function __get($_name)
{
return $this->_var;
}
public function __set($_name, $_val)
{
$ret=$this->_var;
$this->_var=$_val;
return $ret;
}
}
?>
EBadType.class.php
<?php
class EBadType extends Exception
{
}
?>
IntType.class.php
<?php
class IntType extends PhpType
{
protected function _check()
{
}
}
?>
I tak dalej już idą typy. Jeżeli chcecie całość to proszę pisać na pw, a wyśle spakowane na maila.
Tutaj test
<?php
function requiresint(IntType $_int)
{
$_int->var=8;
}
require_once('types/init.php');
print \"IntType(5)n\"; $int=new IntType(5);
print \"ArrayType(array(10))n\"; $arr=new ArrayType
(array(10
)); print \"BooleanType(TRUE)n\"; $bln=new BooleanType(TRUE);
try
{
print \"ResourceType(NULL)n\"; $res=new ResourceType(NULL);
}
catch (EBadType $e)
{
print \"nError catchedn\"; }
requiresint($int); // OK
requiresint($bln); // BŁĄD php
?>
Proszę o ocene i ewentualne komentarze, pomysły.