Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper way to abort export() inside callback? #86

Closed
mikyk10 opened this issue Jan 17, 2020 · 0 comments
Closed

Proper way to abort export() inside callback? #86

mikyk10 opened this issue Jan 17, 2020 · 0 comments

Comments

@mikyk10
Copy link

mikyk10 commented Jan 17, 2020

Hi guys,

I want to cap the rows of CSV to certain number and I am not sure if I could safely stop the export process from a callback function, not using exit. Then I came up with throwing an exception to stop the function.

How would you think about this?

Here's example code.

$collection = new CallbackCollection($data, function($row) {
	// apply custom format to the row
	$row[1] = $row[1] . '!';

	// if the data size exceeds a limit
	if (...) {
		throw new \Exception('ABORTED');
	}

	return $row;
});

$config = new ExporterConfig();
$exporter = new Exporter($config);

$exporter->export('php://stdout', $collection);
@mikyk10 mikyk10 closed this as completed Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant