phpDocumentor PEAR_PackageFileManager
[ class tree: PEAR_PackageFileManager ] [ index: PEAR_PackageFileManager ] [ all elements ]

Source for file Cvs.php

Documentation is available at Cvs.php


1 <?php
2 /**
3 * @package PEAR_PackageFileManager
4 */
5 /**
6 * The PEAR_PackageFileManager_File class
7 */
8 require_once 'PEAR/PackageFileManager/File.php';
9 /**
10 * Generate a file list from a CVS checkout
11 *
12 * Note that this will <b>NOT</b> work on a
13 * repository, only on a checked out CVS module
14 * @package PEAR_PackageFileManager
15 */
16 class PEAR_PackageFileManager_CVS extends PEAR_PackageFileManager_File {
17 /**
18 * Return a list of all files in the CVS repository
19 * @return array list of files in a directory
20 * @param string $directory full path to the directory you want the list of
21 * @uses _recurDirList()
22 * @uses _readCVSEntries()
23 */
24 function dirList($directory)
25 {
26 $entries = $this->_recurDirList($directory);
27 if (!$entries) {
28 return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_NOCVSENTRIES, $directory);
29 }
30 return $this->_readCVSEntries($entries);
31 }
32
33 /**
34 * Pull all the CVS/Entries files out from the base
35 * directory
36 * @param string current directory to traverse
37 * @access private
38 */
39 function _recurDirList($directory)
40 {
41 $ret = false;
42 if (@is_dir($directory)) {
43 $ret = array();
44 $d = @dir($directory); // thanks to Jason E Sweat (jsweat@users.sourceforge.net) for fix
45 while($d && $entry=$d->read()) {
46 if ($entry{0} != '.') {
47 if (is_file($directory . '/' . $entry) && (strcmp($entry, 'Entries') == 0)) {
48 $ret[] = $directory . '/' . $entry;
49 }
50 if (is_dir($directory . '/' . $entry)) {
51 $tmp = $this->_recurDirList($directory . '/' . $entry);
52 if (is_array($tmp)) {
53 foreach($tmp as $ent) {
54 $ret[] = $ent;
55 }
56 }
57 }
58 }
59 }
60 if ($d) {
61 $d->close();
62 }
63 } else {
64 return PEAR_PackageFileManager::raiseError(PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST, $directory);
65 }
66 return $ret;
67 }
68
69 /**
70 * Iterate over the CVS Entries files, and retrieve every
71 * file in the repository
72 * @uses _getCVSEntries()
73 * @uses _isCVSFile()
74 * @param array array of full paths to CVS/Entries files
75 * @access private
76 */
77 function _readCVSEntries($entries)
78 {
79 $ret = array();
80 foreach($entries as $cvsentry) {
81 $directory = dirname(dirname($cvsentry));
82 $d = $this->_getCVSEntries($cvsentry);
83 if (!is_array($d)) {
84 continue;
85 }
86 foreach($d as $entry) {
87 if ($this->_isCVSFile($entry)) {
88 $ret[] = $directory . '/' . $this->_getCVSFileName($entry);
89 }
90 }
91 }
92 return $ret;
93 }
94
95 /**
96 * Retrieve the filename from an entry
97 *
98 * This method assumes that the entry is a file,
99 * use _isCVSFile() to verify before calling
100 * @param string a line in a CVS/Entries file
101 * @return string the filename (no path information)
102 * @access private
103 */
104 function _getCVSFileName($cvsentry)
105 {
106 $stuff = explode('/', $cvsentry);
107 array_shift($stuff);
108 return array_shift($stuff);
109 }
110
111 /**
112 * Retrieve the entries in a CVS/Entries file
113 * @return array each line of the entries file, output of file()
114 * @uses function file()
115 * @param string full path to a CVS/Entries file
116 * @access private
117 */
118 function _getCVSEntries($cvsentryfilename)
119 {
120 $cvsfile = @file($cvsentryfilename);
121 if (is_array($cvsfile)) {
122 return $cvsfile;
123 } else {
124 return false;
125 }
126 }
127
128 /**
129 * Check whether an entry is a file or a directory
130 * @return boolean
131 * @param string a line in a CVS/Entries file
132 * @access private
133 */
134 function _isCVSFile($cvsentry)
135 {
136 return $cvsentry{0} == '/';
137 }
138 }
139 ?>

Documentation generated on Tue, 22 Jul 2003 15:09:35 -0400 by phpDocumentor 1.2.1