1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
12 | abstract class Kohana_Jam_Query_Builder { |
||
13 | |||
14 | /** |
||
15 | * Convert a column to a `table`.`column` using the appropriate model info |
||
16 | * @param string $column |
||
17 | * @param string $model |
||
18 | * @param mixed $value |
||
19 | * @return string |
||
20 | */ |
||
21 | 135 | public static function resolve_attribute_name($column, $model = NULL, $value = NULL) |
|
64 | |||
65 | /** |
||
66 | * Set a primary key condition. If its an array make in an IN condition. |
||
67 | * @param Database_Query $query |
||
68 | * @param string $key |
||
69 | * @return Database_Query |
||
70 | */ |
||
71 | 24 | public static function find_by_primary_key(Database_Query $query, $key) |
|
89 | |||
90 | /** |
||
91 | * Set the table name, even if its in an alias array (table, alias) |
||
92 | * @param string|array $model |
||
93 | * @param string $table |
||
94 | * @return string|array |
||
95 | */ |
||
96 | 101 | public static function set_table_name($model, $table) |
|
108 | |||
109 | /** |
||
110 | * Convert model name to its corresponding table, even if its in an array (model, alias) |
||
111 | * @param string|array $model |
||
112 | * @return string|array |
||
113 | */ |
||
114 | 103 | public static function resolve_table_alias($model) |
|
122 | |||
123 | /** |
||
124 | * Generate Jam_Query_Builder_Join based on the given arguments |
||
125 | * @param string $table |
||
126 | * @param string $type LEFT, NATURAL... |
||
127 | * @param string $context_model the model of the parent |
||
128 | * @param boolean $resolve_table_model wether to resolve the name of the model to a tablename |
||
129 | * @return Jam_Query_Builder_Join |
||
130 | */ |
||
131 | 35 | public static function resolve_join($table, $type = NULL, $context_model = NULL, $resolve_table_model = TRUE) |
|
151 | |||
152 | /** |
||
153 | * Return the model if its alias array (model, alias) |
||
154 | * @param string|array $model |
||
155 | * @return string |
||
156 | */ |
||
157 | 139 | public static function aliased_model($model) |
|
161 | |||
162 | /** |
||
163 | * Convert :primary_key, :name_kay and :unique_key to their corresponding column names |
||
164 | * @param string $attribute |
||
165 | * @param Jam_Meta $meta |
||
166 | * @param mixed $value |
||
167 | * @return string |
||
168 | */ |
||
169 | 146 | public static function resolve_meta_attribute($attribute, Jam_Meta $meta, $value = NULL) |
|
188 | } |
||
189 |
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_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.