Advertisement
fruffl

struct test

Nov 23rd, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1.     class test{}
  2.    
  3.     class a extends \ILLI\Base\Component\Structure\aStructure
  4.     {
  5.         private $__test = NULL;
  6.        
  7.         public function __construct()
  8.         {
  9.             $this->__test = new Test;
  10.            
  11.             $this->tStructure_define('functionName', [
  12.                 Prop::FLAG  => Flag::REQUIRED | Flag::EXPECT_WHITELIST,
  13.                 Prop::INITIAL   => NULL,
  14.                 Prop::TYPE  => ['string'],
  15.                 Prop::WHITELIST => ['foo', 'bar', $this->__test], // Flag::EXPECT_WHITELIST set: foo is allowed!
  16.                 Prop::BLACKLIST => ['foo', 'bob'],
  17.                 Prop::ON_COMPARE    => function($value)
  18.                 {
  19.                 },
  20.                 Prop::ON_SET    => [
  21.                     function($value)
  22.                     {
  23.                         //throw new \Exception('boo');
  24.                         return $value;
  25.                     }
  26.                 ],
  27.             ]);
  28.            
  29.             $this->tStructure_define('name', 'string');
  30.             $this->tStructure_define('lastName');
  31.         }
  32.        
  33.         public function validate($__field, $__value)
  34.         {
  35.             switch($__field):
  36.                 case 'name':
  37.                     return substr($__value, 0, 2) !== '__';
  38.                     break;
  39.                 case 'lastName':
  40.                     return $__value !== 'CH';
  41.                     break;
  42.             endswitch;
  43.         }
  44.     }
  45.    
  46.     $a = new a;
  47.     $a->functionName = 'bab'; // ValueComparisonWhitelistException
  48.     //$a->functionName = new Test; // ValueExpectedException: strict compare
  49.     var_dump($a);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement