A Simple Example

So you've got Subversion repository set up somewhere, and you want to take a look at what's inside with a PHP script. With the VersionControl_SVN::VersionControl_SVN_List() command, you're just a few steps away.

Reading the content of a Subversion repository

<?php
require_once 'VersionControl/SVN.php';

// Setup error handling -- always a good idea!
$svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');

// Set up runtime options.
$options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ARRAY);
// Request list class from factory
$svn VersionControl_SVN::factory('list'$options);

// Define any switches and aguments we may need
$switches = array('username' => 'user''password' => 'pass');
$args = array('svn://svn.example.com/repos/TestProject');

// Run command
if ($output $svn->run($args$switches)) {
    
print_r($output);
} else {
    if (
count($errs $svnstack->getErrors())) {
        foreach (
$errs as $err) {
            echo 
'<br />'.$err['message']."<br />\n";
            echo 
"Command used: " $err['params']['cmd'];
        }
    }
}
?>

If your example repository above happened to have the VersionControl_SVN source in it, your output would be something like this:

<?php
Array
(
    [
0] => Array
        (
            [
name] => docs
            
[type] => D
        
)

    [
1] => Array
        (
            [
name] => package.xml
            
[type] => F
        
)

    [
2] => Array
        (
            [
name] => SVN.php
            
[type] => F
        
)

    [
3] => Array
        (
            [
name] => SVN
            
[type] => D
        
)

    [
4] => Array
        (
            [
name] => tests
            
[type] => D
        
)

)
?>

Note that in the above output, directories are flagged as type D, and files are flagged as type F.

For additional information in the output, try setting verbose to TRUE in your $options array.

Introduction (Previous) One Factory To Rule Them All (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.