PHP Conference Japan 2024

svn_ls

(PECL svn >= 0.1.0)

svn_ls傳回儲存庫 URL 中目錄內容的列表,可選擇特定修訂版本

描述

svn_ls(
    string $repos_url,
    int $revision_no = SVN_REVISION_HEAD,
    bool $recurse = false,
    bool $peg = false
):array

此函式查詢儲存庫 URL 並傳回檔案和目錄的列表,可選擇特定修訂版本。這相當於 svn list $repos_url[@$revision_no]

注意:

此函式不適用於工作副本。repos_url必須是儲存庫 URL。

參數

url

儲存庫的 URL,例如 http://www.example.com/svnroot。若要透過檔案系統存取本機 Subversion 儲存庫,請使用 file URI 方案,例如 file:///home/user/svn-repos

revision

要擷取列表的整數修訂版本號碼。若省略,則使用 HEAD 修訂版本。

recurse

啟用遞迴。

傳回值

成功時,此函式會傳回檔案列表的陣列,格式如下:

[0] => Array
    (
        [created_rev] => integer revision number of last edit
        [last_author] => string author name of last edit
        [size] => integer byte file size of file
        [time] => string date of last edit in form 'M d H:i'
                  or 'M d Y', depending on how old the file is
        [time_t] => integer unix timestamp of last edit
        [name] => name of file/directory
        [type] => type, can be 'file' or 'dir'
    )
[1] => ...

範例

範例 1:svn_ls() 範例

<?php
print_r
( svn_ls('http://www.example.com/svnroot/') );
?>

上述範例會輸出類似以下的內容:

Array
(
    [0] => Array
        (
            [created_rev] => 20
            [last_author] => Joe
            [size] => 0
            [time] => Apr 02 09:28
            [time_t] => 1175520529
            [name] => tags
            [type] => dir
        )
    [1] => Array
        (
            [created_rev] => 23
            [last_author] => Bob
            [size] => 0
            [time] => Apr 02 15:15
            [time_t] => 1175541322
            [name] => trunk
            [type] => dir
        )
)

注意

警告

此函式為實驗性。此函式的行為、名稱和相關文件可能會在未來的 PHP 版本中變更,恕不另行通知。使用此函式風險自負。

新增註解

使用者貢獻的註解 1 則註解

0
php thereatthe bluedream dotty tv
12 年前
請注意,此函式會為您處理路徑;請勿自行處理,否則會產生錯誤。

例如:路徑中有空格時,不需要跳脫斜線
<?php
svn_ls
('file:///var/svn/myrepo/dirA/another dir'); //會成功->開心
svn_ls('file:///var/svn/myrepo/dirA/another\ dir'); //會失敗
?>
Warning: svn_ls(): svn error(s) occured 160013 (Filesystem has no item) URL 'file:///var/svn/myrepo/dirA/another\ dir' non-existent in that revision in file.php on line 42
To Top