PHP Class ElggBatch, Elgg
This is usually used with elgg_get_entities() and friends,
elgg_get_annotations(), and elgg_get_metadata().
If you pass a valid PHP callback, all results will be run through that
callback. You can still foreach() through the result set after. Valid
PHP callbacks can be a string, an array, or a closure.
{@link http://php.net/manual/en/language.pseudo-types.php}
The callback function must accept 3 arguments: an entity, the getter
used, and the options used.
Results from the callback are stored in callbackResult. If the callback
returns only booleans, callbackResults will be the combined result of
all calls.
If the callback returns anything else, callbackresult will be an indexed
array of whatever the callback returns. If returning error handling
information, you should include enough information to determine which
result you're referring to.
Don't combine returning bools and returning something else.
Note that returning false will not stop the foreach.
显示文件
Open project: elgg/elgg
Class Usage Examples
Public Properties
Property |
Type |
Description |
|
$callbackResult |
mixed |
The result of running all entities through the callback function. |
|
Public Methods
Private Methods
Method Details
__construct()
public method
Instead of returning all objects in memory, it goes through $chunk_size
objects, then requests more from the server. This avoids OOM errors.
public __construct ( string $getter, array $options, mixed $callback = null, integer $chunk_size = 25, boolean $inc_offset = true ) |
$getter |
string |
The function used to get objects. Usually
an elgg_get_*() function, but can be any valid PHP callback. |
$options |
array |
The options array to pass to the getter function. If limit is
not set, 10 is used as the default. In most cases that is not
what you want. |
$callback |
mixed |
An optional callback function that all results will be passed
to upon load. The callback needs to accept $result, $getter,
$options. |
$chunk_size |
integer |
The number of entities to pull in before requesting more.
You have to balance this between running out of memory in PHP
and hitting the db server too often. |
$inc_offset |
boolean |
Increment the offset on each fetch. This must be false for
callbacks that delete rows. You can set this after the
object is created with {@link \ElggBatch::setIncrementOffset()}. |
As this performs a separate query, the count returned may not match the number of results you can
fetch via iteration on a very active DB.
reportIncompleteEntity()
public method
Tell the process that an entity was incomplete during a fetch
setIncrementOffset()
public method
Increment the offset from the original options array? Setting to
false is required for callbacks that delete rows.
Property Details
$callbackResult public_oe property
The result of running all entities through the callback function.
public mixed $callbackResult |
return |
mixed |
|