Adopting the GPL
[viewsvn.git] / includes / repository.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # ViewSVN [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Class that manages repositories and can produce lists of
24 * repositories
25 *
26 * @pacakge ViewSVN
27 */
28
29 /**
30 * Repository class that can list repositories and prepare
31 * them for use
32 *
33 * @package DeskPRO
34 * @version $Id$
35 */
36 class Repository
37 {
38 /**
39 * Array of valid repositories
40 * @var array
41 */
42 var $repositories = array();
43
44 /**
45 * Root path to the repository
46 * @var string
47 */
48 var $path;
49
50 /**
51 * Whether or not the path is a container
52 * @var bool
53 */
54 var $container;
55
56 /**
57 * Constructor: prepare for repository
58 *
59 * @param string Path to repository or container
60 * @param bool Whether the path is a container
61 */
62 function Repository($path, $iscontainer)
63 {
64 global $viewsvn;
65
66 $this->path = $viewsvn->fetch_sourcepath($path);
67 $this->container = (bool)$iscontainer;
68
69 if ($this->container)
70 {
71 if ($dir = @opendir($this->path))
72 {
73 while (($file = readdir($dir)) !== false)
74 {
75 if (is_dir($this->path . $file) AND $file{0} != '.' AND is_dir($this->path . $file . '/' . 'db'))
76 {
77 $this->repositories[] = $file;
78 }
79 }
80 closedir($dir);
81 }
82 }
83 else
84 {
85 if (is_dir($this->path . 'db'))
86 {
87 $this->repositories[] = $this->path;
88 }
89 }
90
91 if (count($this->repositories) < 1)
92 {
93 $viewsvn->trigger->error('no valid repositories');
94 }
95 }
96
97 /**
98 * Returns a list of repositories
99 *
100 * @access public
101 *
102 * @return array List of repositories
103 */
104 function fetch_list()
105 {
106 return $this->repositories;
107 }
108
109 /**
110 * Returns a path to a repository
111 *
112 * @access public
113 *
114 * @param string Repository name
115 *
116 * @return string Full path to the repository
117 */
118 function fetch_path($repository = '')
119 {
120 global $viewsvn;
121
122 if (!in_array($repository, $this->fetch_list()))
123 {
124 $viewsvn->trigger->error('invalid repository name');
125 }
126
127 if ($this->container)
128 {
129 return 'file://' . $this->path . $repository . '/';
130 }
131 else
132 {
133 return 'file://' . $this->path . '/';
134 }
135 }
136
137 /**
138 * Verifies a path inside a repository
139 *
140 * @access public
141 *
142 * @param string Repository name
143 * @param string Path
144 *
145 * @return bool Validity
146 */
147 function verify($repos, $path)
148 {
149 global $viewsvn;
150
151 if ($repospath = $this->fetch_path($repos))
152 {
153 return true;
154 }
155 else
156 {
157 return false;
158 }
159 }
160 }
161
162 /*=====================================================================*\
163 || ###################################################################
164 || # $HeadURL$
165 || # $Id$
166 || ###################################################################
167 \*=====================================================================*/
168 ?>