Skip to content

Commit

Permalink
Support for Backpack v6
Browse files Browse the repository at this point in the history
  • Loading branch information
promatik committed Sep 18, 2023
1 parent f78fa03 commit bd4bb43
Show file tree
Hide file tree
Showing 60 changed files with 4,439 additions and 2,169 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0",
"zanysoft/laravel-zip": "^2.0",
"rector/rector": "^0.18.0"
"rector/rector": "^0.18.0",
"nunomaduro/larastan": "^2.6"
},
"repositories": [
{
Expand Down Expand Up @@ -73,6 +74,11 @@
}
}
},
"scripts": {
"analyse": [
"vendor/bin/phpstan analyse src/app"
]
},
"suggest": {
"league/flysystem-aws-s3-v3": "Required to connect to AWS S3 or a Digital Ocean Space.",
"eduardokum/laravel-mail-auto-embed": "Useful to embed images on emails."
Expand Down
774 changes: 485 additions & 289 deletions composer.lock

Large diffs are not rendered by default.

3,825 changes: 3,810 additions & 15 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"devDependencies": {
"milligram": "^1.4.1",
"dependencies": {
"cantil": "^1.1.2",
"normalize.css": "^8.0.1"
}
}
8 changes: 0 additions & 8 deletions src/Framework.php

This file was deleted.

40 changes: 0 additions & 40 deletions src/FrameworkServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ public function boot()

// Blade directives

// SVG
\Blade::directive('svg', function ($arguments) {
list($path, $class, $style) = array_pad(explode(',', trim($arguments.',,', '() ')), 2, '');
$path = trim($path, "' ");
$class = trim($class, "' ");
$style = trim($style, "' ");

$svg = new \DOMDocument();
$svg->load(public_path($path));
$svg->documentElement->setAttribute('class', $class);
$svg->documentElement->setAttribute('style', $style);

return $svg->saveXML($svg->documentElement);
});

// Is (Role, Permission)
\Blade::directive('is', function ($roles, $permissions = null) {
return "<?php if (is($roles, $permissions)) { ?>";
Expand Down Expand Up @@ -100,28 +85,13 @@ public function boot()
*/
public function register()
{
// Register the service the package provides.
$this->app->singleton('framework', function ($app) {
return new Framework();
});

// register all configs
$this->loadConfigs();

// register the helper functions
$this->loadHelpers();
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['framework'];
}

/**
* Console-specific booting.
*
Expand Down Expand Up @@ -162,16 +132,6 @@ public function loadHelpers()
*/
public function loadConfigs()
{
// Framework config
$this->mergeConfigFrom(__DIR__.'/config/framework.php', 'gemadigital');

// Services config
$this->mergeConfigFrom(__DIR__.'/config/services.php', 'services');

// Enums config
$this->mergeConfigFrom(__DIR__.'/config/enums.php', 'enums');

// File Systems config
$this->mergeConfigFrom(__DIR__.'/config/filesystems.php', 'filesystems');
}
}
2 changes: 1 addition & 1 deletion src/app/Console/Commands/package.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Carbon\Carbon;
use Illuminate\Console\Command;
use ZanySoft\Zip\Zip;
use ZanySoft\Zip\Facades\Zip;

class package extends Command
{
Expand Down
15 changes: 0 additions & 15 deletions src/app/Events/BaseEvent.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/Events/DefaultEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace GemaDigital\Framework\app\Events;

use Auth;
use Carbon\Carbon;
use GemaDigital\Framework\app\Events\SerializesEvents;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Auth;

abstract class DefaultEvent
{
Expand Down
32 changes: 15 additions & 17 deletions src/app/Helpers/CommonHelper.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

use App\Models\User;
use GemaDigital\Framework\app\Helpers\QueryLogger;
use Illuminate\Foundation\Auth\User;
use Illuminate\Http\Response;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;

if (! function_exists('user')) {
function user(): ?User
Expand All @@ -24,24 +26,16 @@ function debugMode(): bool
}

if (! function_exists('api')) {
function api()
function api(): mixed
{
return app('App\Http\Controllers\Admin\APICrudController');
}
}

if (! function_exists('data_get_first')) {
function data_get_first($target, $key, $attribute, $default = 0)
{
$value = data_get($target, $key);

return count($value) ? $value[0]->{$attribute} : $default;
}
}

if (! function_exists('hasRole')) {
function hasRole(string $role): bool
{
// @phpstan-ignore-next-line
$user = backpack_user() ?: user();

return $user && $user->hasRole($role);
Expand All @@ -51,6 +45,7 @@ function hasRole(string $role): bool
if (! function_exists('hasAnyPermissions')) {
function hasAnyPermissions(string | array $permissions): bool
{
// @phpstan-ignore-next-line
$user = backpack_user() ?: user();

if ($user) {
Expand All @@ -59,6 +54,7 @@ function hasAnyPermissions(string | array $permissions): bool
}

foreach ($permissions as $permission) {
// @phpstan-ignore-next-line
if ($user->checkPermissionTo($permission, backpack_guard_name())) {
return true;
}
Expand All @@ -72,6 +68,7 @@ function hasAnyPermissions(string | array $permissions): bool
if (! function_exists('hasAllPermissions')) {
function hasAllPermissions(string | array $permissions): bool
{
// @phpstan-ignore-next-line
$user = backpack_user() ?: user();

if ($user) {
Expand All @@ -81,6 +78,7 @@ function hasAllPermissions(string | array $permissions): bool

$value = true;
foreach ($permissions as $permission) {
// @phpstan-ignore-next-line
$value &= $user->checkPermissionTo($permission, backpack_guard_name());
}

Expand Down Expand Up @@ -149,7 +147,7 @@ function is(string | array $roles, string | array $permissions = null): bool
if (! function_exists('aurl')) {
function aurl(string $disk, string $path): string
{
return Str::startsWith($path, 'http') ? $path : Storage::disk($disk)->url($path);
return str_starts_with($path, 'http') ? $path : Storage::disk($disk)->url($path);
}
}

Expand Down Expand Up @@ -209,7 +207,7 @@ function json_response(mixed $data = null, int $code = 0, int $status = 200, mix
}

if (! function_exists('json_response_raw')) {
function json_response_raw(mixed $raw = null, int $code = 0, int $status = 200, mixed $errors = null)
function json_response_raw(mixed $raw = null, int $code = 0, int $status = 200, mixed $errors = null): Response
{
$response = [
'code' => $code,
Expand Down Expand Up @@ -273,7 +271,7 @@ function sized_image(string $path, int $size): string
if (! function_exists('__fallback')) {
function __fallback(string $key, ?string $fallback = null, ?string $locale = null, ?array $replace = []): ?string
{
if (\Illuminate\Support\Facades\Lang::has($key, $locale)) {
if (Lang::has($key, $locale)) {
return trans($key, $replace, $locale);
}

Expand All @@ -284,7 +282,7 @@ function __fallback(string $key, ?string $fallback = null, ?string $locale = nul
if (! function_exists('get_class_name')) {
function get_class_name(string $object): string
{
return (new \ReflectionClass($object))->getShortName();
return (new ReflectionClass($object))->getShortName();
}
}

Expand All @@ -297,7 +295,7 @@ function memoize(mixed $target): mixed
{
function __construct(
protected $target,
protected &$memo,
protected &$memo,
) {}

function __call($method, $params)
Expand Down
18 changes: 0 additions & 18 deletions src/app/Helpers/Composer/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,12 @@ public static function postInstall(): void
{
switch (DIRECTORY_SEPARATOR) {
case '/': // unix
exec('unlink "public/packages"');
exec('ln -s "../vendor/backpack/crud/src/public/packages" "public/packages"');
exec('unlink "public/gemadigital"');
exec('ln -s "../vendor/gemadigital/framework/src/public/gemadigital" "public/gemadigital"');

// ElFinder Assets
exec('mkdir -p "vendor/backpack/crud/src/public/packages/barryvdh/elfinder"');
foreach (['css', 'img', 'js', 'sounds'] as $folder) {
exec('unlink "vendor/backpack/crud/src/public/packages/barryvdh/elfinder/'.$folder.'"');
exec('ln -s "../../../../../../../../vendor/studio-42/elfinder/'.$folder.'" "vendor/backpack/crud/src/public/packages/barryvdh/elfinder/'.$folder.'"');
}
break;
case '\\': // windows
exec('if exist "public\packages" rmdir "public\packages" /s /q');
exec('mklink /J "public\packages" "vendor\backpack\crud\src\public\packages"');
exec('if exist "public\gemadigital" rmdir "public\gemadigital" /s /q');
exec('mklink /J "public\gemadigital" "vendor\gemadigital\framework\src\public\gemadigital"');

// ElFinder Assets
exec('if not exist "vendor/backpack/crud/src/public/packages/barryvdh/elfinder" mkdir "vendor/backpack/crud/src/public/packages/barryvdh/elfinder"');
foreach (['css', 'img', 'js', 'sounds'] as $folder) {
exec('if exist "vendor/backpack/crud/src/public/packages/barryvdh/elfinder/'.$folder.'" rmdir "vendor/backpack/crud/src/public/packages/barryvdh/elfinder/'.$folder.'" /s /q');
exec('mklink /J "vendor/backpack/crud/src/public/packages/barryvdh/elfinder/'.$folder.'" "vendor/studio-42/elfinder/'.$folder.'"');
}
break;
}
}
Expand Down
57 changes: 0 additions & 57 deletions src/app/Helpers/EnumHelper.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/Helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace GemaDigital\Framework\app\Helpers;

use File;
use Str;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;

class FileHelper
{
Expand Down
Loading

0 comments on commit bd4bb43

Please sign in to comment.