public function _getTorpor()
 {
     if (is_null($this->_torpor)) {
         $this->_setTorpor(Torpor::getInstance());
     }
     return $this->_torpor;
 }
Exemple #2
0
 public function __construct()
 {
     $args = func_get_args();
     $torpor = null;
     foreach ($args as $index => $arg) {
         if ($arg instanceof Torpor) {
             $torpor = $arg;
             unset($args[$index]);
             break;
         }
     }
     $this->_setTorpor($torpor instanceof Torpor ? $torpor : Torpor::getInstance());
     $gridName = get_class($this);
     if ($prefix = $this->Torpor()->typedGridClassesPrefix()) {
         $gridName = substr($gridName, strlen($prefix));
     }
     if (!$this->Torpor()->supportedGrid($gridName)) {
         $this->throwException('Could not resolve grid type from class name "' . get_class($this) . '"');
     }
     $this->_setObjName($gridName);
     // $gridPrototype = $this->Torpor()->_newGrid( $gridName, Torpor::DEFAULT_GRID_CLASS );
     $this->Torpor()->_newGridColumns($this);
     $this->Torpor()->_newGridParameters($this);
     // Look at the remaining arguments, and see if they match the primary key length of this
     // grid, populating in order.
     $primaryKey = $this->primaryKey();
     if (!is_array($primaryKey)) {
         $primaryKey = array($primaryKey);
     }
     // Doing this via array_values resets any index gaps resuting from the Torpor object
     // search and subsequent unset() calls above.
     // This pattern of invocation assumes that all keys will be passed in the order in
     // which they are defined in the XML (and/or that there's only 1, which will be the
     // most common case).
     foreach (array_values($args) as $index => $arg) {
         $primaryKey[$index]->setData($arg);
     }
     $this->OnNew();
 }
Exemple #3
0
 public function __construct()
 {
     $args = func_get_args();
     $torpor = null;
     foreach ($args as $index => $arg) {
         if ($arg instanceof Torpor) {
             $torpor = $arg;
             unset($args[$index]);
             break;
         }
     }
     $this->_setTorpor($torpor instanceof Torpor ? $torpor : Torpor::getInstance());
     $gridTypeName = get_class($this);
     if ($prefix = $this->Torpor()->typedGridClassesPrefix()) {
         $gridTypeName = substr($gridTypeName, strlen($prefix));
     }
     $gridTypeName = substr($gridTypeName, 0, -1 * strlen(Torpor::OPERATION_GET_SET));
     if (!$this->Torpor()->supportedGrid($gridTypeName)) {
         $this->throwException('Could not resolve grid type from class name "' . get_class($this) . '"');
     }
     $this->setType($gridTypeName);
     foreach ($args as $arg) {
         if ($arg instanceof CriteriaBase) {
             $this->addCriteria($arg);
         } else {
             if ($arg instanceof Grid) {
                 $this->setSourceGrid($arg);
             }
         }
     }
 }
Exemple #4
0
 public static function typedGridClassCreate($className, $checkInitialization = true, $extends = 'TypedGrid')
 {
     $return = !$checkInitialization;
     $setClass = false;
     if ($checkInitialization) {
         $torpor = isset($this) ? $this : Torpor::getInstance();
         $gridName = substr($className, strlen($torpor->typedGridClassesPrefix()));
         if (!$torpor->supportedGrid($gridName) && ($gridSetName = strtolower(substr($gridName, -1 * strlen(self::OPERATION_GET_SET)))) == self::OPERATION_GET_SET) {
             $setClass = true;
             $gridName = substr($gridName, 0, -1 * strlen(self::OPERATION_GET_SET));
         }
         $return = $torpor->supportedGrid($gridName) && $torpor->typedGridClasses();
         if ($return) {
             $className = $torpor->typedGridClassesPrefix() . $gridName;
         }
     }
     if ($return) {
         // Should be done in 2 passes: determine if we're looking for a set, and if so create
         // that definition.  If not, create the grid class only.  This allows for more flexible
         // end user implementation (can extend one without affecting the other)
         // Using class_exists() causes some initialization recursion if typedGridClassCheck
         // is hooked into __autoload, so we use the slightly heavier get_declared_classes
         // instead which saves us running the same portions of code over and over.
         $declaredClasses = array_map('strtoupper', get_declared_classes());
         if ($setClass) {
             $setClassName = $className . self::OPERATION_GET_SET;
             if (!in_array(strtoupper($setClassName), $declaredClasses)) {
                 eval('class ' . $setClassName . ' extends ' . $extends . self::OPERATION_GET_SET . ' {}');
             }
         } else {
             if (!in_array(strtoupper($className), $declaredClasses)) {
                 eval('class ' . $className . ' extends ' . $extends . ' {}');
             }
         }
     }
     return $return;
 }
Exemple #5
0
$user->setId(12345);
$user->setUserName('george');
try {
    $user->setPasswordHash('george');
} catch (TorporException $e) {
    print_r('Encountered exception: ' . $e->getMessage() . "\n");
}
$user->setPasswordHash('something other than george');
var_dump($user->getId());
var_dump($user->getUserName());
var_dump($user->getEmail());
var_dump($user->getPasswordHash());
var_dump($user->GET_PASSWORD_HASH());
print "\n";
// TODO: test juggling multiple instances or Torpor.
$torpor = Torpor::getInstance();
// Create a grid instance in object context
$userToo = $torpor->newUser();
// Access member methods as a simple object,
// atomically redirected to getX and setX
$userToo->ID = 54321;
$userToo->ID++;
// Redirect works for increment operators too.
$userToo->UserName = '******';
$userToo->ReferringUserId = null;
foreach ($userToo->columnNames() as $column) {
    var_dump($userToo->{$column});
}
foreach ($userToo as $columnName => $column) {
    var_dump($columnName . ' = ' . var_export($column->getData(), true));
    var_dump($columnName . ' = ' . $column);