phpdoc
[m6w6/pq-gateway] / lib / pq / Mapper / RefProperty.php
1 <?php
2
3 namespace pq\Mapper;
4
5 trait RefProperty
6 {
7 use Property;
8
9 /**
10 * The referred class
11 * @var string
12 */
13 private $refClass;
14
15 /**
16 * The foreign key name
17 * @var string
18 */
19 private $refName;
20
21 /**
22 * Define the referred class
23 * @param string $class
24 * @return RefPropertyInterface
25 */
26 function to($class) {
27 $this->refClass = $class;
28 return $this;
29 }
30
31 /**
32 * Check whether this mapping refers to $class
33 * @param string $class
34 * @return bool
35 */
36 function references($class) {
37 return $this->refClass === (is_object($class) ? get_class($class) : $class);
38 }
39
40 /**
41 * Define the foreign key name as defined by pq\Gateway\Table\Reference
42 * @param string $ref
43 * @return RefPropertyInterface
44 */
45 function by($ref) {
46 $this->refName = $ref;
47 return $this;
48 }
49
50 /**
51 * Check whether this mapping referes to a foreign key
52 * @param string $ref
53 * @return bool
54 */
55 function on($ref) {
56 return $this->refName === $ref;
57 }
58 }