Skip to content

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

Description

@Dmitri10

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions