|
|---|
| 1 | | <?php |
| 2 | | /* This class is part of the XP framework |
| 3 | | * |
| 4 | | * $Id: Binford.class.php 6194 2005-11-30 12:28:51Z friebe $ |
| 5 | | */ |
| 6 | | |
| 7 | | uses('peer.Header'); |
| 8 | | |
| 9 | | /** |
| 10 | | * This class has more power |
| 11 | | * |
| 12 | | * @purpose Add power to an application |
| 13 | | * @see http://www.binford.de/ |
| 14 | | */ |
| 15 | | class Binford extends Object { |
| 16 | | var |
| 17 | | $poweredBy= 0; |
| 18 | | |
| 19 | | /** |
| 20 | | * Constructor |
| 21 | | * |
| 22 | | * @access public |
| 23 | | * @param int power default 6100 |
| 24 | | * @throws lang.IllegalArgumentException in case power contains an illegal value |
| 25 | | */ |
| 26 | | function __construct($poweredBy= 6100) { |
| 27 | 18 | $this->setPoweredBy($poweredBy); |
| 28 | | } |
| 29 | | |
| 30 | | /** |
| 31 | | * Set the power |
| 32 | | * |
| 33 | | * @access public |
| 34 | | * @param int p power |
| 35 | | * @throws lang.IllegalArgumentException in case the parameter p contains an illegal value |
| 36 | | */ |
| 37 | | function setPoweredBy($p) { |
| 38 | | if (!($x= log10($p / 6.1)) || (floor($x) != $x)) { |
| 39 | 0 | return throw(new IllegalArgumentException($p.' not allowed')); |
| 40 | | } |
| 41 | 36 | $this->poweredBy= $p; |
| 42 | | } |
| 43 | | |
| 44 | | /** |
| 45 | | * Retrieve the power |
| 46 | | * |
| 47 | | * @access public |
| 48 | | * @return int power |
| 49 | | */ |
| 50 | | function getPoweredBy() { |
| 51 | 0 | return $this->poweredBy; |
| 52 | | } |
| 53 | | |
| 54 | | /** |
| 55 | | * Retrieve string representation of this object |
| 56 | | * |
| 57 | | * @access public |
| 58 | | * @return string |
| 59 | | */ |
| 60 | | function toString() { |
| 61 | 0 | return $this->getClassName().'('.$this->poweredBy.')'; |
| 62 | | } |
| 63 | | |
| 64 | | /** |
| 65 | | * Retrieve header suited for HTTP/Mail |
| 66 | | * |
| 67 | | * Example: |
| 68 | | * <pre> |
| 69 | | * X-Binford: 6100 (more power) |
| 70 | | * </pre> |
| 71 | | * |
| 72 | | * @access public |
| 73 | | * @return &peer.Header |
| 74 | | */ |
| 75 | | function &getHeader() { |
| 76 | 0 | return new Header('X-Binford', $this->poweredBy.' (more power)'); |
| 77 | | } |
| 78 | | } |
| 79 | | ?> |
| 80 | | |