One Factory To Rule Them All

Have a script that needs to utilize several VersionControl_SVN subclasses? At the expense of a little overhead, you can be sure your $svn objects are fully-loaded by using the VersionControl_SVN::factory() command keyword __ALL__.

For example, in a basic script to get the list of current files in a repository, you just need the VersionControl_SVN::VersionControl_SVN_List() subclass.

Getting the list of current files in a 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'];
        }
    }
}
?>

However, if you need to get a recursive list of files in a repository, look up the recent log activity for those files, and view the annotated source for those files, you've got two options.

Recursively getting the list of current files in a 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_RAW);

// METHOD ONE: Lowest Overhead
// Create svn object with subcommands we need listed out individually
$svn VersionControl_SVN::factory(array('list''log''blame'), $options);

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

print_r($svn->list->run($args$switches));

// Pick files out of the above output, and see who did what
$args = array('svn://svn.example.com/repos/TestProject/trunk/index.php');

echo 
"<pre>" $svn->blame->run($args) . "</pre>";

// METHOD TWO: Put all available commands at your disposal
// Load up all subcommands - higher overhead, but convenient for certain occasions
$svn VersionControl_SVN::factory('__ALL__'$options);

// Now you may run whatever you need to ...
$svn->cat->run($args$switches);
$svn->info->run($args$switches);
// ... and so on.
?>
A Simple Example (Previous) Further Reading (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.