|
1
|
|
|
<?php |
|
2
|
|
|
namespace samson\activerecord; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class for relation table/class data storage on joining tables |
|
6
|
|
|
* |
|
7
|
|
|
* @author Vitaly Iegorov <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
class RelationData |
|
10
|
|
|
{ |
|
11
|
|
|
/** Base class in relation */ |
|
12
|
|
|
public $base; |
|
13
|
|
|
|
|
14
|
|
|
/** Relative class in relation */ |
|
15
|
|
|
public $relation; |
|
16
|
|
|
|
|
17
|
|
|
/** Real table name name or alias table name in relation */ |
|
18
|
|
|
public $table; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** Full table name as stored in database(with prefix) */ |
|
22
|
|
|
public $realTableName; |
|
23
|
|
|
|
|
24
|
|
|
/** Short table name as stored everywhere in code (without prefix) */ |
|
25
|
|
|
public $virtualTableName; |
|
26
|
|
|
|
|
27
|
|
|
/** Alias table name */ |
|
28
|
|
|
public $aliasTableName; |
|
29
|
|
|
|
|
30
|
|
|
/** Class name for creating table instances */ |
|
31
|
|
|
public $className; |
|
32
|
|
|
|
|
33
|
|
|
/** Flag for ignoring this class, and do not create instances of this class */ |
|
34
|
|
|
public $ignore = false; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructor |
|
38
|
|
|
* @param string $base_class Base class in relation |
|
39
|
|
|
* @param string $table_name Name/alias of table in relation |
|
|
|
|
|
|
40
|
|
|
* @param string $relation_class Classname that has to be created on joining |
|
41
|
|
|
* @param boolean $ignore Flag for not creating object instances for this class |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( $base_class, $table_name_simple, $relation_class = null, $ignore = false ) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
// If table name passed without namespace consider it as activerecord namespace |
|
46
|
|
|
$table_name = \samson\core\AutoLoader::className( $table_name_simple, 'samson\activerecord'); |
|
47
|
|
|
|
|
48
|
|
|
// If relation class not specified |
|
49
|
|
|
if (!isset($relation_class)) { |
|
50
|
|
|
// if there is no class exists for table name specified |
|
51
|
|
|
if (!class_exists($table_name, false)) { |
|
52
|
|
|
// PHP < 5.3 get relation aliases |
|
53
|
|
|
eval('$_relation_alias = '.$base_class.'::$_relation_alias;'); |
|
54
|
|
|
|
|
55
|
|
|
// Try to find classname in relation aliases |
|
56
|
|
|
if( isset($_relation_alias[ $table_name_simple ])) { |
|
|
|
|
|
|
57
|
|
|
$relation_class = \samson\core\AutoLoader::className($_relation_alias[ $table_name_simple ], __NAMESPACE__); |
|
58
|
|
|
} else if (isset($_relation_alias[ $table_name ])) { |
|
|
|
|
|
|
59
|
|
|
$relation_class = \samson\core\AutoLoader::className($_relation_alias[ $table_name ], __NAMESPACE__); |
|
60
|
|
|
} else { // use thi table name as class |
|
61
|
|
|
$relation_class = $table_name; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
// Relation class name equals to table name |
|
65
|
|
|
else $relation_class = $table_name; |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
// Try to find closest parent class to dbRecord class |
|
68
|
|
|
$parent_class = get_parent_class( $relation_class ); |
|
69
|
|
|
if( $parent_class != \samson\core\AutoLoader::className( 'dbRecord', 'samson\activerecord')) $table_name = \samson\core\AutoLoader::getOnlyClass($parent_class); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// Set defined class fields |
|
73
|
|
|
$this->base = $base_class; |
|
74
|
|
|
$this->relation = $relation_class; |
|
75
|
|
|
$this->table = \samson\core\AutoLoader::getOnlyClass( $table_name ); |
|
76
|
|
|
$this->ignore = $ignore; |
|
77
|
|
|
|
|
78
|
|
|
// TODO: fix this problem |
|
79
|
|
|
$this->table = str_replace('samson_activerecord_', '', $this->table); |
|
80
|
|
|
} |
|
81
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.