/
Property.php
52 lines (47 loc) · 1.11 KB
/
Property.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @package Morph
* @subpackage Compare
* @author Jonathan Moss <xirisr@gmail.com>
* @copyright Jonathan Moss 2009
*/
/**
* Comparator for Morph_Object
*
* @package Morph
* @subpackage Compare
*/
class Morph_Compare_Property implements Morph_ICompare
{
/**
* Name of the property to compare
* @var string
*/
private $propertyName;
/**
*
* @param string $propertyName The name of the property to compare
* @return Morph_Compare_Property
*/
public function __construct($propertyName)
{
$this->propertyName = $propertyName;
}
/**
* The actual compare function
*
* @param Morph_Object $objectA
* @param Morph_Object $objectB
* @return integer
*/
public function compare(Morph_Object $objectA, Morph_Object $objectB)
{
$compare = null;
if ($objectA->{$this->propertyName} == $objectB->{$this->propertyName}){
$compare = 0;
}else{
$compare = ($objectA->{$this->propertyName} < $objectB->{$this->propertyName}) ? -1 : 1;
}
return $compare;
}
}