示例#1
0
 /**
  * Checks if attribute is deprecated and needs migration.
  * @param Opt_Xml_Attribute $attr Attribute to migrate
  * @return boolean If attribute needs migration
  */
 public function attributeNeedMigration(Opt_Xml_Attribute $attr)
 {
     $name = $attr->getXmlName();
     if (in_array($name, $this->_deprecatedAttributes)) {
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * Tries to extract a single attribute, using the specified value type.
  *
  * @final
  * @internal
  * @param Opt_Xml_Element $item The scanned XML element.
  * @param Opt_Xml_Attribute $attr The parsed attribute
  * @param Int $type The requested value type.
  * @return Mixed The extracted attribute value
  */
 private final function _extractAttribute(Opt_Xml_Element $item, Opt_Xml_Attribute $attr, $type, $exprType = null)
 {
     $value = (string) $attr;
     switch ($type) {
         // An identifier, but with empty values allowed.
         case self::ID_EMP:
             if ($value == '') {
                 return $value;
             }
             // An identifier
         // An identifier
         case self::ID:
             if (!preg_match('/^[a-zA-Z0-9\\_\\.]+$/', $value)) {
                 throw new Opt_InvalidAttributeType_Exception($attr->getXmlName(), $item->getXmlName(), 'identifier');
             }
             return $value;
             // A number
         // A number
         case self::NUMBER:
             if (!preg_match('/^\\-?([0-9]+\\.?[0-9]*)|(0[xX][0-9a-fA-F]+)$/', $value)) {
                 throw new Opt_InvalidAttributeType_Exception($attr->getXmlName(), $item->getXmlName(), 'number');
             }
             return $value;
             // Boolean value: "yes" or "no"
         // Boolean value: "yes" or "no"
         case self::BOOL:
             if ($value != 'yes' && $value != 'no') {
                 throw new Opt_InvalidAttributeType_Exception($attr->getXmlName(), $item->getXmlName(), '"yes" or "no"');
             }
             return $value == 'yes';
             // A string packed into PHP expression. Can be switched to EXPRESSION.
         // A string packed into PHP expression. Can be switched to EXPRESSION.
         case self::STRING:
             return $value;
             break;
             // An OPT expression.
         // An OPT expression.
         case self::EXPRESSION:
         case self::ASSIGN_EXPR:
             if (strlen(trim($value)) == 0) {
                 throw new Opt_AttributeEmpty_Exception($attr->getXmlName(), $item->getXmlName());
             }
             if (preg_match('/^([a-zA-Z0-9\\_]{2,})\\:([^\\:].*)$/', $value, $found)) {
                 $result = $this->_compiler->parseExpression($found[2], $found[1]);
             } else {
                 $result = $this->_compiler->parseExpression($value, $exprType);
             }
             if ($result['type'] == Opt_Expression_Interface::ASSIGNMENT && $type != self::ASSIGN_EXPR) {
                 Opt_ExpressionOptionDisabled_Exception('Assignments', 'compiler requirements');
             }
             return $result['bare'];
     }
 }
示例#3
0
 /**
  * Adds a new attribute to the tag.
  *
  * @param Opt_Xml_Attribute $attribute The new attribute.
  */
 public function addAttribute(Opt_Xml_Attribute $attribute)
 {
     if (!is_array($this->_attributes)) {
         $this->_attributes = array();
     }
     $this->_attributes[$attribute->getXmlName()] = $attribute;
 }