I would like to get information about an arbitrary website build with Kirby from an external program, i.e. a bash script, and just pick the piece of information I need.
Apparently, it is not possible to get this by a method of the Kirby
object. I discovered that I need to build my own associative array with different methods:
<?php
// getConfig.php to get the configuration of a Kirby site
// Usage: php getConfig.php DOCROOT
// Example: php getConfig.php /srv/www/vhost/kirby-test/htdocs
require $argv[1] . '/kirby/bootstrap.php';
$kirby = new Kirby([ 'roots' => [ 'index' => $argv[1] ] ]);
$myKirby = array(
'languages' => $kirby->languages()->toArray(),
'options' => $kirby->options(),
'plugins' => $kirby->plugins(),
// 'roles' => $kirby->roles()->toArray(),
'roots' => $kirby->roots()->toArray(),
// 'routes' => $kirby->routes(),
'urls' => $kirby->urls()->toArray(),
'users' => $kirby->users()->toArray(),
'version' => $kirby->version(),
);
echo json_encode($myKirby);
?>
which would result in this output (when piped through jq
):
{
"languages": [],
"options": {
"debug": true
},
"plugins": [],
"roots": {
"kirby": "/usr/local/lib/kirby/3.4.5",
"i18n": "/usr/local/lib/kirby/3.4.5/i18n",
"i18n:translations": "/usr/local/lib/kirby/3.4.5/i18n/translations",
"i18n:rules": "/usr/local/lib/kirby/3.4.5/i18n/rules",
"index": "/home/uwe/vhosts/kirby-test1/htdocs",
"assets": "/home/uwe/vhosts/kirby-test1/htdocs/assets",
"content": "/home/uwe/vhosts/kirby-test1/htdocs/content",
"media": "/home/uwe/vhosts/kirby-test1/htdocs/media",
"panel": "/usr/local/lib/kirby/3.4.5/panel",
"site": "/home/uwe/vhosts/kirby-test1/htdocs/site",
"accounts": "/home/uwe/vhosts/kirby-test1/htdocs/site/accounts",
"blueprints": "/home/uwe/vhosts/kirby-test1/htdocs/site/blueprints",
"cache": "/home/uwe/vhosts/kirby-test1/htdocs/site/cache",
"collections": "/home/uwe/vhosts/kirby-test1/htdocs/site/collections",
"config": "/home/uwe/vhosts/kirby-test1/htdocs/site/config",
"controllers": "/home/uwe/vhosts/kirby-test1/htdocs/site/controllers",
"languages": "/home/uwe/vhosts/kirby-test1/htdocs/site/languages",
"models": "/home/uwe/vhosts/kirby-test1/htdocs/site/models",
"plugins": "/home/uwe/vhosts/kirby-test1/htdocs/site/plugins",
"sessions": "/home/uwe/vhosts/kirby-test1/htdocs/site/sessions",
"snippets": "/home/uwe/vhosts/kirby-test1/htdocs/site/snippets",
"templates": "/home/uwe/vhosts/kirby-test1/htdocs/site/templates",
"roles": "/home/uwe/vhosts/kirby-test1/htdocs/site/blueprints/users"
},
"urls": {
"index": "/",
"base": "",
"current": "/",
"assets": "/assets",
"api": "/api",
"media": "/media",
"panel": "/panel"
},
"users": {
"XakNcEEq": {
"avatar": null,
"content": [],
"email": "uwe@somewhere.de",
"id": "XakNcEEq",
"language": "en",
"role": "admin",
"username": "Uwe Gehring"
}
},
"version": "3.4.5"
}
which is fine, but I do not like the fact that I have to create an array first with the info I am interested in, using different methods. It would be much better, if one could just get the info about the whole Kirby
object with one call:
...
require $argv[1] . '/kirby/bootstrap.php';
$kirby = new Kirby([ 'roots' => [ 'index' => $argv[1] ] ]);
echo json_encode($kirby);
...
But this does not work. Is there another possibility to achieve this?