Exemple #1
0
 public function initialize(SimpleXMLElement $xmlDef)
 {
     // TODO: Loaded primary keys should be read only?
     // TODO: Build a local attributes interface in order to keep settings conveniently
     // accessible to inheriting classes.
     $this->_attributes = array();
     $type = Torpor::makeKeyName((string) $xmlDef->attributes()->type);
     if (!in_array($type, $this->getValidTypes())) {
         $this->throwException('Unrecognized type "' . $type . '"');
     }
     $this->setType($type);
     switch ($type) {
         case self::TYPE_BINARY:
             if ((int) $xmlDef->attributes()->length) {
                 $this->setMaxLength((int) $xmlDef->attributes()->length);
             }
             break;
         case self::TYPE_BOOL:
             break;
         case self::TYPE_CLASS:
             break;
         case self::TYPE_DATE:
         case self::TYPE_DATETIME:
         case self::TYPE_TIME:
             break;
         case self::TYPE_FLOAT:
         case self::TYPE_INTEGER:
         case self::TYPE_UNSIGNED_INTEGER:
             if ((int) $xmlDef->attributes()->precision) {
                 $this->setMaxLength((int) $xmlDef->attributes()->precision);
             }
             if ((int) $xmlDef->attributes()->length) {
                 $this->setMaxLength((int) $xmlDef->attributes()->length);
             }
             break;
         case self::TYPE_CHAR:
         case self::TYPE_VARCHAR:
         case self::TYPE_TEXT:
             if ((string) $xmlDef->attributes()->encoding) {
                 $this->setEncoding((string) $xmlDef->attributes()->encoding);
             }
             if ((int) $xmlDef->attributes()->length) {
                 $this->setMaxLength((int) $xmlDef->attributes()->length);
             }
             break;
     }
     if (!isset($xmlDef->attributes()->dataName)) {
         $this->throwException('Required attribute dataName not found');
     }
     $this->_dataName = (string) $xmlDef->attributes()->dataName;
     if (isset($xmlDef->attributes()->generatedOnPublish) && (string) $xmlDef->attributes()->generatedOnPublish == Torpor::VALUE_TRUE) {
         $this->setGeneratedOnPublish();
     }
     if (isset($xmlDef->attributes()->nullable) && (string) $xmlDef->attributes()->nullable == Torpor::VALUE_FALSE) {
         $this->setNullable(false);
     }
     if (isset($xmlDef->attributes()->precision)) {
         $this->setPrecision((string) $xmlDef->attributes()->precision);
     }
     // Set any default data prior to configuring as readOnly
     if (isset($xmlDef->attributes()->default)) {
         // This way we reset to this for originalData, and are still considered
         // dirty
         // WARNING: validating content from the dataStore; which can throw some
         // strange warnings if the XML and the repository definitions don't agree.
         $this->_defaultData = (string) $xmlDef->attributes()->default;
         $this->_data = $this->validatePersistData($this->_defaultData);
         $this->setOriginalData($this->_data);
         $this->_setDirty();
     }
     if (isset($xmlDef->attributes()->readOnly) && (string) $xmlDef->attributes()->readOnly == Torpor::VALUE_TRUE) {
         $this->setReadOnly();
     }
     // TODO: options for navigating attributes
     foreach ($xmlDef->attributes() as $key => $val) {
         $this->_attributes[$key] = (string) $val;
     }
 }
 public function __construct()
 {
     $args = func_get_args();
     $container = array_shift($args);
     if ($container instanceof Column) {
         $this->setGridName($container->Grid());
         $this->setColumnName($container);
     } else {
         if ($container && count($args)) {
             $this->setGridName($container);
             $this->setColumnName(array_shift($args));
         }
     }
     $type = '';
     if (get_class($this) != __CLASS__) {
         // This destroys any underscore separators
         $objType = Torpor::makeKeyName(get_class($this));
         if (strpos($objType, self::CRITERIA) === 0) {
             $objType = substr($objType, strlen(self::CRITERIA));
             $typeKeyNames = array_map(array('Torpor', 'makeKeyName'), self::getValidTypes());
             if (!in_array($objType, $typeKeyNames)) {
                 trigger_error('Unrecognized Criteria descendant "' . $objType . '", cannot auto-detect type from name', E_USER_WARNING);
                 $type = array_shift($args);
             } else {
                 $objNot = Torpor::makeKeyName(self::NOT);
                 $objColumn = Torpor::makeKeyName(self::COLUMN);
                 if (strpos($objType, $objNot) === 0) {
                     $type .= self::NOT;
                     $objType = substr($objType, strlen($objNot));
                 }
                 if ($pos = strrpos($objType, $objColumn)) {
                     $type .= substr($objType, 0, $pos) . self::COLUMN;
                 } else {
                     $type .= $objType;
                 }
             }
         } else {
             $type = array_shift($args);
         }
     } else {
         $type = array_shift($args);
     }
     if (!empty($type)) {
         $this->setType($type);
     }
     if (count($args) && !is_null($this->getType())) {
         $this->processArgs($args);
     }
 }
 public function addParameter($parameterName, $placeholder = null)
 {
     $paramterName = Torpor::makeKeyName($parameterName);
     if (empty($parameterName)) {
         throw new TorporException('Invalid parameterName');
     }
     $this->_parameters[] = $parameterName . (!empty($placeholder) ? Torpor::VALUE_SEPARATOR . $placeholder : '');
     return count($this->_parameters);
 }
 public function _setObjName($name)
 {
     return $this->_name = Torpor::makeKeyName($name);
 }