Skip to content
This repository was archived by the owner on Feb 8, 2019. It is now read-only.

Commit 52899ed

Browse files
committed
Add 'YAML' Provider
1 parent d48169f commit 52899ed

File tree

1 file changed

+123
-0
lines changed
  • src/VectorNetworkProject/TheMix/provider

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2018 VectorNetworkProject. All rights reserved. MIT license.
4+
*
5+
* GitHub: https://github.com/VectorNetworkProject/TheMix
6+
* Website: https://www.vector-network.tk
7+
*/
8+
9+
namespace VectorNetworkProject\TheMix\provider;
10+
11+
12+
use pocketmine\utils\Config;
13+
14+
class YAML extends Provider
15+
{
16+
/* @var string $path */
17+
private $path;
18+
19+
/* @var string $file */
20+
private $file;
21+
22+
/**
23+
* JSON constructor.
24+
* @param string $file
25+
*/
26+
public function __construct(string $file = 'config')
27+
{
28+
$this->path = self::getPath('configs', 'yaml');
29+
$this->file = $file . '.yml';
30+
}
31+
32+
/**
33+
* @param array $table
34+
* @return void
35+
*/
36+
public function createTable(array $table = []): void
37+
{
38+
@mkdir($this->path);
39+
$config = new Config($this->path . $this->file, Config::YAML, $table);
40+
$config->save();
41+
}
42+
43+
/**
44+
* @return bool
45+
*/
46+
public function hasTable(): bool
47+
{
48+
return file_exists($this->path . $this->file)
49+
? true
50+
: false;
51+
}
52+
53+
/**
54+
* @return bool
55+
*/
56+
public function deleteTable(): bool
57+
{
58+
return unlink($this->path . $this->file)
59+
? true
60+
: false;
61+
}
62+
63+
/**
64+
* @param string $key
65+
* @param bool|mixed $data
66+
*/
67+
public function set(string $key, $data): void
68+
{
69+
$config = new Config($this->path . $this->file, Config::YAML);
70+
$config->set($key, $data);
71+
$config->save();
72+
}
73+
74+
/**
75+
* @param string $key
76+
* @return mixed
77+
*/
78+
public function get(string $key)
79+
{
80+
$config = new Config($this->path . $this->file, Config::YAML);
81+
return $config->get($key);
82+
}
83+
84+
/**
85+
* @return array
86+
*/
87+
public function getAll(): array
88+
{
89+
$config = new Config($this->path . $this->file, Config::YAML);
90+
return $config->getAll();
91+
}
92+
93+
/**
94+
* @return array
95+
*/
96+
public function getKeys(): array
97+
{
98+
$config = new Config($this->path . $this->file, Config::YAML);
99+
return $config->getAll(true);
100+
}
101+
102+
/**
103+
* @param string $key
104+
* @return bool
105+
*/
106+
public function has(string $key): bool
107+
{
108+
$config = new Config($this->path . $this->file, Config::YAML);
109+
return $config->exists($key)
110+
? true
111+
: false;
112+
}
113+
114+
/**
115+
* @param string $key
116+
* @return void
117+
*/
118+
public function remove(string $key): void
119+
{
120+
$config = new Config($this->path . $this->file, Config::YAML);
121+
$config->remove($key);
122+
}
123+
}

0 commit comments

Comments
 (0)