-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
68 lines (62 loc) · 2.26 KB
/
init.php
File metadata and controls
68 lines (62 loc) · 2.26 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
use Bookstore\Domain\Customer;
use Bookstore\Domain\Customer\Basic;
use Bookstore\Domain\Customer\Premium;
use Bookstore\Domain\Book;
use Bookstore\Utils\Config;
use Bookstore\Domain\Payer;
use Bookstore\Domain\Person;
use Bookstore\Exceptions\InvalidIdException;
use Bookstore\Domain\Tax;
function autoloader($classname)
{
$lastSlash = strpos($classname, '\\') + 1;
$classname = substr($classname, $lastSlash);
$directory = str_replace('\\', '/', $classname);
$filename = __DIR__.'/src/'.$directory.".php";
require_once($filename);
}
spl_autoload_register('autoloader');
//
//$book = new Book(16578901, "River Between", "James Thiongo", 1);
//$book1 = ['River between'];
//
//
//function checkIfValid(Customer $customer, array $books): bool
//{
// return $customer->getAmountToBorrow() >= count($books);
//}
//$customer1 = new Basic(5, 'John', 'Doe', 'johndoe@mail.com');
//$customer2 = new Premium(7, 'James', 'Bond', 'james@bond.com');
//var_dump($customer1 instanceof Basic);
//var_dump($customer1 instanceof Premium);
//var_dump($customer2 instanceof Premium);
//var_dump($customer1 instanceof Customer);
//var_dump($customer2 instanceof Customer);
//var_dump($customer1 instanceof Payer);
//var_dump($customer1 instanceof Person);
//var_dump($customer1::getLastId());
//var_dump($customer2::getLastId());
$customer = Customer\CustomerFactory::factory('basic',2,'Mary', 'Hawkins', 'mary@hostgater.com');
$customer1 = Customer\CustomerFactory::factory('premium',2,'Mary', 'Hawkins', 'mary@hostgater.com');
var_dump($customer->getType());
var_dump($customer1->getType());
//Anonymous function/ lambda functions
$addTaxes = function(array &$book, $index, $percentage ) {
$book['price'] += round($percentage * $book['price'], 2);
};
$books = [
['title' => '1984', 'price' => 8.15],
['title' => 'Don Quijote', 'price' => 12.00],
['title' => 'Odyssey', 'price' => 3.55]
];
$CLASSNAME = __NAMESPACE__ . '\\' . ucfirst("Tax"); //constant __NAMESPACE__ containts the namespace of the current file
echo $CLASSNAME;
// foreach ($books as $index => $book) {
// $addTaxes($book, $index, 0.16);
// }
array_walk($books, ['\Bookstore\Domain\Tax', 'add'], 0.16);
array_walk($books, [new \Bookstore\Domain\Tax(), 'addTaxes'], 0.16);
echo "<pre>";
var_dump($books);
echo "</pre>";