1<?php
2/**
3 * A class that describes an extension author or maintainer
4 *
5 * PHP versions 5
6 *
7 * LICENSE: This source file is subject to version 3.0 of the PHP license
8 * that is available through the world-wide-web at the following URI:
9 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
10 * the PHP License and are unable to obtain it through the web, please
11 * send a note to license@php.net so we can mail you a copy immediately.
12 *
13 * @category   Tools and Utilities
14 * @package    CodeGen
15 * @author     Hartmut Holzgraefe <hartmut@php.net>
16 * @copyright  2005-2008 Hartmut Holzgraefe
17 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
18 * @version    CVS: $Id: Maintainer.php,v 1.8 2007/04/18 14:37:13 hholzgra Exp $
19 * @link       http://pear.php.net/package/CodeGen
20 */
21
22/**
23 * A class that describes an extension author or maintainer
24 *
25 * This class wraps up the functionality needed for the
26 * command line script.
27 *
28 * @category   Tools and Utilities
29 * @package    CodeGen
30 * @author     Hartmut Holzgraefe <hartmut@php.net>
31 * @copyright  2005-2008 Hartmut Holzgraefe
32 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
33 * @version    Release: @package_version@
34 * @link       http://pear.php.net/package/CodeGen
35 */
36class CodeGen_Maintainer
37{
38    /**
39     * Users system account name
40     *
41     * @var string
42     */
43    protected $user;
44
45    /**
46     * Real name
47     *
48     * @var string
49     */
50    protected $name;
51
52    /**
53     * Email address
54     *
55     * @var string
56     */
57    protected $email;
58
59    /**
60     * Role in this project
61     *
62     * @var string
63     */
64    protected $role = "developer";
65
66    /**
67     * First maintainer added?
68     *
69     * @var bool
70     */
71    protected static $first = true;
72
73    /**
74     * Prefix to use in comment headers
75     *
76     * @var bool
77     */
78    protected $comment_prefix = "Authors:";
79
80    /**
81     * Constructor
82     *
83     * @access public
84     * @param  string  CVS user name
85     * @param  string  real name
86     * @param  string  email address
87     * @param  string  role in this project
88     */
89    function __construct($user="unknown", $name="Anonymous Coward", $email="unknown@example.org", $role="unknown")
90    {
91        $this->user  = $user;
92        $this->name  = $name;
93        $this->email = $email;
94        $this->role  = $role;
95
96        if (self::$first) {
97            self::$first = false;
98        } else {
99            $this->comment_prefix = "        ";
100        }
101    }
102
103    /**
104     * System user factory
105     *
106     * @access public
107     * @return Maintainer object
108     */
109    static function systemUser()
110    {
111        $userinfo = posix_getpwuid(posix_geteuid());
112        $hostinfo = posix_uname();
113
114        $user = $userinfo["name"];
115        $name = $userinfo["gecos"];
116        $email= $userinfo["name"]."@php.net"; // TODO detect real domain
117    }
118
119    /**
120     * Set CVS user name
121     *
122     * @access public
123     * @param  string CVS user name
124     * @return bool   true on success
125     */
126    function setUser($name)
127    {
128        if (!preg_match('|^[\w-]+$|i', $name)) {
129            return PEAR::raiseError("'$name' is not a valid CVS user name");
130        }
131
132        $this->user = $name;
133        return true;
134    }
135
136    /**
137     * CVS user getter
138     *
139     * @access public
140     * @return string
141     */
142    function getUser()
143    {
144        return $this->user;
145    }
146
147    /**
148     * Set real user name
149     *
150     * @access public
151     * @param  string user name
152     * @return bool   true on success
153     */
154    function setName($name)
155    {
156        $this->name = $name;
157        return true;
158    }
159
160    /**
161     * real name getter
162     *
163     * @access public
164     * @return string
165     */
166    function getName()
167    {
168        return $this->name;
169    }
170
171
172    /**
173     * Set email address
174     *
175     * @access public
176     * @param  string email address
177     * @return bool   true on success
178     */
179    function setEmail($email)
180    {
181        // TODO check for valid address
182
183        $this->email = $email;
184        return true;
185    }
186
187    /**
188     * email getter
189     *
190     * @access public
191     * @return string
192     */
193    function getEmail()
194    {
195        return $this->email;
196    }
197
198
199    /**
200     * Set project role
201     *
202     * @access public
203     * @param  string project role
204     * @return bool   true on success
205     */
206    function setRole($role)
207    {
208        switch ($role) {
209        case "lead":
210        case "developer":
211        case "contributor":
212        case "helper":
213            $this->role = $role;
214            return true;
215        default:
216            return PEAR::raiseError("'$role' is not a valid maintainer role");
217        }
218    }
219
220    /**
221     * Generate a comment header line for this author
222     *
223     * @access public
224     * @return string comment line
225     */
226    function comment()
227    {
228        $code   = sprintf("   | {$this->comment_prefix} %-59s |\n", "{$this->name} <{$this->email}>");
229        $prefix = "        ";
230
231        return $code;
232    }
233
234}
235/*
236 * Local variables:
237 * tab-width: 4
238 * c-basic-offset: 4
239 * indent-tabs-mode:nil
240 * End:
241 */
242
243?>
244