| 1 | <?php |
||
| 11 | class IlluminateDBAdapter implements DBAdapter |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var Connection |
||
| 15 | */ |
||
| 16 | protected $connection; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * IlluminateDBAdapter constructor. |
||
| 20 | * @param Connection $connection |
||
| 21 | */ |
||
| 22 | public function __construct(Connection $connection) |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Return a new Query instance for this driver |
||
| 29 | * |
||
| 30 | * @return QueryAdapter |
||
| 31 | */ |
||
| 32 | public function getQuery() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get the date format supported by the current connection |
||
| 43 | * |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | public function getDateFormat() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Start a DB transaction on driver that supports it. |
||
| 53 | * @return void |
||
| 54 | */ |
||
| 55 | public function beginTransaction() |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Commit a DB transaction on driver that supports it. |
||
| 62 | * @return void |
||
| 63 | */ |
||
| 64 | public function commit() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Rollback a DB transaction |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | public function rollback() |
||
| 77 | } |
||
| 78 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.