Пример #1
0
 /**
  * Derived classes can override this logic and have different constrainst on the field names and values.
  * Here we can also add complex validaitons as long as the order of thefields doesn't matter at this point -
  * only the name and the value of a single filed.
  * Relationships between other fileds ought to be verified after the whole object is full
  * because no assumption can be made on the order of the field filling.
  * The basic implementation verifies that the field_name already exists in the fields array (meaning - part of the object's schema).
  *
  * @param string $field_name
  * @param any $field_value
  */
 protected function isFieldValid($field_name, $field_value)
 {
     //		echo "isFieldValid: $field_name , $field_value , <br>" . print_r ( $this->fields  , false );
     if (!array_key_exists($field_name, $this->fields)) {
         debugUtils::DEBUG("", "Cannot set field [" . $field_name . "] in object of type - TODO - how to display current object's class ??");
         return false;
     }
     return true;
 }
 /**
  * Override the basic implementation of the field validation so there will be no need to define each and every field name in the fields schema.
  * IMPORTANT - the restriction will be based on several parameters mainly to protect againt injection of arbitrary data in large quantities.
  * 1. the prefix of the field_name is FIELD_NAME_PREFIX 
  * 2. the length of the field_name is less than or equal MAX_FIELD_NAME_LENGTH 
  * 3. the length of the field_value  is less than or equal MAX_FIELD_VALUE_LENGTH
  * 4. the total number of fields is less tham or equal MAX_NUMBER_OF_FIELDS
  *
  * @param stirng  $field_name
  * @param any $field_value
  * @return true if the field (name & value) fit the constraints, false otherwise
  */
 protected function isFieldValid($field_name, $field_value)
 {
     /*		if ( ! kString::beginsWith( $field_name , skinContainer::FIELD_NAME_PREFIX ) )
     		{
     			debugUtils::DEBUG( "Field [" . $field_name . "] invalid. Every field shouild start with the prefix "  , skinContainer::FIELD_NAME_PREFIX );
     			return false;
     		}
     */
     if (strlen($field_name) > skinContainer::MAX_FIELD_NAME_LENGTH) {
         debugUtils::DEBUG("Field [" . $field_name . "] invalid. Field name should not be longer than ", skinContainer::MAX_FIELD_NAME_LENGTH);
         return false;
     }
     if (strlen($field_value) > skinContainer::MAX_FIELD_VALUE_LENGTH) {
         debugUtils::DEBUG("Field [" . $field_name . "] invalid. Field value is [" . $field_value . "] and should not be longer than ", skinContainer::MAX_FIELD_VALUE_LENGTH);
         return false;
     }
     if (count($this->fields) > skinContainer::MAX_NUMBER_OF_FIELDS) {
         debugUtils::DEBUG("Too many fields. Number should not exceed [" . skinContainer::MAX_NUMBER_OF_FIELDS . "]", "");
         return false;
     }
     return true;
 }