Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental Robo plugin feature (#671)
- Loading branch information
1 parent
79c04e5
commit cd88c29
Showing
12 changed files
with
473 additions
and
23 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
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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* if we're running from phar load the phar autoload, | ||
* else let the script 'robo' search for the autoloader | ||
* else let the script 'robo' search for the autoloader. | ||
* If we cannot find a vendor/autoload.php file, then | ||
* we will go ahead and try the phar. | ||
*/ | ||
if (strpos(basename(__FILE__), 'phar')) { | ||
require_once 'phar://robo.phar/vendor/autoload.php'; | ||
} else { | ||
$autoloaderPath = 'phar://robo.phar/vendor/autoload.php'; | ||
if (!strpos(basename(__FILE__), 'phar')) { | ||
if (file_exists(__DIR__.'/vendor/autoload.php')) { | ||
require_once __DIR__.'/vendor/autoload.php'; | ||
$autoloaderPath = __DIR__.'/vendor/autoload.php'; | ||
} elseif (file_exists(__DIR__.'/../../autoload.php')) { | ||
require_once __DIR__ . '/../../autoload.php'; | ||
} else { | ||
require_once 'phar://robo.phar/vendor/autoload.php'; | ||
$autoloaderPath = __DIR__ . '/../../autoload.php'; | ||
} | ||
} | ||
$classLoader = require $autoloaderPath; | ||
$runner = new \Robo\Runner(); | ||
$runner->setSelfUpdateRepository('consolidation/robo'); | ||
$runner | ||
->setRelativePluginNamespace('Robo\Plugin') | ||
->setSelfUpdateRepository('consolidation/robo') | ||
->setClassLoader($classLoader); | ||
$statusCode = $runner->execute($_SERVER['argv']); | ||
exit($statusCode); | ||
exit($statusCode); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
greg-1-anderson
Member
|
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 Robo\ClassDiscovery; | ||
|
||
/** | ||
* Class AbstractClassDiscovery | ||
* | ||
* @package Robo\ClassDiscovery | ||
*/ | ||
abstract class AbstractClassDiscovery implements ClassDiscoveryInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $searchPattern = '*.php'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setSearchPattern($searchPattern) | ||
{ | ||
$this->searchPattern = $searchPattern; | ||
|
||
return $this; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace Robo\ClassDiscovery; | ||
|
||
/** | ||
* Interface ClassDiscoveryInterface | ||
* | ||
* @package Robo\Plugin\ClassDiscovery | ||
*/ | ||
interface ClassDiscoveryInterface | ||
{ | ||
/** | ||
* @param $searchPattern | ||
* | ||
* @return $this | ||
*/ | ||
public function setSearchPattern($searchPattern); | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getClasses(); | ||
|
||
/** | ||
* @param $class | ||
* | ||
* @return string|null | ||
*/ | ||
public function getFile($class); | ||
} |
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,112 @@ | ||
<?php | ||
|
||
namespace Robo\ClassDiscovery; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
use Composer\Autoload\ClassLoader; | ||
|
||
/** | ||
* Class RelativeNamespaceDiscovery | ||
* | ||
* @package Robo\Plugin\ClassDiscovery | ||
*/ | ||
class RelativeNamespaceDiscovery extends AbstractClassDiscovery | ||
{ | ||
/** | ||
* @var \Composer\Autoload\ClassLoader | ||
*/ | ||
protected $classLoader; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $relativeNamespace = ''; | ||
|
||
/** | ||
* RelativeNamespaceDiscovery constructor. | ||
* | ||
* @param \Composer\Autoload\ClassLoader $classLoader | ||
*/ | ||
public function __construct(ClassLoader $classLoader) | ||
{ | ||
$this->classLoader = $classLoader; | ||
} | ||
|
||
/** | ||
* @param string $relativeNamespace | ||
* | ||
* @return RelativeNamespaceDiscovery | ||
*/ | ||
public function setRelativeNamespace($relativeNamespace) | ||
{ | ||
$this->relativeNamespace = $relativeNamespace; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getClasses() | ||
{ | ||
$classes = []; | ||
$relativePath = $this->convertNamespaceToPath($this->relativeNamespace); | ||
|
||
foreach ($this->classLoader->getPrefixesPsr4() as $baseNamespace => $directories) { | ||
$directories = array_filter(array_map(function ($directory) use ($relativePath) { | ||
return $directory.$relativePath; | ||
}, $directories), 'is_dir'); | ||
|
||
if ($directories) { | ||
foreach ($this->search($directories, $this->searchPattern) as $file) { | ||
$relativePathName = $file->getRelativePathname(); | ||
$classes[] = $baseNamespace.$this->convertPathToNamespace($relativePath.'/'.$relativePathName); | ||
} | ||
} | ||
} | ||
|
||
return $classes; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFile($class) | ||
{ | ||
return $this->classLoader->findFile($class); | ||
} | ||
|
||
/** | ||
* @param $directories | ||
* @param $pattern | ||
* | ||
* @return \Symfony\Component\Finder\Finder | ||
*/ | ||
protected function search($directories, $pattern) | ||
{ | ||
$finder = new Finder(); | ||
$finder->files() | ||
->name($pattern) | ||
->in($directories); | ||
|
||
return $finder; | ||
} | ||
|
||
/** | ||
* @param $path | ||
* | ||
* @return mixed | ||
*/ | ||
protected function convertPathToNamespace($path) | ||
{ | ||
return str_replace(['/', '.php'], ['\\', ''], trim($path, '/')); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function convertNamespaceToPath($namespace) | ||
{ | ||
return '/'.str_replace("\\", '/', trim($namespace, '\\')); | ||
} | ||
} |
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
Oops, something went wrong.
😖