]> src.bluestatic.org Git - viewsvn.git/blob - includes/repository.php
Lots of documentation updates
[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 * @access private
42 */
43 var $repositories = array();
44
45 /**
46 * Root path to the repository
47 * @var string
48 * @access private
49 */
50 var $path;
51
52 /**
53 * Whether or not the path is a container
54 * @var bool
55 * @access private
56 */
57 var $container;
58
59 // ###################################################################
60 /**
61 * Constructor: prepare for repository
62 *
63 * @param string Path to repository or container
64 * @param bool Whether the path is a container
65 */
66 function Repository($path, $iscontainer)
67 {
68 global $viewsvn;
69
70 $this->path = $viewsvn->fetch_sourcepath($path);
71 $this->container = (bool)$iscontainer;
72
73 if ($this->container)
74 {
75 if ($dir = @opendir($this->path))
76 {
77 while (($file = readdir($dir)) !== false)
78 {
79 if (is_dir($this->path . $file) AND $file{0} != '.' AND is_dir($this->path . $file . '/' . 'db'))
80 {
81 $this->repositories[] = $file;
82 }
83 }
84 closedir($dir);
85 }
86 }
87 else
88 {
89 if (is_dir($this->path . 'db'))
90 {
91 $this->repositories[] = $this->path;
92 }
93 }
94
95 sort($this->repositories);
96
97 if (sizeof($this->repositories) < 1)
98 {
99 $viewsvn->trigger->error($viewsvn->lang->string('There are no valid repositories'));
100 }
101 }
102
103 // ###################################################################
104 /**
105 * Returns a list of repositories
106 *
107 * @access public
108 *
109 * @return array List of repositories
110 */
111 function fetch_list()
112 {
113 return $this->repositories;
114 }
115
116 // ###################################################################
117 /**
118 * Returns a path to a repository
119 *
120 * @access public
121 *
122 * @param string Repository name
123 *
124 * @return string Full path to the repository
125 */
126 function fetch_path($repository = '')
127 {
128 global $viewsvn;
129
130 if (!in_array($repository, $this->fetch_list()))
131 {
132 $viewsvn->trigger->error($viewsvn->lang->string('Invalid repository name specified'));
133 }
134
135 if ($this->container)
136 {
137 return 'file://' . $this->path . $repository;
138 }
139 else
140 {
141 return 'file://' . $this->path;
142 }
143 }
144
145 // ###################################################################
146 /**
147 * Verifies a path inside a repository
148 *
149 * @access public
150 *
151 * @param string Repository name
152 * @param string Path
153 *
154 * @return bool Validity
155 */
156 function verify($repos, $path)
157 {
158 global $viewsvn;
159
160 if ($repospath = $this->fetch_path($repos))
161 {
162 return true;
163 }
164 else
165 {
166 return false;
167 }
168 }
169 }
170
171 /*=====================================================================*\
172 || ###################################################################
173 || # $HeadURL$
174 || # $Id$
175 || ###################################################################
176 \*=====================================================================*/
177 ?>