DNProject::getRepositoryInterface PHP Method

getRepositoryInterface() public method

Get a ViewableData structure describing the UI tool that lets the user view the repository code
public getRepositoryInterface ( ) : ArrayData
return ArrayData
    public function getRepositoryInterface()
    {
        $interfaces = $this->config()->repository_interfaces;
        /* Look for each whitelisted hostname */
        foreach ($interfaces as $host => $interface) {
            /* See if the CVS Path is for this hostname, followed by some junk (maybe a port), then the path */
            if (preg_match('{^[^.]*' . $host . '(.*?)([/a-zA-Z].+)}', $this->CVSPath, $match)) {
                $path = $match[2];
                $scheme = isset($interface['scheme']) ? $interface['scheme'] : 'https';
                $host = isset($interface['host']) ? $interface['host'] : $host;
                $regex = isset($interface['regex']) ? $interface['regex'] : ['\\.git$' => ''];
                $components = explode('.', $host);
                foreach ($regex as $pattern => $replacement) {
                    $path = preg_replace('/' . $pattern . '/', $replacement, $path);
                }
                $uxurl = Controller::join_links($scheme . '://', $host, $path);
                if (array_key_exists('commit', $interface) && $interface['commit'] == false) {
                    $commiturl = false;
                } else {
                    $commiturl = Controller::join_links($uxurl, isset($interface['commit']) ? $interface['commit'] : 'commit');
                }
                return new ArrayData(['Name' => isset($interface['name']) ? $interface['name'] : ucfirst($components[0]), 'Icon' => isset($interface['icon']) ? $interface['icon'] : 'deploynaut/img/git.png', 'URL' => $uxurl, 'CommitURL' => $commiturl]);
            }
        }
    }

Usage Example

 public function testURLParsing()
 {
     $shouldMatchURLs = array('https://github.com/silverstripe/deploynaut.git', 'github.com:silverstripe/deploynaut.git', '[email protected]:silverstripe/deploynaut.git', 'ssh://[email protected]:22/silverstripe/deploynaut.git');
     $project = new DNProject();
     foreach ($shouldMatchURLs as $url) {
         $project->CVSPath = $url;
         $repositoryInterface = $project->getRepositoryInterface();
         $this->assertEquals('https://github.com/silverstripe/deploynaut', $repositoryInterface->URL, "Failed to extract repository from " . $url);
     }
     $shouldntMatchURLs = array('https://othersite.com/github.com/ranking');
     foreach ($shouldntMatchURLs as $url) {
         $project->CVSPath = $url;
         $repositoryInterface = $project->getRepositoryInterface();
         $this->assertNull($repositoryInterface);
     }
 }
All Usage Examples Of DNProject::getRepositoryInterface