Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan provided path for all available FQCNs in paths within and outside app folder #1714

Merged
merged 21 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
70bf26b
Merge pull request #1528 from rappasoft/new-develop
lrljoe Nov 3, 2023
6b07b80
Merge pull request #1530 from rappasoft/new-develop
lrljoe Nov 3, 2023
f0a32bc
Merge pull request #1532 from rappasoft/develop
lrljoe Nov 3, 2023
b554a83
Merge pull request #1535 from rappasoft/develop
lrljoe Nov 3, 2023
419c2ff
Merge pull request #1541 from rappasoft/develop
lrljoe Nov 5, 2023
df31c86
Merge pull request #1561 from rappasoft/develop
lrljoe Nov 19, 2023
aec86d1
Merge pull request #1579 from rappasoft/develop
lrljoe Dec 4, 2023
2bfe6df
Merge pull request #1591 from rappasoft/develop
lrljoe Dec 9, 2023
e2b5c4f
Merge pull request #1610 from rappasoft/develop
lrljoe Dec 26, 2023
269c86b
Merge pull request #1617 from rappasoft/develop
lrljoe Dec 29, 2023
669269f
Merge pull request #1619 from rappasoft/develop
lrljoe Dec 29, 2023
2c0d9c9
Update ChangeLog - Showing as UNRELEASED rather than 3.1.8 (#1621)
lrljoe Dec 29, 2023
9b05c64
Merge branch 'develop' into master
lrljoe Jan 4, 2024
d49c0c7
Merge pull request #1667 from rappasoft/develop
lrljoe Feb 24, 2024
d07354a
Merge pull request #1672 from rappasoft/develop
lrljoe Feb 29, 2024
67c6489
Merge pull request #1676 from rappasoft/develop
lrljoe Mar 1, 2024
05a3d41
Fix for Collapsing Columns - Multiple Tables, Single Page (#1678) (#1…
lrljoe Mar 2, 2024
31915d5
Merge pull request #1707 from rappasoft/develop
lrljoe Apr 30, 2024
2bd477e
Fix ChangeLog, SP (#1710)
lrljoe Apr 30, 2024
69fadb7
Updated the make command to scan paths provided and check whether cla…
hakarabakara May 3, 2024
3bba4a6
Merge branch 'develop' into feature/external-models
lrljoe May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

=======
## [v3.2.6] - UNRELEASED
### New Features
- Add configurable wire:model for filters by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1699
Expand Down
47 changes: 44 additions & 3 deletions src/Commands/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ public function getModelImport(): string
}

if (isset($this->modelPath)) {
if (File::exists(rtrim($this->modelPath, '/').'/'.$this->model.'.php')) {

return Str::studly(str_replace('/', '\\', $this->modelPath)).$this->model;
$filename = rtrim($this->modelPath, '/').'/'.$this->model.'.php';
if (File::exists($filename)) {
//In case the file has more than one class which is highly unlikely but still possible
$classes = array_filter($this->getClassesList($filename), function($class) {
return substr($class,strrpos($class,'\\')+1) == $this->model;
});
if(count($classes) == 1)
return $classes[0];
}
}

Expand All @@ -138,6 +143,42 @@ public function getModelImport(): string
return 'App\Models\\'.$this->model;
}

/*
* Credits to Harm Smits: https://stackoverflow.com/a/67099502/2263114
*/
private function getClassesList($file): array
{
$classes = [];
$namespace = '';
$tokens = \PhpToken::tokenize(file_get_contents($file));

for ($i = 0; $i < count($tokens); $i++) {
if ($tokens[$i]->getTokenName() === 'T_NAMESPACE') {
for ($j = $i + 1; $j < count($tokens); $j++) {
if ($tokens[$j]->getTokenName() === 'T_NAME_QUALIFIED') {
$namespace = $tokens[$j]->text;
break;
}
}
}

if ($tokens[$i]->getTokenName() === 'T_CLASS') {
for ($j = $i + 1; $j < count($tokens); $j++) {
if ($tokens[$j]->getTokenName() === 'T_WHITESPACE') {
continue;
}

if ($tokens[$j]->getTokenName() === 'T_STRING') {
$classes[] = $namespace . '\\' . $tokens[$j]->text;
} else {
break;
}
}
}
}
return $classes;
}

/**
* @throws \Exception
*/
Expand Down
Loading