Advertisement
fruffl

Callable Constants

Aug 23rd, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. <?PHP
  2.     FINAL CLASS eUserInfoComponents EXTENDS \ILLI\Core\Enum IMPLEMENTS \ILLI\Core\iProviderBitwise
  3.     {
  4.         /**
  5.          * @const int ILLI\System\UserInfo::$username
  6.          */
  7.         const USERNAME      = 1;
  8.        
  9.         /**
  10.          * @const int ILLI\System\UserInfo::$password
  11.          */
  12.         const PASSWORD      = 2;
  13.        
  14.         /**
  15.          * @const int ILLI\System\UserInfo::$username
  16.          *      | ILLI\System\UserInfo::$password
  17.          */
  18.         const PASSPORT      = 4;
  19.  
  20.  
  21.  
  22.         const MY_TEST       = 3;
  23.     }
  24.  
  25.  
  26.  
  27.  
  28.     NAMESPACE ILLI\System;
  29.     CLASS UserInfo EXTENDS \ILLI\Core\Table IMPLEMENTS \ILLI\Core\iProviderArrayList
  30.     {
  31.         const USERNAME_PASSWORD_DELIMETER   = ':';
  32.         const PASSPORT_DELIMETER        = '@';
  33.        
  34.         private $__UserInfoComponents       = NULL;
  35.        
  36.         public function __construct(array $config = array())
  37.         {
  38.             $this->__UserInfoComponents = eUserInfoComponents::instanceGet();
  39.            
  40.             $default = [
  41.                 'username'      => '',
  42.                 'password'      => '',
  43.                 'passport'      => ''
  44.             ];
  45.            
  46.             $config += $default;
  47.             parent::__construct($config);
  48.            
  49.             $self = $this;
  50.            
  51.             $this
  52.             ->filterRegisterEventClosure(\ILLI\Core\eFilter::ARGUMENTS, 'ILLI\Core\Table::__set', function($data) use ($self)
  53.             {
  54.                 $index = $data['index'];
  55.                 $value = $data['value'];
  56.                 switch($index):
  57.                     case 'username':
  58.                         $this->passport = $value.static::USERNAME_PASSWORD_DELIMETER.$this->password;
  59.                         break;
  60.                     case 'password':
  61.                         $this->passport = $this->username.static::USERNAME_PASSWORD_DELIMETER.$value;
  62.                         break;
  63.                     case 'passport':
  64.                         $value = $value.static::PASSPORT_DELIMETER;
  65.                         break;
  66.                 endswitch;
  67.                
  68.                 return ['index' => $index, 'value' => $value];
  69.             });
  70.         }
  71.         public function __call($name, array $args = array())
  72.         {  
  73.             if(TRUE === $this->adapterTriggerExists(__METHOD__))
  74.                 return $this->adapterCallAlias(__METHOD__, $args);
  75.            
  76.             $filtered   = $this->filterApply(\ILLI\Core\eFilter::METHOD, __METHOD__, ['method' => $name, 'args' => $args]);
  77.             $name       = $filtered['method'];
  78.             $args       = $filtered['args'];
  79.            
  80.             $c = $this->__UserInfoComponents;
  81.             $value = '';
  82.            
  83.             foreach($c::$name()->enumGetVariablesArray() as $index)
  84.             {
  85.                 $result = $this->$index;
  86.                 $value .= $result;
  87.             }
  88.            
  89.             $this->observerNotify(__METHOD__, $name, $value, $args);
  90.            
  91.             $value = $this->filterApply(\ILLI\Core\eFilter::RESULT, __METHOD__, $value);
  92.            
  93.             return $value;
  94.         }
  95.     }
  96.  
  97.  
  98. $user = new UserInfo;
  99. $user->username = 'baz';
  100. $user->password = '$s:@!ioe';
  101. print $user->passport(); // baz:$s:@!ioe@
  102. print $user->myTest(); // baz$s:@!ioe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement