upgraded dependencies
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Laravel\Tinker;
|
||||
|
||||
use Psy\Shell;
|
||||
use Illuminate\Support\Str;
|
||||
use Psy\Shell;
|
||||
|
||||
class ClassAliasAutoloader
|
||||
{
|
||||
@@ -21,16 +21,39 @@ class ClassAliasAutoloader
|
||||
*/
|
||||
protected $classes = [];
|
||||
|
||||
/**
|
||||
* Path to the vendor directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $vendorPath;
|
||||
|
||||
/**
|
||||
* Explicitly included namespaces/classes.
|
||||
*
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $includedAliases;
|
||||
|
||||
/**
|
||||
* Excluded namespaces/classes.
|
||||
*
|
||||
* @var \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $excludedAliases;
|
||||
|
||||
/**
|
||||
* Register a new alias loader instance.
|
||||
*
|
||||
* @param \Psy\Shell $shell
|
||||
* @param string $classMapPath
|
||||
* @param array $includedAliases
|
||||
* @param array $excludedAliases
|
||||
* @return static
|
||||
*/
|
||||
public static function register(Shell $shell, $classMapPath)
|
||||
public static function register(Shell $shell, $classMapPath, array $includedAliases = [], array $excludedAliases = [])
|
||||
{
|
||||
return tap(new static($shell, $classMapPath), function ($loader) {
|
||||
return tap(new static($shell, $classMapPath, $includedAliases, $excludedAliases), function ($loader) {
|
||||
spl_autoload_register([$loader, 'aliasClass']);
|
||||
});
|
||||
}
|
||||
@@ -40,26 +63,21 @@ class ClassAliasAutoloader
|
||||
*
|
||||
* @param \Psy\Shell $shell
|
||||
* @param string $classMapPath
|
||||
* @param array $includedAliases
|
||||
* @param array $excludedAliases
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Shell $shell, $classMapPath)
|
||||
public function __construct(Shell $shell, $classMapPath, array $includedAliases = [], array $excludedAliases = [])
|
||||
{
|
||||
$this->shell = $shell;
|
||||
|
||||
$vendorPath = dirname(dirname($classMapPath));
|
||||
$this->vendorPath = dirname(dirname($classMapPath));
|
||||
$this->includedAliases = collect($includedAliases);
|
||||
$this->excludedAliases = collect($excludedAliases);
|
||||
|
||||
$classes = require $classMapPath;
|
||||
|
||||
$excludedAliases = collect(config('tinker.dont_alias', []));
|
||||
|
||||
foreach ($classes as $class => $path) {
|
||||
if (! Str::contains($class, '\\') || Str::startsWith($path, $vendorPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $excludedAliases->filter(function ($alias) use ($class) {
|
||||
return Str::startsWith($class, $alias);
|
||||
})->isEmpty()) {
|
||||
if (! $this->isAliasable($class, $path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -83,9 +101,7 @@ class ClassAliasAutoloader
|
||||
return;
|
||||
}
|
||||
|
||||
$fullName = isset($this->classes[$class])
|
||||
? $this->classes[$class]
|
||||
: false;
|
||||
$fullName = $this->classes[$class] ?? false;
|
||||
|
||||
if ($fullName) {
|
||||
$this->shell->writeStdout("[!] Aliasing '{$class}' to '{$fullName}' for this Tinker session.\n");
|
||||
@@ -113,4 +129,35 @@ class ClassAliasAutoloader
|
||||
{
|
||||
$this->unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a class may be aliased.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $path
|
||||
*/
|
||||
public function isAliasable($class, $path)
|
||||
{
|
||||
if (! Str::contains($class, '\\')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->includedAliases->filter(function ($alias) use ($class) {
|
||||
return Str::startsWith($class, $alias);
|
||||
})->isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Str::startsWith($path, $this->vendorPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->excludedAliases->filter(function ($alias) use ($class) {
|
||||
return Str::startsWith($class, $alias);
|
||||
})->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace Laravel\Tinker\Console;
|
||||
|
||||
use Psy\Shell;
|
||||
use Psy\Configuration;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Env;
|
||||
use Laravel\Tinker\ClassAliasAutoloader;
|
||||
use Psy\Configuration;
|
||||
use Psy\Shell;
|
||||
use Psy\VersionUpdater\Checker;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class TinkerCommand extends Command
|
||||
{
|
||||
@@ -16,7 +19,7 @@ class TinkerCommand extends Command
|
||||
* @var array
|
||||
*/
|
||||
protected $commandWhitelist = [
|
||||
'clear-compiled', 'down', 'env', 'inspire', 'migrate', 'optimize', 'up',
|
||||
'clear-compiled', 'down', 'env', 'inspire', 'migrate', 'migrate:install', 'optimize', 'up',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -36,36 +39,50 @@ class TinkerCommand extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->getApplication()->setCatchExceptions(false);
|
||||
|
||||
$config = new Configuration([
|
||||
'updateCheck' => 'never',
|
||||
]);
|
||||
$config = Configuration::fromInput($this->input);
|
||||
$config->setUpdateCheck(Checker::NEVER);
|
||||
|
||||
$config->getPresenter()->addCasters(
|
||||
$this->getCasters()
|
||||
);
|
||||
|
||||
if ($this->option('execute')) {
|
||||
$config->setRawOutput(true);
|
||||
}
|
||||
|
||||
$shell = new Shell($config);
|
||||
$shell->addCommands($this->getCommands());
|
||||
$shell->setIncludes($this->argument('include'));
|
||||
|
||||
if (isset($_ENV['COMPOSER_VENDOR_DIR'])) {
|
||||
$path = $_ENV['COMPOSER_VENDOR_DIR'];
|
||||
} else {
|
||||
$path = $this->getLaravel()->basePath().DIRECTORY_SEPARATOR.'vendor';
|
||||
}
|
||||
$path = Env::get('COMPOSER_VENDOR_DIR', $this->getLaravel()->basePath().DIRECTORY_SEPARATOR.'vendor');
|
||||
|
||||
$path .= '/composer/autoload_classmap.php';
|
||||
|
||||
$loader = ClassAliasAutoloader::register($shell, $path);
|
||||
$config = $this->getLaravel()->make('config');
|
||||
|
||||
$loader = ClassAliasAutoloader::register(
|
||||
$shell, $path, $config->get('tinker.alias', []), $config->get('tinker.dont_alias', [])
|
||||
);
|
||||
|
||||
if ($code = $this->option('execute')) {
|
||||
try {
|
||||
$shell->setOutput($this->output);
|
||||
$shell->execute($code);
|
||||
} finally {
|
||||
$loader->unregister();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
$shell->run();
|
||||
return $shell->run();
|
||||
} finally {
|
||||
$loader->unregister();
|
||||
}
|
||||
@@ -86,8 +103,12 @@ class TinkerCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
foreach (config('tinker.commands', []) as $command) {
|
||||
$commands[] = $this->getApplication()->resolve($command);
|
||||
$config = $this->getLaravel()->make('config');
|
||||
|
||||
foreach ($config->get('tinker.commands', []) as $command) {
|
||||
$commands[] = $this->getApplication()->add(
|
||||
$this->getLaravel()->make($command)
|
||||
);
|
||||
}
|
||||
|
||||
return $commands;
|
||||
@@ -102,6 +123,8 @@ class TinkerCommand extends Command
|
||||
{
|
||||
$casters = [
|
||||
'Illuminate\Support\Collection' => 'Laravel\Tinker\TinkerCaster::castCollection',
|
||||
'Illuminate\Support\HtmlString' => 'Laravel\Tinker\TinkerCaster::castHtmlString',
|
||||
'Illuminate\Support\Stringable' => 'Laravel\Tinker\TinkerCaster::castStringable',
|
||||
];
|
||||
|
||||
if (class_exists('Illuminate\Database\Eloquent\Model')) {
|
||||
@@ -112,7 +135,9 @@ class TinkerCommand extends Command
|
||||
$casters['Illuminate\Foundation\Application'] = 'Laravel\Tinker\TinkerCaster::castApplication';
|
||||
}
|
||||
|
||||
return $casters;
|
||||
$config = $this->getLaravel()->make('config');
|
||||
|
||||
return array_merge($casters, (array) $config->get('tinker.casters', []));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,4 +151,16 @@ class TinkerCommand extends Command
|
||||
['include', InputArgument::IS_ARRAY, 'Include file(s) before starting tinker'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['execute', null, InputOption::VALUE_OPTIONAL, 'Execute the given code using Tinker'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
50
vendor/laravel/tinker/src/TinkerCaster.php
vendored
50
vendor/laravel/tinker/src/TinkerCaster.php
vendored
@@ -68,6 +68,32 @@ class TinkerCaster
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representing the properties of an html string.
|
||||
*
|
||||
* @param \Illuminate\Support\HtmlString $htmlString
|
||||
* @return array
|
||||
*/
|
||||
public static function castHtmlString($htmlString)
|
||||
{
|
||||
return [
|
||||
Caster::PREFIX_VIRTUAL.'html' => $htmlString->toHtml(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representing the properties of a fluent string.
|
||||
*
|
||||
* @param \Illuminate\Support\Stringable $stringable
|
||||
* @return array
|
||||
*/
|
||||
public static function castStringable($stringable)
|
||||
{
|
||||
return [
|
||||
Caster::PREFIX_VIRTUAL.'value' => (string) $stringable,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representing the properties of a model.
|
||||
*
|
||||
@@ -84,10 +110,30 @@ class TinkerCaster
|
||||
$model->getVisible() ?: array_diff(array_keys($attributes), $model->getHidden())
|
||||
);
|
||||
|
||||
$hidden = array_flip($model->getHidden());
|
||||
|
||||
$appends = (function () {
|
||||
return array_combine($this->appends, $this->appends);
|
||||
})->bindTo($model, $model)();
|
||||
|
||||
foreach ($appends as $appended) {
|
||||
$attributes[$appended] = $model->{$appended};
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach (array_intersect_key($attributes, $visible) as $key => $value) {
|
||||
$results[(isset($visible[$key]) ? Caster::PREFIX_VIRTUAL : Caster::PREFIX_PROTECTED).$key] = $value;
|
||||
foreach ($attributes as $key => $value) {
|
||||
$prefix = '';
|
||||
|
||||
if (isset($visible[$key])) {
|
||||
$prefix = Caster::PREFIX_VIRTUAL;
|
||||
}
|
||||
|
||||
if (isset($hidden[$key])) {
|
||||
$prefix = Caster::PREFIX_PROTECTED;
|
||||
}
|
||||
|
||||
$results[$prefix.$key] = $value;
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
@@ -2,20 +2,14 @@
|
||||
|
||||
namespace Laravel\Tinker;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Tinker\Console\TinkerCommand;
|
||||
use Laravel\Lumen\Application as LumenApplication;
|
||||
use Illuminate\Contracts\Support\DeferrableProvider;
|
||||
use Illuminate\Foundation\Application as LaravelApplication;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Lumen\Application as LumenApplication;
|
||||
use Laravel\Tinker\Console\TinkerCommand;
|
||||
|
||||
class TinkerServiceProvider extends ServiceProvider
|
||||
class TinkerServiceProvider extends ServiceProvider implements DeferrableProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
|
Reference in New Issue
Block a user