commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / packages / ezc / Base / src / metadata / pear.php
1 <?php
2 /**
3 * File containing the ezcBaseMetaDataPearReader class.
4 *
5 * @package Base
6 * @version 1.7
7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
8 * @license http://ez.no/licenses/new_bsd New BSD License
9 */
10
11 @require 'PEAR/Registry.php';
12
13 /**
14 * Base class implements ways of fetching information about the installed
15 * eZ Components when installed as tarball.
16 *
17 * Note: there are lots of @ used here, because PEAR still lives in the stone
18 * age with their PHP 3 code and general liberal use of throwing warnings and
19 * notices.
20 *
21 * @package Base
22 * @version 1.7
23 * @mainclass
24 */
25 class ezcBaseMetaDataPearReader
26 {
27 /**
28 * Stores the PEAR_Registry to query for information
29 *
30 * @var PEAR_Registry
31 */
32 private $registry;
33
34 /**
35 * Creates the reader object and initialized the registry for querying
36 */
37 public function __construct()
38 {
39 @$this->registry = new PEAR_Registry;
40 }
41
42 /**
43 * Returns the version string for the installed eZ Components bundle.
44 *
45 * A version string such as "2008.2.2" is returned.
46 *
47 * @return string
48 */
49 public function getBundleVersion()
50 {
51 @$packageInfo = $this->registry->packageInfo( 'ezcomponents', null, 'components.ez.no' );
52 return $packageInfo['version']['release'];
53 }
54
55 /**
56 * Returns a PHP version string that describes the required PHP version for
57 * this installed eZ Components bundle.
58 *
59 * @return string
60 */
61 public function getRequiredPhpVersion()
62 {
63 @$packageInfo = $this->registry->packageInfo( 'ezcomponents', null, 'components.ez.no' );
64 if ( array_key_exists( 'required', $packageInfo['dependencies'] ) )
65 {
66 return $packageInfo['dependencies']['required']['php']['min'];
67 }
68 return $packageInfo['dependencies']['php']['min'];
69 }
70
71 /**
72 * Returns whether $componentName is installed
73 *
74 * Checks the PEAR registry whether the component is there.
75 *
76 * @return bool
77 */
78 public function isComponentInstalled( $componentName )
79 {
80 @$packageInfo = $this->registry->packageInfo( $componentName, null, 'components.ez.no' );
81 return is_array( $packageInfo );
82 }
83
84 /**
85 * Returns the version string of the available $componentName or false when
86 * the component is not installed.
87 *
88 * @return string
89 */
90 public function getComponentVersion( $componentName )
91 {
92 @$packageInfo = $this->registry->packageInfo( $componentName, null, 'components.ez.no' );
93 $release = $packageInfo['version']['release'];
94 return $release === null ? false : $release;
95 }
96
97 /**
98 * Returns a list of components that $componentName depends on.
99 *
100 * If $componentName is left empty, all installed components are returned.
101 *
102 * The returned array has as keys the component names, and as values the
103 * version of the components.
104 *
105 * @return array(string=>string).
106 */
107 public function getComponentDependencies( $componentName = 'ezcomponents' )
108 {
109 @$packageInfo = $this->registry->packageInfo( $componentName, 'dependencies', 'components.ez.no' );
110 if ( isset( $packageInfo['required']['package'] ) )
111 {
112 $deps = array();
113 if ( isset( $packageInfo['required']['package']['name'] ) )
114 {
115 $deps[$packageInfo['required']['package']['name']] = $packageInfo['required']['package']['min'];
116 }
117 else
118 {
119 foreach ( $packageInfo['required']['package'] as $package )
120 {
121 $deps[$package['name']] = $package['min'];
122 }
123 }
124 return $deps;
125 }
126 return array();
127 }
128 }
129 ?>