/components/lib/Components/Component/Base.php

https://github.com/finger2000/horde · PHP · 438 lines · 170 code · 33 blank · 235 comment · 1 complexity · 4a998c85e5415e57224571f135be2262 MD5 · raw file

  1. <?php
  2. /**
  3. * Represents base functionality for a component.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Horde
  8. * @package Components
  9. * @author Gunnar Wrobel <wrobel@pardus.de>
  10. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11. * @link http://pear.horde.org/index.php?package=Components
  12. */
  13. /**
  14. * Represents base functionality for a component.
  15. *
  16. * Copyright 2011 Horde LLC (http://www.horde.org/)
  17. *
  18. * See the enclosed file COPYING for license information (LGPL). If you
  19. * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  20. *
  21. * @category Horde
  22. * @package Components
  23. * @author Gunnar Wrobel <wrobel@pardus.de>
  24. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  25. * @link http://pear.horde.org/index.php?package=Components
  26. */
  27. abstract class Components_Component_Base implements Components_Component
  28. {
  29. /**
  30. * The configuration for the current job.
  31. *
  32. * @var Components_Config
  33. */
  34. private $_config;
  35. /**
  36. * The factory for additional helpers.
  37. *
  38. * @var Components_Component_Factory
  39. */
  40. private $_factory;
  41. /**
  42. * Constructor.
  43. *
  44. * @param Components_Config $config The configuration for the
  45. current job.
  46. * @param Components_Component_Factory $factory Generator for additional
  47. * helpers.
  48. */
  49. public function __construct(
  50. Components_Config $config,
  51. Components_Component_Factory $factory
  52. )
  53. {
  54. $this->_config = $config;
  55. $this->_factory = $factory;
  56. }
  57. /**
  58. * Return the name of the component.
  59. *
  60. * @return string The component name.
  61. */
  62. public function getName()
  63. {
  64. return $this->getPackageXml()->getName();
  65. }
  66. /**
  67. * Return the component summary.
  68. *
  69. * @return string The summary of the component.
  70. */
  71. public function getSummary()
  72. {
  73. return $this->getPackageXml()->getSummary();
  74. }
  75. /**
  76. * Return the component description.
  77. *
  78. * @return string The description of the component.
  79. */
  80. public function getDescription()
  81. {
  82. return $this->getPackageXml()->getDescription();
  83. }
  84. /**
  85. * Return the version of the component.
  86. *
  87. * @return string The component version.
  88. */
  89. public function getVersion()
  90. {
  91. return $this->getPackageXml()->getVersion();
  92. }
  93. /**
  94. * Return the channel of the component.
  95. *
  96. * @return string The component channel.
  97. */
  98. public function getChannel()
  99. {
  100. return $this->getPackageXml()->getChannel();
  101. }
  102. /**
  103. * Return the dependencies for the component.
  104. *
  105. * @return array The component dependencies.
  106. */
  107. public function getDependencies()
  108. {
  109. return $this->getPackageXml()->getDependencies();
  110. }
  111. /**
  112. * Return the stability of the release or api.
  113. *
  114. * @param string $key "release" or "api"
  115. *
  116. * @return string The stability.
  117. */
  118. public function getState($key = 'release')
  119. {
  120. return $this->getPackageXml()->getState($key);
  121. }
  122. /**
  123. * Return the package lead developers.
  124. *
  125. * @return string The package lead developers.
  126. */
  127. public function getLeads()
  128. {
  129. return $this->getPackageXml()->getLeads();
  130. }
  131. /**
  132. * Return the component license.
  133. *
  134. * @return string The component license.
  135. */
  136. public function getLicense()
  137. {
  138. return $this->getPackageXml()->getLicense();
  139. }
  140. /**
  141. * Return the component license URI.
  142. *
  143. * @return string The component license URI.
  144. */
  145. public function getLicenseLocation()
  146. {
  147. return $this->getPackageXml()->getLicenseLocation();
  148. }
  149. /**
  150. * Return the package notes.
  151. *
  152. * @return string The notes for the current release.
  153. */
  154. public function getNotes()
  155. {
  156. return $this->getPackageXml()->getNotes();
  157. }
  158. /**
  159. * Indicate if the component has a local package.xml.
  160. *
  161. * @return boolean True if a package.xml exists.
  162. */
  163. public function hasLocalPackageXml()
  164. {
  165. return false;
  166. }
  167. /**
  168. * Returns the link to the change log.
  169. *
  170. * @param Components_Helper_ChangeLog $helper The change log helper.
  171. *
  172. * @return string|null The link to the change log.
  173. */
  174. public function getChangelog($helper)
  175. {
  176. throw new Components_Exception(
  177. 'Not supported!'
  178. );
  179. }
  180. /**
  181. * Return the path to the release notes.
  182. *
  183. * @return string|boolean The path to the release notes or false.
  184. */
  185. public function getReleaseNotesPath()
  186. {
  187. return false;
  188. }
  189. /**
  190. * Return the dependency list for the component.
  191. *
  192. * @return Components_Component_DependencyList The dependency list.
  193. */
  194. public function getDependencyList()
  195. {
  196. return $this->_factory->createDependencyList($this);
  197. }
  198. /**
  199. * Return the path to a DOCS_ORIGIN file within the component.
  200. *
  201. * @return string|NULL The path name or NULL if there is no DOCS_ORIGIN file.
  202. */
  203. public function getDocumentOrigin()
  204. {
  205. }
  206. /**
  207. * Update the package.xml file for this component.
  208. *
  209. * @param string $action The action to perform. Either "update", "diff",
  210. * or "print".
  211. * @param array $options Options for this operation.
  212. *
  213. * @return NULL
  214. */
  215. public function updatePackageXml($action, $options)
  216. {
  217. throw new Components_Exception(
  218. 'Updating the package.xml is not supported!'
  219. );
  220. }
  221. /**
  222. * Update the component changelog.
  223. *
  224. * @param string $log The log entry.
  225. * @param Components_Helper_ChangeLog $helper The change log helper.
  226. * @param array $options Options for the operation.
  227. *
  228. * @return NULL
  229. */
  230. public function changed(
  231. $log, Components_Helper_ChangeLog $helper, $options
  232. )
  233. {
  234. throw new Components_Exception(
  235. 'Updating the change log is not supported!'
  236. );
  237. }
  238. /**
  239. * Timestamp the package.xml file with the current time.
  240. *
  241. * @param array $options Options for the operation.
  242. *
  243. * @return string The success message.
  244. */
  245. public function timestampAndSync($options)
  246. {
  247. throw new Components_Exception(
  248. 'Timestamping is not supported!'
  249. );
  250. }
  251. /**
  252. * Add the next version to the package.xml.
  253. *
  254. * @param string $version The new version number.
  255. * @param string $initial_note The text for the initial note.
  256. * @param string $stability_api The API stability for the next release.
  257. * @param string $stability_release The stability for the next release.
  258. * @param array $options Options for the operation.
  259. *
  260. * @return NULL
  261. */
  262. public function nextVersion(
  263. $version,
  264. $initial_note,
  265. $stability_api = null,
  266. $stability_release = null,
  267. $options = array()
  268. )
  269. {
  270. throw new Components_Exception(
  271. 'Setting the next version is not supported!'
  272. );
  273. }
  274. /**
  275. * Replace the current sentinel.
  276. *
  277. * @param string $changes New version for the CHANGES file.
  278. * @param string $app New version for the Application.php file.
  279. * @param array $options Options for the operation.
  280. *
  281. * @return string The success message.
  282. */
  283. public function currentSentinel($changes, $app, $options)
  284. {
  285. throw new Components_Exception(
  286. 'Modifying the sentinel is not supported!'
  287. );
  288. }
  289. /**
  290. * Set the next sentinel.
  291. *
  292. * @param string $changes New version for the CHANGES file.
  293. * @param string $app New version for the Application.php file.
  294. * @param array $options Options for the operation.
  295. *
  296. * @return string The success message.
  297. */
  298. public function nextSentinel($changes, $app, $options)
  299. {
  300. throw new Components_Exception(
  301. 'Modifying the sentinel is not supported!'
  302. );
  303. }
  304. /**
  305. * Tag the component.
  306. *
  307. * @param string $tag Tag name.
  308. * @param string $message Tag message.
  309. * @param Components_Helper_Commit $commit The commit helper.
  310. *
  311. * @return NULL
  312. */
  313. public function tag($tag, $message, $commit)
  314. {
  315. throw new Components_Exception(
  316. 'Tagging is not supported!'
  317. );
  318. }
  319. /**
  320. * Identify the repository root.
  321. *
  322. * @param Components_Helper_Root $helper The root helper.
  323. *
  324. * @return NULL
  325. */
  326. public function repositoryRoot(Components_Helper_Root $helper)
  327. {
  328. throw new Components_Exception(
  329. 'Identifying the repository root is not supported!'
  330. );
  331. }
  332. /**
  333. * Install the channel of this component in the environment.
  334. *
  335. * @param Components_Pear_Environment $env The environment to install
  336. * into.
  337. * @param array $options Install options.
  338. *
  339. * @return NULL
  340. */
  341. public function installChannel(
  342. Components_Pear_Environment $env, $options = array()
  343. )
  344. {
  345. $env->provideChannel(
  346. $this->getChannel(),
  347. $options,
  348. sprintf(' [required by %s]', $this->getName())
  349. );
  350. }
  351. /**
  352. * Return the application options.
  353. *
  354. * @return array The options.
  355. */
  356. protected function getOptions()
  357. {
  358. return $this->_config->getOptions();
  359. }
  360. /**
  361. * Return the factory.
  362. *
  363. * @return Components_Component_Factory The factory.
  364. */
  365. protected function getFactory()
  366. {
  367. return $this->_factory;
  368. }
  369. /**
  370. * Create the specified directory.
  371. *
  372. * @param string $destination The destination path.
  373. *
  374. * @return NULL
  375. */
  376. protected function createDestination($destination)
  377. {
  378. if (!file_exists($destination)) {
  379. mkdir($destination, 0700, true);
  380. }
  381. }
  382. /**
  383. * Return a PEAR package representation for the component.
  384. *
  385. * @return Horde_Pear_Package_Xml The package representation.
  386. */
  387. protected function getPackageXml()
  388. {
  389. throw new Component_Exception('Not supported!');
  390. }
  391. /**
  392. * Derive the basic PEAR install options from the current option set.
  393. *
  394. * @param array $options The current options.
  395. *
  396. * @return array The installatin options.
  397. */
  398. protected function getBaseInstallationOptions($options)
  399. {
  400. $installation_options = array();
  401. $installation_options['force'] = !empty($options['force']);
  402. $installation_options['nodeps'] = !empty($options['nodeps']);
  403. return $installation_options;
  404. }
  405. }