upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -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;
}
}