-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
2,318 additions
and
3,043 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Illuminate\Console; | ||
|
||
use Symfony\Component\Console\Input\ArgvInput as ConsoleArgvInput; | ||
|
||
class ArgvInput extends ConsoleArgvInput | ||
{ | ||
private $argv = array(); | ||
/** | ||
* Constructor. | ||
* | ||
* @param array $argv An array of parameters from the CLI (in the argv format) | ||
* @param InputDefinition $definition A InputDefinition instance | ||
*/ | ||
public function __construct(array $argv = null, InputDefinition $definition = null) | ||
{ | ||
if (null === $argv) { | ||
$argv = $_SERVER['argv']; | ||
} | ||
|
||
$this->argv = $argv; | ||
|
||
// strip the application name | ||
array_shift($this->argv); | ||
|
||
parent::__construct($argv, $definition); | ||
} | ||
|
||
public function removeParameterOption($values, $onlyParams = false) | ||
{ | ||
$index = $this->indexParameterOption($values, $onlyParams); | ||
if ($index !== false) { | ||
unset($this->argv[$index]); | ||
$this->setTokens($this->argv = array_values($this->argv)); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the raw parameters (not parsed) contain a value. | ||
* | ||
* This method is to be used to introspect the input parameters | ||
* before they have been validated. It must be used carefully. | ||
* | ||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array) | ||
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal | ||
* | ||
* @return bool true if the value is contained in the raw parameters | ||
*/ | ||
public function indexParameterOption($values, $onlyParams = false) | ||
{ | ||
$values = (array) $values; | ||
|
||
foreach ($this->argv as $index => $token) { | ||
if ($onlyParams && $token === '--') { | ||
return false; | ||
} | ||
foreach ($values as $value) { | ||
if ($token === $value || 0 === strpos($token, $value.'=')) { | ||
return $index; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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,209 @@ | ||
<?php | ||
|
||
namespace Illuminate\Console\Command; | ||
|
||
use Closure; | ||
use Illuminate\Support\Str; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
class Source | ||
{ | ||
protected $tokens; | ||
|
||
protected $count; | ||
|
||
protected $index; | ||
|
||
/** | ||
* Get the command class for the file | ||
* | ||
* @param string|array|\Symfony\Component\Finder\SplFileInfo $source | ||
* | ||
* @return void | ||
*/ | ||
|
||
public function __construct($source) | ||
{ | ||
$source = $this->getContents($source); | ||
$this->tokens = token_get_all($source); | ||
$this->count = count($this->tokens); | ||
$this->index = -1; | ||
} | ||
|
||
/** | ||
* Get the command source from file | ||
* | ||
* @param string|\Symfony\Component\Finder\SplFileInfo $file | ||
* | ||
* @return static | ||
*/ | ||
public static function fromFile($file) | ||
{ | ||
if (!$file instanceof SplFileInfo) { | ||
$file = new SplFileInfo($file, null, null); | ||
} | ||
|
||
return new static($file); | ||
} | ||
|
||
/** | ||
* Get the command class for the file | ||
* | ||
* @param string|\Symfony\Component\Finder\SplFileInfo $file | ||
* | ||
* @return string | ||
*/ | ||
protected function getContents($source) | ||
{ | ||
if ($source instanceof SplFileInfo) { | ||
$source = $source->getContents(); | ||
} | ||
|
||
if (is_array($source)) { | ||
$source = implode(PHP_EOL, $source); | ||
} | ||
|
||
if (!Str::startsWith($source, '<?php')) { | ||
$source = '<?php ' . ltrim($source); | ||
} | ||
|
||
return $source; | ||
} | ||
|
||
protected function findToken($posibleTokens, Closure $where = null) | ||
{ | ||
if ($hasWhere = ($where instanceof Closure)) { | ||
$where = Closure::bind($where, $this); | ||
} | ||
$posibleTokens = (array) $posibleTokens; | ||
foreach ($this->getTokens() as $index => $token) { | ||
if (in_array($token['search'], $posibleTokens) && | ||
(!$hasWhere || ($where($index) && ($index = $this->index))) | ||
) { | ||
return $this->index = $index; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected function getTokenContent($posibleTokens, $start = null) | ||
{ | ||
$content = null; | ||
$posibleTokens = (array) $posibleTokens; | ||
$endTokens = ['{', ';', '(']; | ||
foreach ($this->getTokens($start) as $index => $token) { | ||
if (($content !==null && $token['number'] == T_WHITESPACE) || | ||
in_array($token['text'], $endTokens) | ||
) { | ||
break; | ||
} | ||
if (in_array($token['number'], $posibleTokens)) { | ||
$content .= $token['text']; | ||
$this->index = $index; | ||
} | ||
} | ||
|
||
return $content; | ||
} | ||
|
||
protected function getTokenContentUntil($posibleTokens, $after = null) | ||
{ | ||
$content = null; | ||
$posibleTokens = (array) $posibleTokens; | ||
$after = (array) $after; | ||
foreach ($this->getTokens() as $index => $token) { | ||
if (in_array($token['search'], $posibleTokens)) { | ||
break; | ||
} | ||
if ($token['number'] == T_WHITESPACE || | ||
($after && in_array($token['search'], $after)) | ||
) { | ||
continue; | ||
} | ||
$content .= $token['text']; | ||
$this->index = $index; | ||
$after = null; | ||
} | ||
|
||
return $content === null ? $content: trim($content); | ||
} | ||
|
||
protected function getTokens($start = null) | ||
{ | ||
$start = ($start ?: $this->index); | ||
for ($index = $start + 1; $index < $this->count; ++ $index) { | ||
yield $index => $this->getToken($index); | ||
} | ||
} | ||
|
||
protected function getToken($index) | ||
{ | ||
$token = $this->tokens[$index]; | ||
if (!is_array($token)) { | ||
$token = [null, $token]; | ||
} | ||
|
||
return [ | ||
'number' => $token[0], | ||
'text' => $token[1], | ||
'search' => $token[0] === null ? $token[1] : $token[0] | ||
]; | ||
} | ||
|
||
public function getNamespace() | ||
{ | ||
if ($this->findToken(T_NAMESPACE) && | ||
($namespace = $this->getTokenContent([T_STRING, T_NS_SEPARATOR])) | ||
) { | ||
if (!Str::startsWith($namespace, '\\')) { | ||
$namespace = "\\$namespace"; | ||
} | ||
|
||
return $namespace; | ||
} | ||
} | ||
|
||
public function getShortClassName() | ||
{ | ||
if ($this->findToken([T_CLASS, T_TRAIT]) && | ||
($className = $this->getTokenContent(T_STRING)) | ||
) { | ||
return $className; | ||
} | ||
} | ||
|
||
public function getClassName() | ||
{ | ||
$namespace = $this->getNamespace(); | ||
|
||
if ($className = $this->getShortClassName()) { | ||
return $namespace . '\\' . $className; | ||
} | ||
} | ||
|
||
public function getProperty($name) | ||
{ | ||
$name = array_map( | ||
function ($name) { | ||
if (!Str::startsWith($name, '$')) { | ||
$name = '$' . $name; | ||
} | ||
return $name; | ||
}, | ||
(array) $name | ||
); | ||
|
||
$where = function ($index) use ($name) { | ||
$varname = $this->getTokenContent(T_VARIABLE, $index); | ||
return $varname && in_array($varname, $name); | ||
}; | ||
|
||
if ($this->findToken([T_PRIVATE, T_PROTECTED, T_PUBLIC], $where)) { | ||
$properySource = $this->getTokenContentUntil(';', '='); | ||
return $properySource; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.