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

Implement the Iterator interface for the parser #67

Merged
merged 5 commits into from
Jun 8, 2016
Merged

Implement the Iterator interface for the parser #67

merged 5 commits into from
Jun 8, 2016

Conversation

wadmiraal
Copy link
Contributor

This PR contains 3 changes (sorry, I just didn't plan that very well when making the changes; if you want, I can cherry-pick and split it into 3 separate PRs):

  1. Add a unit test for non-existent files when using VCardParser::parseFromFile() (throws an exception)
  2. Add a new method getCards(), which gets all cards. This is to complement the getCardAtIndex() method (which is great, but not sufficient).
  3. Implement the Iterator interface to loop over parsed data. Let me detail this last one.

Implement the Iterator interface for the parser class. This will allow parsed VCard databases to be easily iterated over. Example:

$parser = new VCardParser($vcardDb);
foreach ($parser as $i => $card) {
    // Do stuff with card.
}

This is much more DX friendly than the simple getCardAtIndex() and getCards() methods. Added unit tests accordingly.

Remove empty lines at the beginning of classes.
Add new getCards() method to load all cards, instead of relying on
getCardAtIndex() all the time.
The parser now implements the Iterator interface, allowing parsed VCards
to be iterated over using for and foreach loops.
@jeroendesloovere jeroendesloovere merged commit 15d11cd into jeroendesloovere:master Jun 8, 2016
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

Successfully merging this pull request may close these issues.

None yet

2 participants