Skip to content

Commit 8e3f588

Browse files
authored
Merge pull request #17 from tweakphp/laravel-tinker
Add Tinker ClassAliasAutoloader register
2 parents 64a9413 + 7cd34f3 commit 8e3f588

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

.github/workflows/code-style.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
node-version: [ "20.x" ]
1818

1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2121

2222
- name: Setup PHP
2323
uses: shivammathur/setup-php@v2
@@ -26,7 +26,7 @@ jobs:
2626

2727
- name: Cache Composer packages
2828
id: composer-cache
29-
uses: actions/cache@v2
29+
uses: actions/cache@v4
3030
with:
3131
path: vendor
3232
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
steps:
4343
- name: Checkout Repository
44-
uses: actions/checkout@v3
44+
uses: actions/checkout@v4
4545

4646
- name: Setup PHP for Current Version
4747
uses: shivammathur/setup-php@v2

src/Loaders/LaravelLoader.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public function __construct(string $path)
1818
$this->app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
1919
}
2020

21+
public function init(): void
22+
{
23+
parent::init();
24+
25+
$this->bootAliases();
26+
}
27+
2128
public function name(): string
2229
{
2330
return 'Laravel';
@@ -50,4 +57,22 @@ public function casters(): array
5057

5158
return $casters;
5259
}
60+
61+
private function bootAliases(): void
62+
{
63+
if (! class_exists(\Laravel\Tinker\ClassAliasAutoloader::class)) {
64+
return;
65+
}
66+
67+
$config = $this->app->make('config');
68+
69+
$path = \Illuminate\Support\Env::get('COMPOSER_VENDOR_DIR', $this->app->basePath().DIRECTORY_SEPARATOR.'vendor');
70+
71+
\Laravel\Tinker\ClassAliasAutoloader::register(
72+
$this->tinker->getShell(),
73+
$path.'/composer/autoload_classmap.php',
74+
$config->get('tinker.alias', []),
75+
$config->get('tinker.dont_alias', [])
76+
);
77+
}
5378
}

src/Tinker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,9 @@ protected function cleanOutput(string $output): string
8585

8686
return trim($output);
8787
}
88+
89+
public function getShell(): Shell
90+
{
91+
return $this->shell;
92+
}
8893
}

0 commit comments

Comments
 (0)