Vendor.php
<?php
namespace Taeluf\ProjectViewer;
class Vendor {
protected $name;
protected $rootDir;
protected $dir;
protected $gitDir;
protected $url;
protected $repos;
protected $webhookKey;
protected $projects = null;
public function __construct($name,$info){
$this->name = $name;
$rootDir = $info['dir'];
$this->rootDir = $rootDir;
$this->dir = $rootDir.'/repos/'.$name.'/';
$this->gitDir = $rootDir.'/git/'.$name.'/';
$this->url = $info['url'];
$this->repos = $info['repos'];
$this->webhookKey = $info['webhookKey'] ?? null;
}
public function name(){
return $this->name;
}
public function projectForUrl($url){
foreach ($this->projects() as $project){
$projUrl = $project->url();
$len = strlen($projUrl);
$urlCheck = substr($url,0,$len);
if ($projUrl==$urlCheck)return $project;
}
return false;
}
public function projects(){
if ($this->projects!==null)return $this->projects;
$projects = [];
foreach ($this->repos as $ownDir => $ProjectSettingsDontExistYet){
$path = $this->normalizePath($this->dir.'/'.$ownDir);
if (!is_dir($path)){
//@TODO consider throwing or triggering an error here
continue;
}
$path = realpath($path);
$projects[] = new Project($path,$this->url);
}
$this->projects = $projects;
return $projects;
}
public function normalizePath($path){
return str_replace(['///','//'], '/', $path);
}
}