Skip to content

Commit

Permalink
[#14551] - Corrected warning and get options for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Nov 22, 2019
1 parent 9c2f9b5 commit 27e5986
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions phalcon/Storage/Adapter/AbstractAdapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class AbstractAdapter implements AdapterInterface
/**
* Sets parameters based on options
*/
protected function __construct(<SerializerFactory> factory = null, array! options)
protected function __construct(<SerializerFactory> factory = null, array! options = [])
{
/**
* Lets set some defaults and options here
Expand Down Expand Up @@ -93,7 +93,7 @@ abstract class AbstractAdapter implements AdapterInterface
/**
* Reads data from the adapter
*/
abstract public function get(string! key) -> var;
abstract public function get(string! key, var defaultValue = null) -> var;

/**
* Returns the adapter - connects to the storage if not connected
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Storage/Adapter/AdapterInterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface AdapterInterface
/**
* Reads data from the adapter
*/
public function get(string! key) -> var;
public function get(string! key, var defaultValue = null) -> var;

/**
* Returns the already connected adapter or connects to the backend
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Storage/Adapter/Memory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Memory extends AbstractAdapter
/**
* @var Collection
*/
protected data = [];
protected data;

/**
* @var array
Expand Down
18 changes: 6 additions & 12 deletions phalcon/Storage/Adapter/Stream.zep
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ class Stream extends AbstractAdapter
*/
protected options = [];

/**
* @var bool
*/
private warning = false;

/**
* Stream constructor.
*
Expand Down Expand Up @@ -324,26 +319,25 @@ class Stream extends AbstractAdapter
{
var payload;

let payload = file_get_contents(filepath),
this->warning = false;
let payload = file_get_contents(filepath);

if false === payload {
return [];
}

globals_set("warning.enable", false);
set_error_handler(
function (number, message, file, line, context) {
if number === E_WARNING {
let this->warning = true;
}
}
globals_set("warning.enable", true);
},
E_NOTICE
);

let payload = unserialize(payload);

restore_error_handler();

if unlikely (this->warning || typeof payload !== "array") {
if unlikely (globals_get("warning.enable") || typeof payload !== "array") {
return [];
}

Expand Down

0 comments on commit 27e5986

Please sign in to comment.