-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.php
41 lines (36 loc) · 938 Bytes
/
Book.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Book.php
* Created by Susan Buck
* https://github.com/susanBuck/foobooks0/blob/master/Book.php
*/
namespace DWA;
class Book
{
// Changed this to protected so it's available to ProcessBook extension
protected $books;
public function __construct($dataFile)
{
$booksJson = file_get_contents($dataFile);
$this->books = json_decode($booksJson, true);
}
public function getAll()
{
return $this->books;
}
public function getByTitle($title, $caseSensitive = false)
{
$results = [];
foreach ($this->books as $bookTitle => $book) {
if ($caseSensitive) {
$match = $bookTitle == $title;
} else {
$match = strtolower($bookTitle) == strtolower($title);
}
if ($match) {
$results[$bookTitle] = $book;
}
}
return $results;
}
}