root/trunk/examples/Color.php

Revision 43, 2.2 kB (checked in by schst, 2 years ago)

New feature: It is now possible to use dynamic setter methods based on the value of an attribute of a tag.

Line 
1 <?php
2 /**
3  * example class
4  *
5  * @author  Stephan Schmidt <stephan.schmidt@schlund.de>
6  * @author  Frank Kleine <frank.kleine@schlund.de>
7  */
8 /**
9  * example class
10  *
11  * @package     XJConf
12  * @subpackage  examples
13  */
14 class Color
15 {
16     /**
17      * the red part of the color
18      *
19      * @var  int
20      */
21     private $red        = null;
22     /**
23      * the green part of the color
24      *
25      * @var  int
26      */
27     private $green      = null;
28     /**
29      * the blue part of the color
30      *
31      * @var  int
32      */
33     private $blue       = null;
34     /**
35      * the name of the color
36      *
37      * @var  int
38      */
39     private $name       = null;
40     /**
41      * the title of the color
42      *
43      * @var  int
44      */
45     private $colorTitle = null;
46
47     /**
48      * constructor
49      *
50      * @var  string  $name  name of the color
51      */
52     public function  __construct($name = null)
53     {
54         $this->name = $name;
55     }
56
57     /**
58      * set the red part
59      *
60      * @param  int  $val
61      */
62     public function setRed($val)
63     {
64         $this->red = $val;
65     }
66
67     /**
68      * set the green part
69      *
70      * @param  int  $val
71      */
72     public function setGreen($val)
73     {
74         $this->green = $val;
75     }
76
77     /**
78      * set the blue part
79      *
80      * @param  int  $val
81      */
82     public function setBlue($val)
83     {
84         $this->blue = $val;
85     }
86
87     /**
88      * set the title of the color
89      *
90      * @param  string  $title
91      */
92     public function setColorTitle($title)
93     {
94         $this->colorTitle = $title;
95     }
96
97     /**
98      * get the rgb value as hex
99      *
100      * @return  string
101      */
102     public function getRGB()
103     {
104         return '#' . dechex($this->red) . dechex($this->green) . dechex($this->blue);
105     }
106
107     /**
108      * return the name of the color
109      *
110      * @return  string
111      */
112     public function getName()
113     {
114         return $this->name;
115     }
116
117     /**
118      * return the title of the color
119      *
120      * @return  string
121      */
122     public function getColorTitle()
123     {
124         return $this->colorTitle;
125     }
126
127     /**
128      * returns string representation
129      *
130      * @return  string
131      */
132     public function __toString()
133     {
134         return $this->name  . '(' . $this->getRGB() . ')';
135     }
136 }
137 ?>
Note: See TracBrowser for help on using the browser.