Improve config

parent b18d216e
...@@ -27,7 +27,7 @@ class Config extends Repository ...@@ -27,7 +27,7 @@ class Config extends Repository
$paths = $this->get('commands.paths', []); $paths = $this->get('commands.paths', []);
if (! is_dir($path)) { if (! is_dir($path)) {
TelegramLog::error('Commands path "%s" does not exist.', $path); Logger::error('Commands path "%s" does not exist.', $path);
} else if (! in_array($path, $paths, true)) { } else if (! in_array($path, $paths, true)) {
if ($before) { if ($before) {
array_unshift($paths, $path); array_unshift($paths, $path);
...@@ -76,7 +76,7 @@ class Config extends Repository ...@@ -76,7 +76,7 @@ class Config extends Repository
$admins = $this->get('admins', []); $admins = $this->get('admins', []);
if (! is_int($admin_id) || $admin_id <= 0) { if (! is_int($admin_id) || $admin_id <= 0) {
TelegramLog::error('Invalid value "%s" for admin.', $admin_id); Logger::error('Invalid value "%s" for admin.', $admin_id);
} else if (! in_array($admin_id, $admins, true)) { } else if (! in_array($admin_id, $admins, true)) {
$admins[] = $admin_id; $admins[] = $admin_id;
} }
...@@ -107,4 +107,48 @@ class Config extends Repository ...@@ -107,4 +107,48 @@ class Config extends Repository
{ {
return $this->get('admins', []); return $this->get('admins', []);
} }
/**
* Set custom upload path
*
* @param string $path Custom upload path
*
* @return void
*/
public function setUploadPath($path)
{
$this->set('upload_path', $path);
}
/**
* Get custom upload path
*
* @return string
*/
public function getUploadPath()
{
return $this->get('upload_path', '');
}
/**
* Set custom download path
*
* @param string $path Custom download path
*
* @return void
*/
public function setDownloadPath($path)
{
$this->set('download_path', $path);
}
/**
* Get custom download path
*
* @return string
*/
public function getDownloadPath()
{
return $this->get('download_path', '');
}
} }
...@@ -56,7 +56,7 @@ class ConfigTest extends TestCase ...@@ -56,7 +56,7 @@ class ConfigTest extends TestCase
$this->assertEquals($paths, $config->getCommandsPaths()); $this->assertEquals($paths, $config->getCommandsPaths());
} }
public function testAddAdmins() public function testAdmins()
{ {
$config = new Config(); $config = new Config();
...@@ -67,4 +67,25 @@ class ConfigTest extends TestCase ...@@ -67,4 +67,25 @@ class ConfigTest extends TestCase
$this->assertEquals($admins, $config->getAdmins()); $this->assertEquals($admins, $config->getAdmins());
} }
public function testUploadPath()
{
$config = new Config();
$path = '/some/path';
$config->setUploadPath($path);
$this->assertEquals($path, $config->getUploadPath());
}
public function testDownloadPath()
{
$config = new Config();
$path = '/some/path';
$config->setDownloadPath($path);
$this->assertEquals($path, $config->getDownloadPath());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment