Last active
October 7, 2015 07:48
-
-
Save cythrawll/3130241 to your computer and use it in GitHub Desktop.
Example of three layered Service
This file contains 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 | |
//omitting setting exception mode, don't forget it! | |
$db = new PDO(...); | |
$authorDao = new AuthorDao($db); | |
$authorService = new AuthorServiceDaoImpl($authorDao); | |
$authorService->getBooks($author->getPrimaryKey()); | |
//tip: you can simplify construction by using a Builder pattern, or a Factory pattern if you want to handle more than one implementation of the service. |
This file contains 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 Dao { | |
protected $db; | |
public function __construct(PDO $db) { | |
$this->db = $db; | |
} | |
public function getDB() { | |
return $this->db; | |
} | |
} |
This file contains 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 Entity { | |
private $primaryKey; | |
public getPrimaryKey() { | |
return $this->primaryKey; | |
} | |
public setPrimaryKey($primaryKey) { | |
$this->primaryKey = $primaryKey; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment