Browse Source

init config model

PHP-GTK3
yggverse 4 months ago
parent
commit
789db97319
  1. 355
      config.json
  2. 5
      src/Entity/App.php
  3. 4
      src/Entity/Tab/History.php
  4. 4
      src/Entity/Tab/Page.php
  5. 45
      src/Model/Config.php
  6. 24
      src/Model/File.php

355
config.json

@ -1,229 +1,226 @@ @@ -1,229 +1,226 @@
{
"app":
"name":"Yoda",
"theme":"Default",
"database":
{
"name":"Yoda",
"theme":"Default",
"database":
"name":"database.sqlite",
"username":null,
"password":null
},
"header":
{
"enabled":true,
"button":
{
"name":"database.sqlite",
"username":null,
"password":null
},
"header":
"close":true
}
},
"width":640,
"height":480,
"tab":
{
"page":
{
"enabled":true,
"button":
"title":
{
"close":true
}
},
"width":640,
"height":480,
"tab":
{
"page":
"default":"New page",
"width":
{
"chars":32
},
"ellipsize":
{
"mode":3
},
"postfix":
{
"hostname":true
}
},
"redirect":
{
"title":
"follow":
{
"default":"New page",
"width":
{
"chars":32
},
"ellipsize":
{
"mode":3
},
"postfix":
{
"hostname":true
}
"enabled":true,
"max":5,
"code":
[
30,
31
]
}
},
"resolver":
{
"enabled":true,
"request":
{
"timeout":1,
"host":
[
"1.1.1.1",
"8.8.8.8"
],
"record":
[
"A",
"AAAA"
]
},
"redirect":
"result":
{
"follow":
"shuffle":false,
"cache":
{
"enabled":true,
"max":5,
"code":
[
30,
31
]
"timeout":3600
}
}
},
"history":
{
"memory":
{
"enabled":true
},
"resolver":
"database":
{
"enabled":true,
"request":
"mode":
{
"timeout":1,
"host":
[
"1.1.1.1",
"8.8.8.8"
],
"record":
[
"A",
"AAAA"
]
},
"result":
{
"shuffle":false,
"cache":
{
"timeout":3600
}
"renew":true
}
},
"history":
}
},
"progressbar":
{
"visible":true
},
"header":
{
"margin":8,
"button":
{
"memory":
"home":
{
"enabled":true
"visible":true,
"label":"Home",
"url":"yoda://welcome"
},
"database":
"back":
{
"enabled":true,
"mode":
{
"renew":true
}
"visible":true,
"label":"Back"
},
"forward":
{
"visible":true,
"label":"Forward"
},
"base":
{
"visible":true,
"label":"Base"
},
"go":
{
"visible":true,
"label":"Go"
}
},
"progressbar":
"entry":
{
"visible":true
},
"header":
{
"margin":8,
"button":
"request":
{
"home":
{
"visible":true,
"label":"Home",
"url":"yoda://welcome"
},
"back":
{
"visible":true,
"label":"Back"
},
"forward":
"placeholder":"URL or any search term...",
"length":
{
"visible":true,
"label":"Forward"
"max":1024
},
"base":
{
"visible":true,
"label":"Base"
},
"go":
{
"visible":true,
"label":"Go"
}
},
"entry":
{
"request":
"autocomplete":
{
"placeholder":"URL or any search term...",
"length":
"enabled":true,
"inline":
{
"max":1024
"completion":true,
"selection":true
},
"autocomplete":
"key":
{
"enabled":true,
"inline":
{
"completion":true,
"selection":true
},
"key":
{
"length":1
},
"ignore":
{
"keycode":
[
111,
116
]
},
"result":
{
"limit":15
}
"length":1
},
"ignore":
{
"keycode":
[
111,
116
]
},
"result":
{
"limit":15
}
}
}
},
"body":
{
"margin":8
},
"footer":
}
},
"body":
{
"margin":8
},
"footer":
{
"margin":8,
"status":
{
"margin":8,
"status":
"open":
{
"open":
{
"complete":"{REQUEST_BASE_URL} | {TIME_C} | {RESPONSE_META} | {RESPONSE_LENGTH} bytes | {RESPONSE_SECONDS} seconds"
}
"complete":"{REQUEST_BASE_URL} | {TIME_C} | {RESPONSE_META} | {RESPONSE_LENGTH} bytes | {RESPONSE_SECONDS} seconds"
}
}
}
},
"history":
{
"enabled":true,
"label":"History",
"clean":
{
"timeout":null
},
"history":
"time":
{
"enabled":true,
"label":"History",
"clean":
{
"timeout":null
},
"time":
{
"format":"c"
},
"header":
"format":"c"
},
"header":
{
"margin":8,
"button":
{
"margin":8,
"button":
"open":
{
"open":
{
"visible":true,
"label":"Open"
},
"delete":
{
"visible":true,
"label":"Delete"
},
"search":
{
"visible":true,
"label":"Search"
}
"visible":true,
"label":"Open"
},
"delete":
{
"visible":true,
"label":"Delete"
},
"filter":
"search":
{
"placeholder":"Search in history..."
"visible":true,
"label":"Search"
}
},
"body":
"filter":
{
"margin":8
"placeholder":"Search in history..."
}
},
"body":
{
"margin":8
}
}
}

5
src/Entity/App.php

@ -6,6 +6,7 @@ namespace Yggverse\Yoda\Entity; @@ -6,6 +6,7 @@ namespace Yggverse\Yoda\Entity;
class App
{
public \Yggverse\Yoda\Model\Config $config;
public \Yggverse\Yoda\Model\Database $database;
public \Yggverse\Yoda\Entity\Tab\History $history;
@ -14,12 +15,10 @@ class App @@ -14,12 +15,10 @@ class App
public \GtkHeaderBar $header;
public \GtkNotebook $tabs;
public object $config;
public function __construct()
{
// Init config
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO
$this->config = new \Yggverse\Yoda\Model\Config;
// Init database
$this->database = new \Yggverse\Yoda\Model\Database(

4
src/Entity/Tab/History.php

@ -30,8 +30,8 @@ class History @@ -30,8 +30,8 @@ class History
// Init app
$this->app = $app;
// Init config
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->history;
// Init config namespace
$this->config = $app->config->tab->history;
// Cleanup expired history
if ($this->config->clean->timeout)

4
src/Entity/Tab/Page.php

@ -43,8 +43,8 @@ class Page @@ -43,8 +43,8 @@ class Page
// Init app
$this->app = $app;
// Init config
$this->config = \Yggverse\Yoda\Model\File::getConfig()->app->tab->page;
// Init config namespace
$this->config = $app->config->tab->page;
// Init DNS memory
$this->dns = new \Yggverse\Yoda\Model\Memory;

45
src/Model/Config.php

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Model;
class Config
{
public function __construct(
?string $filename = null
) {
if (empty($filename))
{
$filename = __DIR__ .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'config.json';
}
if (!file_exists($filename))
{
throw new \Exception; // @TODO
}
if (!is_readable($filename))
{
throw new \Exception; // @TODO
}
if (!$data = file_get_contents($filename))
{
throw new \Exception; // @TODO
}
if (!$config = @json_decode($data))
{
throw new \Exception; // @TODO
}
foreach ($config as $key => $value)
{
$this->{$key} = $value; // @TODO
}
}
}

24
src/Model/File.php

@ -6,30 +6,6 @@ namespace Yggverse\Yoda\Model; @@ -6,30 +6,6 @@ namespace Yggverse\Yoda\Model;
class File
{
public static function getConfig(): object
{
$filename = __DIR__ .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'config.json';
if (file_exists($filename) && is_readable($filename))
{
$result = json_decode(
file_get_contents(
$filename
)
);
}
if (empty($result))
{
throw new \Exception(); // @TODO
}
return $result;
}
public static function getTheme(string $name): string
{
$filename = __DIR__ .

Loading…
Cancel
Save