Skip to content

Commit

Permalink
T13893 registry collection (#13895)
Browse files Browse the repository at this point in the history
* [4.0.x] - Added unicode flag for email filter

* [4.0.x] - Updating the ext folder

* [4.0.x] - Added Arr helper class

* Revert "[4.0.x] - Added Arr helper class"

This reverts commit f8153d3.

* Revert "[4.0.x] - Updating the ext folder"

This reverts commit 655eafe.

* [#13893] - Work on the registry extending Collection; Tests!

* [#13893] - Corrected the signature of __get

* [#13893] - Correction to the interface

* [#13893] - Case insensitivity on has and get

* [#13893] - Added more tests for case insensitivity

* [#13893] - Changed the Session\Bag component to use Collection

* [#13893] - Rework the Session\Bag tests

* [#13893] - Updated changelog

* [#13893] - Corrections after the review

* [#13893] - Removed ext/ files
  • Loading branch information
niden authored Mar 13, 2019
1 parent 832c5a0 commit 1e720ea
Show file tree
Hide file tree
Showing 46 changed files with 1,039 additions and 1,167 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ The implementation offers PSR-7/PSR-17 compatible components in a different name
## Fixed
- Fixed Assets Manager hard reference to \Phalcon\Tag, should use DI [#12261](https://github.com/phalcon/cphalcon/issues/12261)

## Changed
- Refactored `Phalcon\Registry` to use the `Phalcon\Collection` class [#13893](https://github.com/phalcon/cphalcon/issues/13893)
- Refactored `Phalcon\Session\Bag` to use the `Phalcon\Collection` class [#13893](https://github.com/phalcon/cphalcon/issues/13893)

## Removed
- Removed `Phalcon\Session\BagInterface` [#13893](https://github.com/phalcon/cphalcon/issues/13893)


# [4.0.0-alpha.3](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0-alpha.3) (2019-02-31)
## Added
Expand Down
76 changes: 0 additions & 76 deletions ext/phalcon/session/baginterface.zep.c

This file was deleted.

75 changes: 0 additions & 75 deletions ext/phalcon/session/baginterface.zep.h

This file was deleted.

104 changes: 62 additions & 42 deletions phalcon/collection.zep
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ class Collection implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonS
/**
* @var array
*/
private data = [];
protected data = [];

public function __construct(array! data = null) -> void
/**
* @var array
*/
protected lowerKeys = [];



public function __construct(array! data = []) -> void
{
if typeof data === "array" {
this->init(data);
}
this->init(data);
}

/**
Expand Down Expand Up @@ -86,12 +91,16 @@ class Collection implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonS
/**
* Get the element from the collection
*/
public function get(string! element, var defaultValue = null) -> var | bool
public function get(string! element, var defaultValue = null, bool insensitive = true) -> var | bool
{
var value;

if likely fetch value, this->data[element] {
return value;
if likely insensitive {
let element = strtolower(element);
}

if likely fetch value, this->lowerKeys[element] {
return this->data[value];
}

return defaultValue;
Expand All @@ -108,44 +117,25 @@ class Collection implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonS
/**
* Get the element from the collection
*/
public function has(string! element) -> bool
public function has(string! element, bool insensitive = true) -> bool
{
return isset this->data[element];
}

/**
* Delete the element from the collection
*/
public function remove(string! element) -> void
{
array data;

let data = this->data;

unset data[element];

this->init(data);
}

/**
* Set an element in the collection
*/
public function set(string! element, var value) -> void
{
array data;

let data = this->data,
data[element] = value;
if likely insensitive {
let element = strtolower(element);
}

this->init(data);
return isset this->lowerKeys[element];
}

/**
* Initialize internal array
*/
public function init(array! data = [])
public function init(array! data = []) -> void
{
let this->data = data;
var key, value;

for key, value in data {
this->set(key, value);
}
}

/**
Expand Down Expand Up @@ -206,19 +196,49 @@ class Collection implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonS
this->remove(element);
}

/**
* Delete the element from the collection
*/
public function remove(string! element) -> void
{
var data, lowerKeys, key, value;

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

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

let this->data = data,
this->lowerKeys = lowerKeys;
}

/**
* String representation of object
*
* @link https://php.net/manual/en/serializable.serialize.php
*/
public function serialize() -> string
{
array data;
return serialize(this->data);
}

let data = this->data;
/**
* Set an element in the collection
*/
public function set(string! element, var value) -> void
{
var key;

return serialize(data);
}
let key = strtolower(element);

let this->data[element] = value,
this->lowerKeys[key] = element;
}

/**
* Returns the object in an array format
Expand Down
Loading

0 comments on commit 1e720ea

Please sign in to comment.