| 1 |
|
<?php |
| 2 |
|
/** |
| 3 |
|
* Xyster Framework |
| 4 |
|
* |
| 5 |
|
* This source file is subject to the new BSD license that is bundled |
| 6 |
|
* with this package in the file LICENSE.txt. |
| 7 |
|
* It is also available through the world-wide-web at this URL: |
| 8 |
|
* http://www.opensource.org/licenses/bsd-license.php |
| 9 |
|
* |
| 10 |
|
* @category Xyster |
| 11 |
|
* @package Xyster_Type |
| 12 |
|
* @copyright Copyright LibreWorks, LLC (http://libreworks.net) |
| 13 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 14 |
|
* @version $Id: Method.php 418 2010-10-18 21:40:08Z jonathanhawk $ |
| 15 |
|
*/ |
| 16 |
|
namespace Xyster\Type\Property; |
| 17 |
|
/** |
| 18 |
|
* A mediator for setting and getting values from a named field |
| 19 |
|
* |
| 20 |
|
* @category Xyster |
| 21 |
|
* @package Xyster_Type |
| 22 |
|
* @copyright Copyright LibreWorks, LLC (http://libreworks.net) |
| 23 |
|
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License |
| 24 |
|
*/ |
| 25 |
|
class Method implements IProperty |
| 26 |
|
{ |
| 27 |
|
/** |
| 28 |
|
* The getter name |
| 29 |
|
* |
| 30 |
|
* @var string |
| 31 |
|
*/ |
| 32 |
|
protected $_getName; |
| 33 |
|
|
| 34 |
|
/** |
| 35 |
|
* The setter name |
| 36 |
|
* |
| 37 |
|
* @var string |
| 38 |
|
*/ |
| 39 |
|
protected $_setName; |
| 40 |
|
|
| 41 |
|
/** |
| 42 |
|
* Creates a new field mapper |
| 43 |
|
* |
| 44 |
|
* @param string $name The name of the property |
| 45 |
|
*/ |
| 46 |
|
public function __construct( $name ) |
| 47 |
|
{ |
| 48 |
10 |
$ucname = ucfirst($name); |
| 49 |
10 |
$this->_getName = 'get' . $ucname; |
| 50 |
10 |
$this->_setName = 'set' . $ucname; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
/** |
| 54 |
|
* Gets the value in the field of the target |
| 55 |
|
* |
| 56 |
|
* @param mixed $target |
| 57 |
|
* @return mixed |
| 58 |
|
*/ |
| 59 |
|
public function get( $target ) |
| 60 |
|
{ |
| 61 |
1 |
$methodName = $this->_getName; |
| 62 |
1 |
return $target->$methodName(); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
/** |
| 66 |
|
* Sets the value in the field of the target |
| 67 |
|
* |
| 68 |
|
* @param mixed $target |
| 69 |
|
* @param mixed $value |
| 70 |
|
*/ |
| 71 |
|
public function set( $target, $value ) |
| 72 |
|
{ |
| 73 |
10 |
$methodName = $this->_setName; |
| 74 |
10 |
$target->$methodName($value); |
| 75 |
|
} |
| 76 |
1 |
} |