forked from klaussilveira/gitlist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request klaussilveira#200 from cschorn/nested-repos
Recursive scanning (should fix klaussilveira#2)
- Loading branch information
Showing
14 changed files
with
190 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,26 @@ | ||
<?php | ||
|
||
namespace GitList\Provider; | ||
|
||
use GitList\Util\Routing; | ||
use Silex\Application; | ||
use Silex\ServiceProviderInterface; | ||
|
||
class RoutingUtilServiceProvider implements ServiceProviderInterface | ||
{ | ||
/** | ||
* Register the Util\Repository class on the Application ServiceProvider | ||
* | ||
* @param Application $app Silex Application | ||
*/ | ||
public function register(Application $app) | ||
{ | ||
$app['util.routing'] = $app->share(function () use ($app) { | ||
return new Routing($app); | ||
}); | ||
} | ||
|
||
public function boot(Application $app) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,52 @@ | ||
<?php | ||
|
||
namespace Gitlist\Util; | ||
|
||
use Silex\Application; | ||
|
||
class Routing | ||
{ | ||
protected $app; | ||
|
||
public function __construct(Application $app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
public function getRepositoryRegex() | ||
{ | ||
static $regex = null; | ||
|
||
if ($regex === null) { | ||
$app = $this->app; | ||
$quotedPaths = array_map( | ||
function ($repo) use ($app) { | ||
return preg_quote($app['util.routing']->getRelativePath($repo['path']), '#'); | ||
}, | ||
$this->app['git']->getRepositories($this->app['git.repos']) | ||
); | ||
usort($quotedPaths, function ($a, $b) { return strlen($b) - strlen($a); }); | ||
$regex = implode('|', $quotedPaths); | ||
} | ||
|
||
return $regex; | ||
} | ||
|
||
/** | ||
* Strips the base path from a full repository path | ||
* | ||
* @param string $repoPath Full path to the repository | ||
* @return string Relative path to the repository from git.repositories | ||
*/ | ||
public function getRelativePath($repoPath) | ||
{ | ||
if (strpos($repoPath, $this->app['git.repos']) === 0) { | ||
$relativePath = substr($repoPath, strlen($this->app['git.repos'])); | ||
return ltrim($relativePath, '/'); | ||
} else { | ||
throw new \InvalidArgumentException( | ||
sprintf("Path '%s' does not match configured repository directory", $repoPath) | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.