Last active
December 18, 2015 07:49
-
-
Save ackintosh/5748987 to your computer and use it in GitHub Desktop.
test the time that book has been loaned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Loan | |
| { | |
| private $book; | |
| private $time; | |
| private static $faketime; | |
| public function __construct(Book $book) | |
| { | |
| $this->book = $book; | |
| $this->time = self::$faketime ? : new DateTime(); | |
| } | |
| public static function setFaketime(DateTime $faketime) | |
| { | |
| self::$faketime = $faketime; | |
| } | |
| public function toString() | |
| { | |
| return $this->book->title() . ' loaned on ' . $this->time->format('Y/m/d H:i:s'); | |
| } | |
| } | |
| class Book | |
| { | |
| private $title; | |
| public function __construct($title) { $this->title = $title; } | |
| public function title() { return $this->title; } | |
| } | |
| Loan::setFaketime(new DateTime('2013/06/10 18:00:00')); | |
| $l = new Loan(new Book('WEEKLY JUMP')); | |
| echo $l->toString(); // always returns 'WEKLY JUMP loaned on 2013/06/10 18:00:00' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Loan | |
| { | |
| // .... | |
| public function __construct($book, $time) | |
| { | |
| $this->book = $book; | |
| $this->time = $time; | |
| } | |
| // .... | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Loan | |
| { | |
| private $book; | |
| private $time; | |
| public function __construct($book) | |
| { | |
| $this->book = $book; | |
| $this->time = new DateTime(); | |
| } | |
| public function toString() | |
| { | |
| return $this->book->title() . ' loaned on ' . $this->time->format('Y/m/d H:i:s'); | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Loan | |
| { | |
| // .... | |
| public function __construct($book, $time, $num) | |
| { | |
| $this->book = $book; | |
| $this->time = $time; | |
| $this->num = $num; | |
| } | |
| // .... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment