示例#1
0
 /**
  * Sets either given default value or value from option to the given field.
  *
  * @param Document $document the document to modify
  * @param string $fieldname the name of the field to set a value for
  * @param mixed $default_value Default value to set.
  * @param array $options Array containing a `fieldname => $mixed` entry.
  *                       $mixed is set as value instead of $default_value.
  *                       If $mixed is a closure it will be called and used.
  *                       $mixed may also be another callable like an array
  *                       `array($class, "$methodName")` or a string like
  *                       `'Your\Namespace\Foo::getStaticTrololo'`.
  *
  * @return void
  */
 protected function setValue(IDocument $document, IField $field, $default_value, array $options = array())
 {
     $fieldname = $field->getName();
     $fieldoptions = array();
     if (!empty($options[self::OPTION_FIELD_VALUES]) && is_array($options[self::OPTION_FIELD_VALUES])) {
         $fieldoptions = $options[self::OPTION_FIELD_VALUES];
     }
     if (empty($fieldoptions[$fieldname])) {
         $document->setValue($fieldname, $default_value);
     } else {
         $option = $fieldoptions[$fieldname];
         if (is_callable($option)) {
             $document->setValue($fieldname, call_user_func($option));
         } else {
             $document->setValue($fieldname, $option);
         }
     }
 }
 /**
  * Tells whether a value has been set for a given field.
  *
  * @param IField $field
  *
  * @return boolean
  */
 public function has(IField $field)
 {
     return isset($this->values[$field->getName()]);
 }
示例#3
0
 /**
  * Tells if a given field is allready inside the collection.
  *
  * @param IField $field
  *
  * @return boolean
  */
 public function has(IField $field)
 {
     // @todo Do a instance-equality check instead of just checking names?
     return isset($this->fields[$field->getName()]);
 }