Uploaded From CV. Swandhana Server

This commit is contained in:
Duidev Software House
2025-01-27 08:16:55 +07:00
commit 6b3be42361
15186 changed files with 2328862 additions and 0 deletions
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider;
use Illuminate\Support\Facades\Gate;
/**
* Class AuthorizationServiceProvider
*
* @author ARCANEDEV <[email protected]>
*/
abstract class AuthorizationServiceProvider extends AuthServiceProvider
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Define policies.
*
* @param string $class
* @param array $policies
*/
protected function defineMany($class, array $policies)
{
foreach ($policies as $ability => $method) {
Gate::define($ability, "$class@$method");
}
}
}
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers;
/**
* Class CommandServiceProvider
*
* @author ARCANEDEV <[email protected]>
*/
abstract class CommandServiceProvider extends ServiceProvider
{
/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
*/
/**
* The commands to be registered.
*
* @var array
*/
protected $commands = [];
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Boot the service provider.
*/
public function boot()
{
$this->commands($this->commands);
}
/**
* Get the provided commands.
*
* @return array
*/
public function provides()
{
return $this->commands;
}
}
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers\Concerns;
/**
* Trait HasAssets
*
* @author ARCANEDEV <[email protected]>
*/
trait HasAssets
{
/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
*/
/**
* Get the assets path.
*
* @return string
*/
protected function getAssetsFolder(): string
{
return realpath($this->getBasePath().DIRECTORY_SEPARATOR.'assets');
}
/**
* Get the assets destination path.
*
* @return string
*/
protected function assetsDestinationPath(): string
{
return base_path('assets'.DIRECTORY_SEPARATOR.$this->getPackageName());
}
/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
*/
/**
* Publish the assets.
*/
protected function publishAssets(): void
{
$this->publishes([
$this->getAssetsFolder() => $this->assetsDestinationPath(),
], $this->getPublishedTags('assets'));
}
}
@@ -0,0 +1,152 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers\Concerns;
use Illuminate\Support\Str;
/**
* Trait HasConfig
*
* @author ARCANEDEV <[email protected]>
*/
trait HasConfig
{
/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
*/
/**
* Merge multiple config files into one instance (package name as root key)
*
* @var bool
*/
protected $multiConfigs = false;
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Get config folder.
*
* @return string
*/
protected function getConfigFolder(): string
{
return realpath($this->getBasePath().DIRECTORY_SEPARATOR.'config');
}
/**
* Get config key.
*
* @param bool $withVendor
* @param string $separator
*
* @return string
*/
protected function getConfigKey(bool $withVendor = false, string $separator = '.'): string
{
$package = Str::slug($this->getPackageName());
return $withVendor
? Str::slug($this->getVendorName()).$separator.$package
: $package;
}
/**
* Get config file path.
*
* @return string
*/
protected function getConfigFile(): string
{
return $this->getConfigFolder().DIRECTORY_SEPARATOR."{$this->getPackageName()}.php";
}
/**
* Get the config files (paths).
*
* @return array|false
*/
protected function configFilesPaths()
{
return glob($this->getConfigFolder().DIRECTORY_SEPARATOR.'*.php');
}
/**
* Register configs.
*
* @param string $separator
*/
protected function registerConfig(string $separator = '.'): void
{
$this->multiConfigs
? $this->registerMultipleConfigs($separator)
: $this->registerSingleConfig();
}
/**
* Register a single config file.
*/
protected function registerSingleConfig(): void
{
$this->mergeConfigFrom($this->getConfigFile(), $this->getConfigKey());
}
/**
* Register all package configs.
*
* @param string $separator
*/
protected function registerMultipleConfigs(string $separator = '.'): void
{
foreach ($this->configFilesPaths() as $path) {
$key = $this->getConfigKey(true, $separator).$separator.basename($path, '.php');
$this->mergeConfigFrom($path, $key);
}
}
/**
* Publish the config file.
*
* @param string|null $path
*/
protected function publishConfig(?string $path = null): void
{
$this->multiConfigs
? $this->publishMultipleConfigs()
: $this->publishSingleConfig($path);
}
/**
* Publish a single config file.
*
* @param string|null $path
*/
protected function publishSingleConfig(?string $path = null): void
{
$this->publishes([
$this->getConfigFile() => $path ?: config_path("{$this->getPackageName()}.php"),
], $this->getPublishedTags('config'));
}
/**
* Publish multiple config files.
*/
protected function publishMultipleConfigs(): void
{
$paths = [];
$package = $this->getConfigKey(true, DIRECTORY_SEPARATOR);
foreach ($this->configFilesPaths() as $file) {
$paths[$file] = config_path($package.DIRECTORY_SEPARATOR.basename($file));
}
$this->publishes($paths, $this->getPublishedTags('config'));
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers\Concerns;
/**
* Trait HasFactories
*
* @author ARCANEDEV <[email protected]>
*/
trait HasFactories
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Get the migrations path.
*
* @return string
*/
protected function getFactoriesPath(): string
{
return $this->getBasePath().DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'factories';
}
/**
* Publish the factories.
*
* @param string|null $path
*/
protected function publishFactories(?string $path = null): void
{
$this->publishes([
$this->getFactoriesPath() => $path ?: database_path('factories'),
], $this->getPublishedTags('factories'));
}
/**
* Load the factories.
*/
protected function loadFactories(): void
{
$this->loadFactoriesFrom($this->getFactoriesPath());
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers\Concerns;
/**
* Trait HasMigrations
*
* @author ARCANEDEV <[email protected]>
*/
trait HasMigrations
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Get the migrations path.
*
* @return string
*/
protected function getMigrationsPath(): string
{
return $this->getBasePath().DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations';
}
/**
* Publish the migration files.
*
* @param string|null $path
*/
protected function publishMigrations(?string $path = null): void
{
$this->publishes([
$this->getMigrationsPath() => $path ?: database_path('migrations')
], $this->getPublishedTags('migrations'));
}
/**
* Load the migrations files.
*/
protected function loadMigrations(): void
{
$this->loadMigrationsFrom($this->getMigrationsPath());
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers\Concerns;
/**
* Trait HasTranslations
*
* @author ARCANEDEV <[email protected]>
*/
trait HasTranslations
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Get the translations' folder name.
*/
protected function getTranslationsFolderName(): string
{
return 'translations';
}
/**
* Get the translations' path.
*/
protected function getTranslationsPath(): string
{
return $this->getBasePath().DIRECTORY_SEPARATOR.$this->getTranslationsFolderName();
}
/**
* Get the destination views path.
*/
protected function getTranslationsDestinationPath(): string
{
return $this->app->langPath(
'vendor'.DIRECTORY_SEPARATOR.$this->getPackageName()
);
}
/**
* Publish the translations.
*/
protected function publishTranslations(?string $path = null): void
{
$this->publishes([
$this->getTranslationsPath() => $path ?: $this->getTranslationsDestinationPath(),
], $this->getPublishedTags('translations'));
}
/**
* Load the translations files.
*/
protected function loadTranslations(): void
{
$packagePath = $this->getTranslationsPath();
$vendorPath = $this->getTranslationsDestinationPath();
$this->loadTranslationsFrom($packagePath, $this->getPackageName());
$this->loadJsonTranslationsFrom(file_exists($vendorPath) ? $vendorPath : $packagePath);
}
}
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers\Concerns;
/**
* Trait HasViews
*
* @author ARCANEDEV <[email protected]>
*/
trait HasViews
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Get the base views path.
*
* @return string
*/
protected function getViewsPath(): string
{
return $this->getBasePath().DIRECTORY_SEPARATOR.'views';
}
/**
* Get the destination views path.
*
* @return string
*/
protected function getViewsDestinationPath(): string
{
return $this->app['config']['view.paths'][0].DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.$this->getPackageName();
}
/**
* Publish the views.
*
* @param string|null $path
*/
protected function publishViews(?string $path = null): void
{
$this->publishes([
$this->getViewsPath() => $path ?: $this->getViewsDestinationPath(),
], $this->getPublishedTags('views'));
}
/**
* Load the views files.
*/
protected function loadViews(): void
{
$this->loadViewsFrom($this->getViewsPath(), $this->getPackageName());
}
}
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers\Concerns;
/**
* Trait InteractsWithApplication
*
* @author ARCANEDEV <[email protected]>
*/
trait InteractsWithApplication
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Register multiple service providers.
*
* @param array $providers
*/
protected function registerProviders(array $providers)
{
foreach ($providers as $provider) {
$this->registerProvider($provider);
}
}
/**
* Register a service provider.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param bool $force
*
* @return \Illuminate\Support\ServiceProvider
*/
protected function registerProvider($provider, $force = false)
{
return $this->app->register($provider, $force);
}
/**
* Register a console service provider.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param bool $force
*
* @return \Illuminate\Support\ServiceProvider|null
*/
protected function registerConsoleServiceProvider($provider, $force = false)
{
if ($this->app->runningInConsole()) {
return $this->registerProvider($provider, $force);
}
return null;
}
/**
* Register the package's custom Artisan commands when running in console.
*
* @param array $commands
*/
protected function registerCommands(array $commands)
{
if ($this->app->runningInConsole()) {
$this->commands($commands);
}
}
/**
* Register a binding with the container.
*
* @param string $abstract
* @param \Closure|string|null $concrete
* @param bool $shared
*/
protected function bind($abstract, $concrete = null, $shared = false)
{
$this->app->bind($abstract, $concrete, $shared);
}
/**
* Register a shared binding in the container.
*
* @param string|array $abstract
* @param \Closure|string|null $concrete
*/
protected function singleton($abstract, $concrete = null)
{
$this->app->singleton($abstract, $concrete);
}
}
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers;
use Illuminate\Support\Facades\Event;
/**
* Class EventServiceProvider
*
* @author ARCANEDEV <[email protected]>
*/
abstract class EventServiceProvider extends ServiceProvider
{
/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
*/
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [];
/**
* The subscriber classes to register.
*
* @var array
*/
protected $subscribe = [];
/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
*/
/**
* Get the events and handlers.
*
* @return array
*/
public function listens()
{
return $this->listen;
}
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Register the application's event listeners.
*/
public function boot()
{
foreach ($this->listens() as $event => $listeners) {
foreach ($listeners as $listener) {
Event::listen($event, $listener);
}
}
foreach ($this->subscribe as $subscriber) {
Event::subscribe($subscriber);
}
}
/**
* {@inheritdoc}
*/
public function register()
{
//
}
}
@@ -0,0 +1,194 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers;
use Arcanedev\Support\Exceptions\PackageException;
use Arcanedev\Support\Providers\Concerns\{
HasAssets, HasConfig, HasFactories, HasMigrations, HasTranslations, HasViews
};
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Str;
use ReflectionClass;
/**
* Class PackageServiceProvider
*
* @author ARCANEDEV <[email protected]>
*/
abstract class PackageServiceProvider extends ServiceProvider
{
/* -----------------------------------------------------------------
| Traits
| -----------------------------------------------------------------
*/
use HasAssets,
HasConfig,
HasFactories,
HasMigrations,
HasTranslations,
HasViews;
/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
*/
/**
* Vendor name.
*
* @var string
*/
protected $vendor = 'arcanedev';
/**
* Package name.
*
* @var string|null
*/
protected $package;
/**
* Package base path.
*
* @var string
*/
protected $basePath;
/* -----------------------------------------------------------------
| Constructor
| -----------------------------------------------------------------
*/
/**
* Create a new service provider instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
*/
public function __construct(Application $app)
{
parent::__construct($app);
$this->basePath = $this->resolveBasePath();
}
/**
* Resolve the base path of the package.
*
* @return string
*/
protected function resolveBasePath()
{
return dirname(
(new ReflectionClass($this))->getFileName(), 2
);
}
/* -----------------------------------------------------------------
| Getters & Setters
| -----------------------------------------------------------------
*/
/**
* Get the base path of the package.
*
* @return string
*/
public function getBasePath()
{
return $this->basePath;
}
/**
* Get the vendor name.
*
* @return string
*/
protected function getVendorName(): string
{
return $this->vendor;
}
/**
* Get the package name.
*
* @return string|null
*/
protected function getPackageName(): ?string
{
return $this->package;
}
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Register the service provider.
*/
public function register()
{
parent::register();
$this->checkPackageName();
}
/* -----------------------------------------------------------------
| Package Methods
| -----------------------------------------------------------------
*/
/**
* Publish all the package files.
*/
protected function publishAll(): void
{
$this->publishAssets();
$this->publishConfig();
$this->publishFactories();
$this->publishMigrations();
$this->publishTranslations();
$this->publishViews();
}
/* -----------------------------------------------------------------
| Check Methods
| -----------------------------------------------------------------
*/
/**
* Check package name.
*
* @throws \Arcanedev\Support\Exceptions\PackageException
*/
protected function checkPackageName(): void
{
if (empty($this->getVendorName()) || empty($this->getPackageName())) {
throw PackageException::unspecifiedName();
}
}
/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/
/**
* Get the published tags.
*
* @param string $tag
*
* @return array
*/
protected function getPublishedTags(string $tag): array
{
$package = $this->getPackageName();
return array_map(function ($name) {
return Str::slug($name);
}, [$this->getVendorName(), $package, $tag, $package.'-'.$tag]);
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers;
use Arcanedev\Support\Routing\Concerns\RegistersRouteClasses;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as IlluminateServiceProvider;
/**
* Class RouteServiceProvider
*
* @author ARCANEDEV <[email protected]>
*/
abstract class RouteServiceProvider extends IlluminateServiceProvider
{
/* -----------------------------------------------------------------
| Traits
| -----------------------------------------------------------------
*/
use RegistersRouteClasses;
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers;
use Arcanedev\Support\Providers\Concerns\InteractsWithApplication;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
/**
* Class ServiceProvider
*
* @author ARCANEDEV <[email protected]>
*/
abstract class ServiceProvider extends IlluminateServiceProvider
{
/* -----------------------------------------------------------------
| Traits
| -----------------------------------------------------------------
*/
use InteractsWithApplication;
}
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace Arcanedev\Support\Providers;
use Illuminate\Contracts\View\Factory as ViewFactory;
/**
* Class ViewComposerServiceProvider
*
* @author ARCANEDEV <[email protected]>
*/
abstract class ViewComposerServiceProvider extends ServiceProvider
{
/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
*/
/**
* Register the composer classes.
*
* @var array
*/
protected $composerClasses = [
// 'view-name' => 'class'
];
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/
/**
* Boot the view composer service provider.
*/
public function boot()
{
$this->registerComposerClasses();
}
/**
* Register the view composer classes.
*/
protected function registerComposerClasses()
{
foreach ($this->composerClasses as $view => $class) {
$this->composer($view, $class);
}
}
/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/
/**
* Get the view factory instance.
*
* @return \Illuminate\Contracts\View\Factory
*/
protected function view()
{
return $this->app->make(ViewFactory::class);
}
/**
* Register a view composer event.
*
* @param array|string $views
* @param \Closure|string $callback
*
* @return array
*/
public function composer($views, $callback)
{
return $this->view()->composer($views, $callback);
}
}