Subversion Repositories Applications.gtt

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 jpm 1
<?php
2
/*
3
 * +------------------------------------------------------------------------+
4
 * | PEAR :: Package File Manager :: Perforce                               |
5
 * +------------------------------------------------------------------------+
6
 * | Copyright (c) 2004 Jon Parise                                          |
7
 * | Email         jon@php.net                                              |
8
 * +------------------------------------------------------------------------+
9
 * | This source file is subject to version 3.00 of the PHP License,        |
10
 * | that is available at http://www.php.net/license/3_0.txt.               |
11
 * | If you did not receive a copy of the PHP license and are unable to     |
12
 * | obtain it through the world-wide-web, please send a note to            |
13
 * | license@php.net so we can mail you a copy immediately.                 |
14
 * +------------------------------------------------------------------------+
15
 * $Id: Perforce.php,v 1.2 2004/08/25 06:02:30 jon Exp $
16
 */
17
 
18
/**
19
 * @package PEAR_PackageFileManager
20
 */
21
 
22
/**
23
 * The PEAR_PackageFileManager_File class
24
 */
25
require_once 'PEAR/PackageFileManager/File.php';
26
 
27
/**
28
 * Generate a file list from a Perforce checkout.  This requires the 'p4'
29
 * command line client, a properly-configured Perforce environment, and a
30
 * connection to the Perforce server.  Specifically, the 'p4 have' command
31
 * is used to determine which local files are under Perforce's control.
32
 *
33
 * @author  Jon Parise <jon@php.net>
34
 * @package PEAR_PackageFileManager
35
 */
36
class PEAR_PackageFileManager_Perforce extends PEAR_PackageFileManager_File
37
{
38
    /**
39
     * Build a list of files based on the output of the 'p4 have' command.
40
     *
41
     * @param   string  $directory  The directory in which to list the files.
42
     *
43
     * @return  mixed   An array of full filenames or a PEAR_Error value if
44
     *                  $directory does not exist.
45
     */
46
    function dirList($directory)
47
    {
48
        /* Return an error if the directory does not exist. */
49
        if (@is_dir($directory) === false) {
50
            return PEAR_PackageFileManager::raiseError(
51
                            PEAR_PACKAGEFILEMANAGER_DIR_DOESNT_EXIST,
52
                            $directory);
53
        }
54
 
55
        /* List the files below $directory that are under Perforce control. */
56
        exec("p4 have $directory/...", $output);
57
 
58
        /* Strip off everything except the filename from each line of output. */
59
        $files = preg_replace('/^.* \- /', '', $output);
60
 
61
        /* If we have a list of files to include, remove all other entries. */
62
        if ($this->ignore[0]) {
63
            $files = array_filter($files, array($this, '_includeFilter'));
64
        }
65
 
66
        /* If we have a list of files to ignore, remove them from the array. */
67
        if ($this->ignore[1]) {
68
            $files = array_filter($files, array($this, '_ignoreFilter'));
69
        }
70
 
71
        return $files;
72
    }
73
 
74
    /**
75
     * Determine whether a given file should be excluded from the file list.
76
     *
77
     * @param   string  $file       The full pathname of file to check.
78
     *
79
     * @return  bool    True if the specified file should be included.
80
     *
81
     * @access  private
82
     */
83
    function _includeFilter($file)
84
    {
85
        return ($this->_checkIgnore(basename($file), $file, 0) === 0);
86
    }
87
 
88
    /**
89
     * Determine whether a given file should be included (i.e., not ignored)
90
     * from the file list.
91
     *
92
     * @param   string  $file       The full pathname of file to check.
93
     *
94
     * @return  bool    True if the specified file should be included.
95
     *
96
     * @access  private
97
     */
98
    function _ignoreFilter($file)
99
    {
100
        return ($this->_checkIgnore(basename($file), $file, 1) !== 1);
101
    }
102
}