key() публичный статический Метод

Generates form signature string from form data.
public static key ( array $data ) : string
$data array An array of fields, locked fields and excluded fields.
Результат string The form signature string.
Пример #1
0
 public function testFormSignatureWithLabelField()
 {
     $form = new Form(array('context' => $this->context));
     $this->subject->sign($form);
     ob_start();
     $content = array($form->create(null, array('url' => 'http:///')), $form->label('foo'), $form->text('email', array('value' => 'foo@bar')), $form->end());
     $signature = ob_get_clean();
     preg_match('/value="([^"]+)"/', $signature, $match);
     list(, $signature) = $match;
     $result = $signature;
     $data = array('fields' => array('email' => 'foo@bar'));
     $expected = FormSignature::key($data);
     $this->assertEqual($expected, $result);
 }
Пример #2
0
 public function testFailsTamperedFieldsAndLockedWithManyAndFieldsChange()
 {
     for ($originalFields = array(), $i = 0; $i < 20; $i++) {
         $originalFields['fooa' . $i] = 'bara' . $i;
     }
     for ($originalLocked = array(), $i = 0; $i < 20; $i++) {
         $originalLocked['foob' . $i] = 'barb' . $i;
     }
     $signature0 = FormSignature::key(array('fields' => $originalFields, 'locked' => $originalLocked));
     $changed = $originalFields;
     $changed['foo10000'] = 'barAdded';
     $signature1 = FormSignature::key(array('fields' => $changed, 'locked' => $originalLocked));
     $this->assertNotIdentical($signature0, $signature1);
     $changed = $originalFields;
     unset($changed['fooa1']);
     $signature1 = FormSignature::key(array('fields' => $changed, 'locked' => $originalLocked));
     $this->assertNotIdentical($signature0, $signature1);
 }