Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive flag for remove in Collections #13897

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
40d9930
[4.0.x] - Added unicode flag for email filter
niden Jan 28, 2019
d92ca2b
Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 2, 2019
4057c4e
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 2, 2019
0f756cb
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 7, 2019
a679d58
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 8, 2019
8aa972f
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 10, 2019
787077a
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 13, 2019
50151e0
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 16, 2019
f90a3cf
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 17, 2019
655eafe
[4.0.x] - Updating the ext folder
niden Feb 17, 2019
f8153d3
[4.0.x] - Added Arr helper class
niden Feb 17, 2019
d9587e9
Revert "[4.0.x] - Added Arr helper class"
niden Feb 17, 2019
d652894
Revert "[4.0.x] - Updating the ext folder"
niden Feb 17, 2019
2259ec6
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 17, 2019
1e66bbd
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 22, 2019
5a1081d
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Feb 23, 2019
be64189
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Mar 3, 2019
43100ff
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Mar 10, 2019
a0574ad
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Mar 12, 2019
50b63f0
[4.0.x] - Merge remote-tracking branch 'upstream/4.0.x' into 4.0.x
niden Mar 13, 2019
59576a8
[4.0.x] - Added case insensitive flag for remove
niden Mar 13, 2019
c03bcf3
[4.0.x] - Added case insensitive flag in remove and adjusted tests
niden Mar 13, 2019
5f41ff4
[4.0.x] - Corrected the interface
niden Mar 13, 2019
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
17 changes: 11 additions & 6 deletions phalcon/collection.zep
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,22 @@ class Collection implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonS
/**
* Delete the element from the collection
*/
public function remove(string! element) -> void
public function remove(string! element, bool insensitive = true) -> void
{
var data, lowerKeys, key, value;
var data, lowerKeys, value;


let data = this->data,
lowerKeys = this->lowerKeys,
key = strtolower(element);
lowerKeys = this->lowerKeys;

if this->has(element) {
let value = lowerKeys[key];
unset lowerKeys[key];
if likely insensitive {
let element = strtolower(element);
}

let value = lowerKeys[element];

unset lowerKeys[element];
unset data[value];
}

Expand Down
4 changes: 2 additions & 2 deletions phalcon/registry.zep
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ final class Registry extends Collection
/**
* Delete the element from the collection
*/
public final function remove(string! element) -> void
public final function remove(string! element, bool insensitive = true) -> void
{
parent::remove(element);
parent::remove(element, insensitive);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions phalcon/session/bag.zep
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class Bag extends Collection implements InjectionAwareInterface
/**
* Removes a property from the internal bag
*/
public function remove(string! element) -> void
public function remove(string! element, bool insensitive = true) -> void
{
parent::remove(element);
parent::remove(element, insensitive);
this->session->set(this->name, this->data);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/integration/Session/Bag/RemoveCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public function sessionBagRemove(IntegrationTester $I)
$actual = $collection->toArray();
$I->assertEquals($expected, $actual);

$collection->remove('FIVE');
$expected = [
'one' => 'two',
'three' => 'four',
];
$actual = $collection->toArray();
$I->assertEquals($expected, $actual);

$collection->init($data);
unset($collection['five']);
$expected = [
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Collection/RemoveCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public function collectionRemove(UnitTester $I)
$actual = $collection->toArray();
$I->assertEquals($expected, $actual);

$collection->remove('FIVE');
$expected = [
'one' => 'two',
'three' => 'four',
];
$actual = $collection->toArray();
$I->assertEquals($expected, $actual);

$collection->init($data);
unset($collection['five']);
$expected = [
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Registry/RemoveCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public function collectionRemove(UnitTester $I)
$actual = $registry->toArray();
$I->assertEquals($expected, $actual);

$registry->remove('FIVE');
$expected = [
'one' => 'two',
'three' => 'four',
];
$actual = $registry->toArray();
$I->assertEquals($expected, $actual);

$registry->init($data);
unset($registry['five']);
$expected = [
Expand Down