WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

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

@Dmitri10

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?

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