コード例 #1
0
ファイル: DataGenerator.php プロジェクト: berlinonline/dat0r
 /**
  * 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);
         }
     }
 }
コード例 #2
0
 /**
  * Creates a IValueHolder instance for a given combination of IField and raw value.
  *
  * @param IField $field
  * @param mixed $raw_value
  *
  * @return IValueHolder
  */
 protected function createValueHolder(IField $field, $raw_value)
 {
     $value_holder = $field->createValueHolder($raw_value);
     if ($value_holder instanceof AggregateValueHolder) {
         // Listen to all changes made to AggregateValueHolder instances corresponding to our related fields
         // and propagte those changes to our listeners such as the ValuesHolder parent document.
         $value_holder->addAggregateChangedListener($this);
     }
     return $value_holder;
 }
コード例 #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()]);
 }