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

What is the best way to exit from observer? #77

Open
Dmitri10 opened this issue May 9, 2018 · 0 comments
Open

What is the best way to exit from observer? #77

Dmitri10 opened this issue May 9, 2018 · 0 comments

Comments

@Dmitri10
Copy link

Dmitri10 commented May 9, 2018

I have a very large csv file. So I don't need to have a full parsing on my local-machine and want to exit after 2000 rows. I'm using throwing exception for now like this:

$interpreter->addObserver(function (array $row) use (&$i, &$captions) {
      // todo remove it for non-local server
      if ($i > 2000) {
           throw new StrictViolationException('Cant exit with another way', 100);
            /* return / return false don't work - 
             * it still continues  and I don't need exit() function
            */
       }
     $i++;
    //do smth...
});

try {
      $lexer->parse($file, $interpreter);
 } catch (StrictViolationException $e) {
       // we'll be here
}
print_r("script continues and that's great");

So what's the best way to go out from observer?

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