pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/cakephp/cakephp/pull/19357/files

="https://github.githubassets.com/assets/primer-primitives-6da842159062d25e.css" /> Add convenience methods to FormProtectionComponent by ADmad · Pull Request #19357 · cakephp/cakephp · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Controller/Component/FormProtectionComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,33 @@ public function implementedEvents(): array
];
}

/**
* Unlock actions from validation.
*
* @param string|array<string> $actions Action or list of actions to unlock.
* @param bool $merge Whether to merge with existing unlocked actions or replace them.
* @return $this
*/
public function unlockActions(string|array $actions, bool $merge = true)
{
return $this->setConfig('unlockedActions', (array)$actions, $merge);
}

/**
* Unlock fields from validation.
*
* Dot notation can be used to unlock nested fields. For example, `user.name`
* will unlock the `name` field in the `user` array.
*
* @param string|array<string> $fields Field or list of fields to unlock.
* @param bool $merge Whether to merge with existing unlocked fields or replace them.
* @return $this
*/
public function unlockFields(string|array $fields, bool $merge = true)
{
return $this->setConfig('unlockedFields', (array)$fields, $merge);
}

/**
* Throws a 400 - Bad request exception or calls custom callback.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,40 @@ public function testClearingOfTokenFromRequestData(): void

$this->assertSame([], $this->Controller->getRequest()->getParsedBody());
}

/**
* Test unlockActions() method.
*/
public function testUnlockActions(): void
{
// Single action as string
$this->FormProtection->unlockActions('index');
$this->assertSame(['index'], $this->FormProtection->getConfig('unlockedActions'));

// Multiple actions as array, merges by default
$this->FormProtection->unlockActions(['view', 'add']);
$this->assertSame(['index', 'view', 'add'], $this->FormProtection->getConfig('unlockedActions'));

// Replace when merge is false
$this->FormProtection->unlockActions('edit', false);
$this->assertSame(['edit'], $this->FormProtection->getConfig('unlockedActions'));
}

/**
* Test unlockFields() method.
*/
public function testUnlockFields(): void
{
// Single field as string
$this->FormProtection->unlockFields('csrf_token');
$this->assertSame(['csrf_token'], $this->FormProtection->getConfig('unlockedFields'));

// Multiple fields as array, merges by default
$this->FormProtection->unlockFields(['debug', 'dynamic_field']);
$this->assertSame(['csrf_token', 'debug', 'dynamic_field'], $this->FormProtection->getConfig('unlockedFields'));

// Replace when merge is false
$this->FormProtection->unlockFields('new_field', false);
$this->assertSame(['new_field'], $this->FormProtection->getConfig('unlockedFields'));
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy