Skip to content

Commit

Permalink
feat: create PathsLoader trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ast21 committed Mar 19, 2023
1 parent ed7adb8 commit d34fc51
Show file tree
Hide file tree
Showing 40 changed files with 281 additions and 351 deletions.
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ parameters:
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
Expand Down
1 change: 0 additions & 1 deletion src/Abstracts/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class Action
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Actions/SubAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class SubAction extends Action
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Commands/ConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class ConsoleCommand extends LaravelCommand
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class ApiController extends Controller
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Controllers/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class WebController extends Controller
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Exceptions/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class Exception extends LaravelException
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class Factory extends LaravelFactory
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Listeners/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class Listener
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Middlewares/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class Middleware
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Notifications/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class Notification extends LaravelNotification
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Policies/Policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class Policy
{

}
2 changes: 0 additions & 2 deletions src/Abstracts/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ abstract class AuthServiceProvider extends LaravelAuthServiceProvider

/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot(): void
{
Expand Down
1 change: 0 additions & 1 deletion src/Abstracts/Providers/BroadcastServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class BroadcastServiceProvider extends LaravelBroadcastServiceProvider
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class EventServiceProvider extends LaravelEventServiceProvider
{

}
5 changes: 0 additions & 5 deletions src/Abstracts/Providers/MainServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ abstract class MainServiceProvider extends LaravelAppServiceProvider

/**
* Register any application services.
*
* @return void
*/
public function register(): void
{
Expand All @@ -24,11 +22,8 @@ public function register(): void

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{

}
}
1 change: 1 addition & 0 deletions src/Abstracts/Providers/MiddlewareServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ abstract class MiddlewareServiceProvider extends MainServiceProvider

/**
* Perform post-registration booting of services.
*
* @throws BindingResolutionException
*/
public function boot(): void
Expand Down
11 changes: 0 additions & 11 deletions src/Abstracts/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,8 @@ abstract class RouteServiceProvider extends LaravelRouteServiceProvider
{
use RoutesLoaderTrait;

/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';

/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot(): void
{
Expand Down
1 change: 0 additions & 1 deletion src/Abstracts/Requests/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class Request extends LaravelRequest
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Seeders/Seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class Seeder extends LaravelSeeder
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Tasks/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

abstract class Task
{

}
1 change: 0 additions & 1 deletion src/Abstracts/Tests/PhpUnit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

abstract class TestCase extends LaravelTestCase
{

}
13 changes: 0 additions & 13 deletions src/Facades/Porto.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
use Illuminate\Support\Facades\Facade;

/**
* @method static array getShipFoldersNames()
* @method static array getShipPath()
* @method static array getSectionContainerNames(string $sectionName)
* @method static mixed getClassObjectFromFile($filePathName)
* @method static string getClassFullNameFromFile($filePathName)
* @method static array getSectionPaths()
* @method static mixed getClassType($className)
* @method static array getAllContainerNames()
* @method static array getAllContainerPaths()
* @method static array getSectionNames()
* @method static array getSectionContainerPaths(string $sectionName)
* @method static void verifyClassExist(string $className)
*
* @see \AdminKit\Porto\Porto
*/
class Porto extends Facade
Expand Down
4 changes: 0 additions & 4 deletions src/Loaders/AliasesLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public function loadAliases(): static
return $this;
}

/**
* @param $aliasKey
* @param $aliasValue
*/
private function loadAlias($aliasKey, $aliasValue): void
{
AliasLoader::getInstance()->alias($aliasKey, $aliasValue);
Expand Down
7 changes: 3 additions & 4 deletions src/Loaders/AutoLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace AdminKit\Porto\Loaders;

use AdminKit\Porto\Facades\Porto;

trait AutoLoaderTrait
{
// Using each component loader trait
Expand All @@ -15,6 +13,7 @@ trait AutoLoaderTrait
use CommandsLoaderTrait;
use AliasesLoaderTrait;
use HelpersLoaderTrait;
use PathsLoaderTrait;

public function runLoaderBoot(): void
{
Expand All @@ -25,7 +24,7 @@ public function runLoaderBoot(): void
$this->loadCommandsFromShip();

// Iterate over all the containers folders and autoload most of the components
foreach (Porto::getAllContainerPaths() as $containerPath) {
foreach ($this->getAllContainerPaths() as $containerPath) {
$this->loadMigrationsFromContainers($containerPath);
$this->loadLocalsFromContainers($containerPath);
$this->loadViewsFromContainers($containerPath);
Expand All @@ -39,7 +38,7 @@ public function runLoaderRegister(): void
$this->loadConfigsFromShip();
$this->loadShipServiceProviderFromShip();

foreach (Porto::getAllContainerPaths() as $containerPath) {
foreach ($this->getAllContainerPaths() as $containerPath) {
$this->loadConfigsFromContainers($containerPath);
$this->loadMainServiceProvidersFromContainers($containerPath);
}
Expand Down
13 changes: 7 additions & 6 deletions src/Loaders/CommandsLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace AdminKit\Porto\Loaders;

use AdminKit\Porto\Facades\Porto;
use Illuminate\Support\Facades\File;

trait CommandsLoaderTrait
{
use PathsLoaderTrait;

public function loadCommandsFromContainers($containerPath): void
{
$containerCommandsDirectory = $containerPath . '/UI/CLI/Commands';
$containerCommandsDirectory = $containerPath.'/UI/CLI/Commands';
$this->loadTheConsoles($containerCommandsDirectory);
}

Expand All @@ -20,8 +21,8 @@ private function loadTheConsoles($directory): void

foreach ($files as $consoleFile) {
// Do not load route files
if (!$this->isRouteFile($consoleFile)) {
$consoleClass = Porto::getClassFullNameFromFile($consoleFile->getPathname());
if (! $this->isRouteFile($consoleFile)) {
$consoleClass = $this->getClassFullNameFromFile($consoleFile->getPathname());
// When user from the Main Service Provider, which extends Laravel
// service provider you get access to `$this->commands`
$this->commands([$consoleClass]);
Expand All @@ -32,12 +33,12 @@ private function loadTheConsoles($directory): void

private function isRouteFile($consoleFile): bool
{
return $consoleFile->getFilename() === "closures.php";
return $consoleFile->getFilename() === 'closures.php';
}

public function loadCommandsFromShip(): void
{
$shipCommandsDirectory = base_path('app/Ship/Commands');
$shipCommandsDirectory = $this->getShipPath().'/Commands';
$this->loadTheConsoles($shipCommandsDirectory);
}
}
9 changes: 5 additions & 4 deletions src/Loaders/ConfigsLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace AdminKit\Porto\Loaders;


use Illuminate\Support\Facades\File;

trait ConfigsLoaderTrait
{
use PathsLoaderTrait;

public function loadConfigsFromShip(): void
{
$shipConfigsDirectory = base_path('app/Ship/Configs');
$shipConfigsDirectory = $this->getShipPath().'/Configs';
$this->loadConfigs($shipConfigsDirectory);
}

Expand All @@ -20,7 +21,7 @@ private function loadConfigs($configFolder): void

foreach ($files as $file) {
$name = File::name($file);
$path = $configFolder . '/' . $name . '.php';
$path = $configFolder.'/'.$name.'.php';

$this->mergeConfigFrom($path, $name);
}
Expand All @@ -29,7 +30,7 @@ private function loadConfigs($configFolder): void

public function loadConfigsFromContainers($containerPath): void
{
$containerConfigsDirectory = $containerPath . '/Configs';
$containerConfigsDirectory = $containerPath.'/Configs';
$this->loadConfigs($containerConfigsDirectory);
}
}
8 changes: 5 additions & 3 deletions src/Loaders/HelpersLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

trait HelpersLoaderTrait
{
use PathsLoaderTrait;

public function loadHelpersFromContainers($containerPath): void
{
$containerHelpersDirectory = $containerPath . '/Helpers';
$containerHelpersDirectory = $containerPath.'/Helpers';
$this->loadHelpers($containerHelpersDirectory);
}

Expand All @@ -20,7 +22,7 @@ private function loadHelpers($helpersFolder): void

foreach ($files as $file) {
try {
require($file);
require $file;
} catch (FileNotFoundException $e) {
}
}
Expand All @@ -29,7 +31,7 @@ private function loadHelpers($helpersFolder): void

public function loadHelpersFromShip(): void
{
$shipHelpersDirectory = base_path('app/Ship/Helpers');
$shipHelpersDirectory = $this->getShipPath().'/Helpers';
$this->loadHelpers($shipHelpersDirectory);
}
}
10 changes: 6 additions & 4 deletions src/Loaders/LocalizationLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

trait LocalizationLoaderTrait
{
use PathsLoaderTrait;

public function loadLocalsFromContainers($containerPath): void
{
$containerLocaleDirectory = $containerPath . '/Languages';
$containerLocaleDirectory = $containerPath.'/Languages';
$containerName = basename($containerPath);
$pathParts = explode(DIRECTORY_SEPARATOR, $containerPath);
$sectionName = $pathParts[count($pathParts) - 2];
Expand All @@ -27,14 +29,14 @@ private function loadLocals($directory, $containerName, $sectionName = null): vo

private function buildLocaleNamespace(?string $sectionName, string $containerName): string
{
return $sectionName ? (Str::camel($sectionName) . '@' . Str::camel($containerName)) : Str::camel(
return $sectionName ? (Str::camel($sectionName).'@'.Str::camel($containerName)) : Str::camel(
$containerName
);
}

public function loadLocalsFromShip(): void
{
$shipLocaleDirectory = base_path('app/Ship/Languages');
$this->loadLocals($shipLocaleDirectory, 'ship');
$shipLocaleDirectory = $this->getShipPath().'/Languages';
$this->loadLocals($shipLocaleDirectory, $this->shipFolderName);
}
}
Loading

0 comments on commit d34fc51

Please sign in to comment.