Skip to content

Commit

Permalink
Allow copyTo() to save field values to regular PHP variables
Browse files Browse the repository at this point in the history
  • Loading branch information
bcosca committed Jul 18, 2018
1 parent 363e345 commit 8364951
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions db/cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ abstract function update();
abstract function copyfrom($var,$func=NULL);

/**
* Populate hive array variable with mapper fields
* Populate array variable with mapper fields
* @return NULL
* @param $key string
* @param $var mixed
**/
abstract function copyto($key);
abstract function copyto(&$var);

/**
* Get cursor's equivalent external iterator
Expand Down
9 changes: 5 additions & 4 deletions db/jig/mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,13 @@ function copyfrom($var,$func=NULL) {
}

/**
* Populate hive array variable with mapper fields
* Populate array variable with mapper fields
* @return NULL
* @param $key string
* @param $var mixed
**/
function copyto($key) {
$var=&\Base::instance()->ref($key);
function copyto(&$var) {
if (is_string($var))
$var=&\Base::instance()->ref($key);
foreach ($this->document as $key=>$field)
$var[$key]=$field;
}
Expand Down
9 changes: 5 additions & 4 deletions db/mongo/mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,13 @@ function copyfrom($var,$func=NULL) {
}

/**
* Populate hive array variable with mapper fields
* Populate array variable with mapper fields
* @return NULL
* @param $key string
* @param $var mixed
**/
function copyto($key) {
$var=&\Base::instance()->ref($key);
function copyto($var) {
if (is_string($var))
$var=&\Base::instance()->ref($key);
foreach ($this->document as $key=>$field)
$var[$key]=$field;
}
Expand Down
9 changes: 5 additions & 4 deletions db/sql/mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,13 @@ function copyfrom($var,$func=NULL) {
}

/**
* Populate hive array variable with mapper fields
* Populate array variable with mapper fields
* @return NULL
* @param $key string
* @param $var mixed
**/
function copyto($key) {
$var=&\Base::instance()->ref($key);
function copyto(&$var) {
if (is_string($var))
$var=&\Base::instance()->ref($var);
foreach ($this->fields+$this->adhoc as $key=>$field)
$var[$key]=$field['value'];
}
Expand Down

4 comments on commit 8364951

@ikkez
Copy link
Member

@ikkez ikkez commented on 8364951 Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$key is not defined in jig and mongo changes
it's probably breaking BC in userland code
itsn't its purpose the same as just using ->cast() ?

@ikkez
Copy link
Member

@ikkez ikkez commented on 8364951 Aug 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issues here are still there @bcosca and actually I think it's a bit hidden fat, since it's the same as the cast method. And since it does break class definition backward-compatibility, we should put this in a feature branch for 3.7 and not into a minor patch level. I can prepare that and fix the missing variables in this change

@ikkez
Copy link
Member

@ikkez ikkez commented on 8364951 Aug 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this commit and its fixes to https://github.com/bcosca/fatfree-core/tree/3.7
I hope that's fine for now.

@bcosca
Copy link
Collaborator Author

@bcosca bcosca commented on 8364951 Aug 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. cast() will do for now.

Please sign in to comment.