Skip to content

Commit

Permalink
Artisan laravel 5.4 subtree.
Browse files Browse the repository at this point in the history
  • Loading branch information
loduis committed Jan 13, 2017
1 parent 282eb41 commit d021f2d
Show file tree
Hide file tree
Showing 90 changed files with 2,318 additions and 3,043 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"ext-mbstring": "*",
"ext-openssl": "*",
"league/flysystem": "~1.0",
"psy/psysh": "0.7.*",
"monolog/monolog": "~1.11",
"symfony/console": "~3.2",
"symfony/finder": "~3.2",
"symfony/http-foundation": "~3.2",
"symfony/http-kernel": "~3.2",
"symfony/process": "~3.2",
"vlucas/phpdotenv": "~2.2",
"paragonie/random_compat": "~1.4|~2.0"
"paragonie/random_compat": "~1.4|~2.0",
"laravel/tinker": "^1.0@dev"
},
"replace": {
"illuminate/config": "self.version",
Expand Down
67 changes: 67 additions & 0 deletions src/Illuminate/Console/ArgvInput.php
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;
}
}
209 changes: 209 additions & 0 deletions src/Illuminate/Console/Command/Source.php
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;
}
}
Loading

0 comments on commit d021f2d

Please sign in to comment.