Skip to content

Commit

Permalink
feat: Allow registering composers in subfolders (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
davideprevosto authored Jul 5, 2022
1 parent ec6f82d commit 2a4ad4a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/AcfComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
namespace Log1x\AcfComposer;

use ReflectionClass;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Log1x\AcfComposer\Composer;
use Log1x\AcfComposer\Partial;
use Roots\Acorn\Application;
use Symfony\Component\Finder\Finder;
use Illuminate\Support\Facades\File;

class AcfComposer
{
/**
/**
* The application instance.
*
* @var \Roots\Acorn\Application
Expand Down Expand Up @@ -61,7 +59,6 @@ class AcfComposer
public function __construct(Application $app)
{
$this->app = $app;

$this->registerPath($this->app->path());
}

Expand Down Expand Up @@ -90,14 +87,23 @@ public function registerPath($path, $namespace = null)
$namespace = $this->app->getNamespace();
}

foreach ((new Finder())->in($paths->toArray())->files()->sortByName() as $file) {
foreach ((new Finder())->in($paths->toArray())->files() as $file) {
$relativePath = Str::remove(
$this->app->path() . DIRECTORY_SEPARATOR,
$file->getPathname()
);

$folders = Str::beforeLast(
$relativePath,
DIRECTORY_SEPARATOR
) . DIRECTORY_SEPARATOR;

$className = Str::after($relativePath, $folders);

$composer = $namespace . str_replace(
['/', '.php'],
['\\', ''],
Str::after(
$file->getPathname(),
Str::beforeLast($file->getPath(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR
)
$folders . $className
);

if (
Expand Down

0 comments on commit 2a4ad4a

Please sign in to comment.