Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adminer-pematon: init at 4.12 #358530

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkgs/by-name/ad/adminer-pematon/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace nixos {
Copy link
Contributor

@drupol drupol Nov 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opinionated: I would modify this into something more functional, like:

<?php

declare(strict_types=1);

namespace nixos {
    use AdminerPlugin;

    use function sprintf;

    function adminer_object(): object
    {
        require_once __DIR__ . '/plugins/plugin.php';

        if (!file_exists(__DIR__ . '/plugins.json')) {
            return new AdminerPlugin();
        }

        $plugins = array_map(
            static function (string $name): ?object {
                $plugin = sprintf('%s/plugins/%s.php', __DIR__, $name);

                if (!is_readable($plugin)) {
                    return null;
                }

                require $plugin;

                preg_match_all('/(\w+)/', $name, $matches);

                return new sprintf('Adminer%s', implode('', array_map('ucfirst', $matches[1])));
            },
            json_decode(file_get_contents(sprintf('%s/plugins.json', __DIR__), true))
        );

        return new AdminerPlugin(array_filter($plugins));
    }
}

Copy link
Contributor Author

@JohnRTitor JohnRTitor Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks, tested and it works.

One thing I might add though, do you know perhaps a way to override to use adminer-theme?

I am currently removing the index.php provided by this package, and adding an index.php with modifications for adminer theme.

use AdminerPlugin;

use function sprintf;

function adminer_object(): object
{
require_once __DIR__ . '/plugins/plugin.php';

if (!file_exists(__DIR__ . '/plugins.json')) {
return new AdminerPlugin();
}

$plugins = array_map(
static function (string $name): ?object {
$plugin = sprintf('%s/plugins/%s.php', __DIR__, $name);

if (!is_readable($plugin)) {
return null;
}

require $plugin;

preg_match_all('/(\w+)/', $name, $matches);

return new sprintf('Adminer%s', implode('', array_map('ucfirst', $matches[1])));
},
json_decode(file_get_contents(sprintf('%s/plugins.json', __DIR__), true))
);

return new AdminerPlugin(array_filter($plugins));
}
}

namespace {
function adminer_object() {
return \nixos\adminer_object();
}

require(__DIR__ . '/adminer.php');
}
75 changes: 75 additions & 0 deletions pkgs/by-name/ad/adminer-pematon/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
lib,
stdenvNoCC,
fetchFromGitHub,
php,
writeText,
nix-update-script,
theme ? null,
plugins ? [ ],
}:
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "adminer-pematon";
version = "4.12";

src = fetchFromGitHub {
owner = "pematon";
repo = "adminer";
rev = "refs/tags/v${finalAttrs.version}";
hash = "sha256-ExCHEsZ+VFmrom3632/1OOjb3zbZgiaZJDapBkBGUnQ=";
};

nativeBuildInputs = [
php
];

buildPhase = ''
runHook preBuild

php compile.php

runHook postBuild
'';

installPhase = ''
runHook preInstall

mkdir $out
cp temp/adminer-${finalAttrs.version}.php $out/adminer.php
cp ${./index.php} $out/index.php

${lib.optionalString (theme != null) ''
cp designs/${theme}/adminer.css $out/adminer.css
''}

# Copy base plugin
mkdir -p $out/plugins
cp plugins/plugin.php $out/plugins/plugin.php

${lib.optionalString (plugins != [ ]) ''
cp plugins/*.php $out/plugins/
cp ${writeText "$out/plugins.json" ''
${toString (builtins.toJSON plugins)}
''} $out/plugins.json
''}

runHook postInstall
'';

passthru = {
updateScript = nix-update-script { };
};

meta = {
description = "Database management in a single PHP file (Pematon fork)";
homepage = "https://github.com/pematon/adminer";
license = with lib.licenses; [
asl20
gpl2Only
];
maintainers = with lib.maintainers; [
johnrtitor
];
platforms = lib.platforms.all;
};
})