Fixed documentation for export() for OODBBean to accurately reflect current implementation of whitelisting beans. The current documentation for export() reads as:
/**
* Exports the bean as an array.
* This function exports the contents of a bean to an array and returns
* the resulting array. Depending on the parameters you can also
* export an entire graph of beans, apply filters or exclude meta data.
*
* Usage:
*
* <code>
* $bookData = $book->export( TRUE, TRUE, FALSE, [ 'author' ] );
* </code>
*
* The example above exports all bean properties to an array
* called $bookData including its meta data, parent objects but without
* any beans of type 'author'.
*
* @param boolean $meta set to TRUE if you want to export meta data as well
* @param boolean $parents set to TRUE if you want to export parents as well
* @param boolean $onlyMe set to TRUE if you want to export only this bean
* @param array $filters optional whitelist for export
*
* @return array
*/
With the relevant portion being (emphasis added):
The example above exports all bean properties to an array called $bookData including its meta data, parent objects but without any beans of type 'author'.
However, the implementation and the language of a "whitelist filter" doesn't seem to match that.
The current implementation does indeed implement a whitelist filter:
if ( $hasFilters ) {
if ( !in_array( strtolower( $value->getMeta( 'type' ) ), $filters ) ) continue;
}
And indeed a simple test:
use RedBeanPHP\R as R;
R::setup("sqlite:./test.db");
$author = R::dispense('author');
$author->name = 'Some Guy';
$book = R::dispense('book');
$book->title = 'Every Book Makes Someone Mad';
$book->author = $author;
var_dump($book->export(false, false, true, ['author']));
Does indeed produce the expected results where the whitelist is respected:
Fixed documentation for export() for OODBBean to accurately reflect current implementation of whitelisting beans. The current documentation for
export()
reads as:With the relevant portion being (emphasis added):
However, the implementation and the language of a "whitelist filter" doesn't seem to match that.
The current implementation does indeed implement a whitelist filter:
And indeed a simple test:
Does indeed produce the expected results where the whitelist is respected: