Skip to content

Commit 2768ef5

Browse files
committed
Introduce exclude_aliases config option to allow classes to be excluded from autocompletion
1 parent 852c2ab commit 2768ef5

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

config/tinker.php.stub

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Prefixes to be excluded when generating class aliases for tinker.
8+
| You can provide fully-qualified class names to exclude specific classes,
9+
| or namespaces to exclude multiple classes within that namespace.
10+
|--------------------------------------------------------------------------
11+
*/
12+
13+
'exclude_aliases' => [
14+
],
15+
16+
];

src/ClassAliasAutoloader.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ public function __construct(Shell $shell, $classMapPath)
5050

5151
$classes = require $classMapPath;
5252

53+
$excludedAliases = collect(config('tinker.exclude_aliases'));
54+
5355
foreach ($classes as $class => $path) {
5456
if (! Str::contains($class, '\\') || Str::startsWith($path, $vendorPath)) {
5557
continue;
5658
}
5759

60+
if (! $excludedAliases->filter(
61+
function ($alias) use ($class) {
62+
return Str::startsWith($class, $alias);
63+
})->isEmpty()) {
64+
continue;
65+
}
66+
5867
$name = class_basename($class);
5968

6069
if (! isset($this->classes[$name])) {

src/TinkerServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public function register()
2525
return new TinkerCommand;
2626
});
2727

28+
$this->publishes([
29+
__DIR__ . '/../config/tinker.php.stub' => config_path('tinker.php'),
30+
], 'config');
31+
2832
$this->commands(['command.tinker']);
2933
}
3034

0 commit comments

Comments
 (0)