File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 ],
1111 "require" : {
1212 "kriswallsmith/buzz" : " ~0.12" ,
13- "symfony/intl" : " ~2.5.4"
13+ "symfony/intl" : " ~2.5.4" ,
14+ "symfony/validator" : " ~2.5.4"
1415 },
1516 "autoload" : {
1617 "psr-4" : { "Sprain\\ BookFinder\\ " : " lib/BookFinder" }
Original file line number Diff line number Diff line change 22
33namespace Sprain \BookFinder ;
44use Sprain \BookFinder \Response \BookFinderResponse ;
5+ use Symfony \Component \Validator \Constraints \Isbn ;
6+ use Symfony \Component \Validator \Validation ;
57
68/**
79 * BookFinder
@@ -31,6 +33,16 @@ public function searchByIsbn($isbn)
3133 $ isbn = trim ($ isbn );
3234 $ isbn = str_replace ('- ' , '' , $ isbn );
3335
36+ // Validate isbn
37+ $ validator = Validation::createValidator ();
38+ $ violations = $ validator ->validateValue ($ isbn , new Isbn ());
39+
40+ if (count ($ violations ) > 0 ) {
41+
42+ return false ;
43+ }
44+
45+ // Use providers to search for book
3446 foreach ($ this ->providers as $ provider ){
3547 $ result = $ provider ['provider ' ]->searchByIsbn ($ isbn )->getResult ();
3648
You can’t perform that action at this time.
0 commit comments