1: <?php
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: class Horde_Pear_Package_Type_Horde
29: implements Horde_Pear_Package_Type
30: {
31: 32: 33: 34: 35:
36: private $_root;
37:
38: 39: 40: 41: 42:
43: private $_repository_root;
44:
45: 46: 47: 48: 49:
50: public function __construct($root, $repository_root = null)
51: {
52: $this->_root = $root;
53: $this->_repository_root = $repository_root;
54: }
55:
56: 57: 58: 59: 60:
61: public function getRootPath()
62: {
63: return $this->_root;
64: }
65:
66: 67: 68: 69: 70:
71: public function getPackageXmlPath()
72: {
73: return $this->_root . '/package.xml';
74: }
75:
76: 77: 78: 79: 80:
81: public function getInclude()
82: {
83: return new Horde_Pear_Package_Contents_Include_All();
84: }
85:
86: 87: 88: 89: 90:
91: public function getIgnore()
92: {
93: return new Horde_Pear_Package_Contents_Ignore_Composite(
94: array(
95: new Horde_Pear_Package_Contents_Ignore_Dot(),
96: new Horde_Pear_Package_Contents_Ignore_Patterns(
97: array(
98: '/package.xml',
99: '*~',
100: 'conf.php',
101: 'CVS/*',
102: 'bin/.htaccess',
103: ),
104: $this->getRootPath()
105: ),
106: new Horde_Pear_Package_Contents_Ignore_Git(
107: $this->getGitIgnore(),
108: $this->getRepositoryRoot()
109: ),
110: )
111: );
112: }
113:
114: 115: 116: 117: 118:
119: public function getRole()
120: {
121: $class = 'Horde_Pear_Package_Contents_Role_Horde' . $this->getType();
122: return new $class();
123: }
124:
125: 126: 127: 128: 129:
130: public function getInstallAs()
131: {
132: switch ($this->getName()) {
133: case 'horde':
134: case 'groupware':
135: case 'webmail':
136: case 'kolab_webmail':
137: $class = 'Horde_Pear_Package_Contents_InstallAs_Horde';
138: break;
139: case 'Horde_Role':
140: $class = 'Horde_Pear_Package_Contents_InstallAs_HordeRole';
141: break;
142: case 'components':
143: $class = 'Horde_Pear_Package_Contents_InstallAs_HordeComponent';
144: break;
145: default:
146: $class = 'Horde_Pear_Package_Contents_InstallAs_Horde' . $this->getType();
147: break;
148: }
149: return new $class($this);
150: }
151:
152: 153: 154: 155: 156:
157: public function getType()
158: {
159: $location = substr($this->getRootPath(), strlen($this->getRepositoryRoot()));
160: if (substr($location, 0, 10) == '/framework') {
161: return 'Component';
162: } else {
163: return 'Application';
164: }
165: }
166:
167: 168: 169: 170: 171:
172: public function getName()
173: {
174: if ($this->getType() == 'Application') {
175: return basename($this->getRootPath());
176: } else {
177: return 'Horde_' . basename($this->getRootPath());
178: }
179: }
180:
181: 182: 183: 184: 185:
186: public function getGitIgnore()
187: {
188: return file_get_contents($this->getRepositoryRoot() . '/.gitignore');
189: }
190:
191: 192: 193: 194: 195:
196: public function getRepositoryRoot()
197: {
198: if ($this->_repository_root === null) {
199: $i = 0;
200: $current = $this->getRootPath();
201: while ($current != '/' || $i < 10) {
202: if (is_dir($current)) {
203: $elements = scandir($current);
204: if (in_array('framework', $elements)
205: && in_array('horde', $elements)
206: && in_array('.gitignore', $elements)) {
207: $this->_repository_root = $current;
208: break;
209: }
210: }
211: $current = dirname($current);
212: $i++;
213: }
214: if ($this->_repository_root === null) {
215: throw new Horde_Pear_Exception(
216: sprintf(
217: 'Unable to determine Horde root from path %s!',
218: $this->getRootPath()
219: )
220: );
221: }
222: }
223: return $this->_repository_root;
224: }
225:
226: 227: 228: 229: 230:
231: public function writePackageXmlDraft()
232: {
233: if (file_exists($this->getPackageXmlPath())) {
234: throw new Horde_Pear_Exception(
235: sprintf(
236: 'File %s already exists and will not be overwritten!',
237: $this->getPackageXmlPath()
238: )
239: );
240: }
241: file_put_contents(
242: $this->getPackageXmlPath(),
243: '<?xml version="1.0" encoding="UTF-8"?>
244: <package packagerversion="1.9.2" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
245: <name>' . $this->getName() . '</name>
246: <channel>pear.horde.org</channel>
247: <summary>TODO</summary>
248: <description>TODO</description>
249: <lead>
250: <name>Chuck Hagenbuch</name>
251: <user>chuck</user>
252: <email>chuck@horde.org</email>
253: <active>yes</active>
254: </lead>
255: <lead>
256: <name>Jan Schneider</name>
257: <user>jan</user>
258: <email>jan@horde.org</email>
259: <active>yes</active>
260: </lead>
261: <date>' . date('Y-m-d') . '</date>
262: <time>' . date('H:i:s') . '</time>
263: <version>
264: <release>1.0.0alpha1</release>
265: <api>1.0.0alpha1</api>
266: </version>
267: <stability>
268: <release>alpha</release>
269: <api>alpha</api>
270: </stability>
271: <license uri="TODO">TODO</license>
272: <notes>
273: * Initial release.
274: </notes>
275: <dependencies>
276: <required>
277: <php>
278: <min>5.2.0</min>
279: </php>
280: <pearinstaller>
281: <min>1.7.0</min>
282: </pearinstaller>
283: </required>
284: </dependencies>
285: <changelog>
286: <release>
287: <version>
288: <release>1.0.0alpha1</release>
289: <api>1.0.0alpha1</api>
290: </version>
291: <stability>
292: <release>alpha</release>
293: <api>alpha</api>
294: </stability>
295: <date>' . date('Y-m-d') . '</date>
296: <license uri="TODO">TODO</license>
297: <notes>
298: * Initial release.
299: </notes>
300: </release>
301: </changelog>
302: </package>'
303: );
304: }
305: }