Update website
This commit is contained in:
parent
0a686aeb9a
commit
c4ffa0f6ee
4360 changed files with 1727 additions and 718385 deletions
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Williamdes\MariaDBMySQLKBS;
|
||||
|
||||
use stdClass;
|
||||
use JsonSerializable;
|
||||
|
||||
class KBDocumentation extends stdClass implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* The URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* The anchor
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $anchor = null;
|
||||
|
||||
/**
|
||||
* Create a KBEntry object
|
||||
*
|
||||
* @param string $url The url
|
||||
* @param string|null $anchor The anchor
|
||||
*/
|
||||
public function __construct(string $url, ?string $anchor = null)
|
||||
{
|
||||
$this->url = $url;
|
||||
if ($anchor !== null) {
|
||||
$this->anchor = $anchor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the anchor
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAnchor(): ?string
|
||||
{
|
||||
return $this->anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for json_encode function
|
||||
* This can seem useless, do not remove it.
|
||||
*
|
||||
* @return array<string,string>
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
$outObj = [];
|
||||
$outObj['url'] = $this->url;
|
||||
if ($this->anchor !== null) {
|
||||
$outObj['anchor'] = $this->anchor;
|
||||
}
|
||||
return $outObj;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Williamdes\MariaDBMySQLKBS;
|
||||
|
||||
use stdClass;
|
||||
use JsonSerializable;
|
||||
|
||||
class KBEntry extends stdClass implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* The name of the variable
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Type of variable
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $type = null;
|
||||
|
||||
/**
|
||||
* Is dynamic ?
|
||||
*
|
||||
* @var bool|null
|
||||
*/
|
||||
private $dynamic = null;
|
||||
|
||||
/**
|
||||
* Documentations
|
||||
*
|
||||
* @var KBDocumentation[]
|
||||
*/
|
||||
private $docs = null;
|
||||
|
||||
/**
|
||||
* Create a KBEntry object
|
||||
*
|
||||
* @param string $name The name of the variable
|
||||
* @param string|null $type Type of variable
|
||||
* @param bool|null $dynamic Is dynamic ?
|
||||
*/
|
||||
public function __construct(string $name, ?string $type, ?bool $dynamic)
|
||||
{
|
||||
$this->name = $name;
|
||||
if ($type !== null) {
|
||||
$this->type = $type;
|
||||
}
|
||||
if ($dynamic !== null) {
|
||||
$this->dynamic = $dynamic;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the variable name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the variable dynamic
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function isDynamic(): ?bool
|
||||
{
|
||||
return $this->dynamic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the variable type
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Variable has documentations
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasDocumentations(): bool
|
||||
{
|
||||
if ($this->docs === null) {
|
||||
return false;
|
||||
} else {
|
||||
return count($this->docs) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all documentations
|
||||
*
|
||||
* @return KBDocumentation[]
|
||||
*/
|
||||
public function getDocumentations(): array
|
||||
{
|
||||
return $this->docs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add documentation link
|
||||
*
|
||||
* @param string $url The URL
|
||||
* @param string|null $anchor The anchor
|
||||
* @return KBDocumentation
|
||||
*/
|
||||
public function addDocumentation(string $url, ?string $anchor = null): KBDocumentation
|
||||
{
|
||||
$this->url = $url;
|
||||
if ($this->docs === null) {
|
||||
$this->docs = [];
|
||||
}
|
||||
$kbd = new KBDocumentation($url, $anchor);
|
||||
$this->docs[] = $kbd;
|
||||
return $kbd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for json_encode function
|
||||
* This can seem useless, do not remove it.
|
||||
*
|
||||
* @return array<string,KBDocumentation[]|bool|string>
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
$outObj = [];
|
||||
$outObj['name'] = $this->name;
|
||||
if ($this->type !== null) {
|
||||
$outObj['type'] = $this->type;
|
||||
}
|
||||
if ($this->dynamic !== null) {
|
||||
$outObj['dynamic'] = $this->dynamic;
|
||||
}
|
||||
if ($this->docs !== null) {
|
||||
$outObj['docs'] = $this->docs;
|
||||
}
|
||||
return $outObj;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Williamdes\MariaDBMySQLKBS;
|
||||
|
||||
use Exception;
|
||||
|
||||
class KBException extends Exception
|
||||
{
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Williamdes\MariaDBMySQLKBS;
|
||||
|
||||
use stdClass;
|
||||
|
||||
class Search
|
||||
{
|
||||
/**
|
||||
* Loaded data
|
||||
*
|
||||
* @var stdClass
|
||||
*/
|
||||
public static $data;
|
||||
|
||||
/**
|
||||
* Data is loaded
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $loaded = false;
|
||||
|
||||
public const ANY = -1;
|
||||
public const MYSQL = 1;
|
||||
public const MARIADB = 2;
|
||||
public const DS = DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* The directory where the data is located
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $DATA_DIR = __DIR__ . self::DS . '..' . self::DS . 'dist' . self::DS;
|
||||
|
||||
/**
|
||||
* Load data from disk
|
||||
*
|
||||
* @return void
|
||||
* @throws KBException
|
||||
*/
|
||||
public static function loadData(): void
|
||||
{
|
||||
if (Search::$loaded === false) {
|
||||
$filePath = Search::$DATA_DIR . 'merged-ultraslim.json';
|
||||
if (! is_file($filePath)) {
|
||||
throw new KBException($filePath . ' does not exist !');
|
||||
}
|
||||
$contents = file_get_contents($filePath);
|
||||
if ($contents === false) {
|
||||
throw new KBException($filePath . ' does not exist !');
|
||||
}
|
||||
$decodedData = json_decode($contents);
|
||||
if ($decodedData instanceof stdClass) {
|
||||
Search::$data = $decodedData;
|
||||
Search::$loaded = true;
|
||||
return;
|
||||
}
|
||||
throw new KBException($filePath . ' could not be JSON decoded !');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load test data
|
||||
*
|
||||
* @param SlimData $slimData The SlimData object
|
||||
* @return void
|
||||
*/
|
||||
public static function loadTestData(SlimData $slimData): void
|
||||
{
|
||||
$decodedData = json_decode((string) json_encode($slimData));
|
||||
if ($decodedData instanceof stdClass) {
|
||||
Search::$data = $decodedData;
|
||||
Search::$loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the first link to doc available
|
||||
*
|
||||
* @param string $name Name of variable
|
||||
* @param int $type (optional) Type of link Search::MYSQL/Search::MARIADB/Search::ANY
|
||||
* @return string
|
||||
* @throws KBException
|
||||
*/
|
||||
public static function getByName(string $name, int $type = Search::ANY): string
|
||||
{
|
||||
self::loadData();
|
||||
$kbEntries = self::getVariable($name);
|
||||
if (isset($kbEntries->a)) {
|
||||
foreach ($kbEntries->a as $kbEntry) {
|
||||
if ($type === Search::ANY) {
|
||||
return Search::$data->urls[$kbEntry->u] . '#' . $kbEntry->a;
|
||||
} elseif ($type === Search::MYSQL) {
|
||||
if ($kbEntry->t === Search::MYSQL) {
|
||||
return Search::$data->urls[$kbEntry->u] . '#' . $kbEntry->a;
|
||||
}
|
||||
} elseif ($type === Search::MARIADB) {
|
||||
if ($kbEntry->t === Search::MARIADB) {
|
||||
return Search::$data->urls[$kbEntry->u] . '#' . $kbEntry->a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new KBException($name . ' does not exist for this type of documentation !');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a variable
|
||||
*
|
||||
* @param string $name Name of variable
|
||||
* @return stdClass
|
||||
* @throws KBException
|
||||
*/
|
||||
public static function getVariable(string $name): stdClass
|
||||
{
|
||||
self::loadData();
|
||||
if (isset(Search::$data->vars->{$name})) {
|
||||
return Search::$data->vars->{$name};
|
||||
} else {
|
||||
throw new KBException($name . ' does not exist !');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the type of the variable
|
||||
*
|
||||
* @param string $name Name of variable
|
||||
* @return string
|
||||
* @throws KBException
|
||||
*/
|
||||
public static function getVariableType(string $name): string
|
||||
{
|
||||
self::loadData();
|
||||
$kbEntry = self::getVariable($name);
|
||||
if (isset($kbEntry->t)) {
|
||||
return Search::$data->varTypes->{$kbEntry->t};
|
||||
} else {
|
||||
throw new KBException($name . ' does have a known type !');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of static variables
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public static function getStaticVariables(): array
|
||||
{
|
||||
return self::getVariablesWithDynamic(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of dynamic variables
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public static function getDynamicVariables(): array
|
||||
{
|
||||
return self::getVariablesWithDynamic(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of variables having dynamic = $dynamic
|
||||
*
|
||||
* @param bool $dynamic dynamic=true/dynamic=false
|
||||
* @return array<int,string>
|
||||
*/
|
||||
public static function getVariablesWithDynamic(bool $dynamic): array
|
||||
{
|
||||
self::loadData();
|
||||
$staticVars = [];
|
||||
foreach (Search::$data->vars as $name => $var) {
|
||||
if (isset($var->d)) {
|
||||
if ($var->d === $dynamic) {
|
||||
$staticVars[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $staticVars;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Williamdes\MariaDBMySQLKBS;
|
||||
|
||||
use stdClass;
|
||||
use JsonSerializable;
|
||||
|
||||
class SlimData extends stdClass implements JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Variables
|
||||
*
|
||||
* @var KBEntry[]
|
||||
*/
|
||||
private $vars = [];
|
||||
|
||||
/**
|
||||
* File revision
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
private $version = 1;
|
||||
|
||||
/**
|
||||
* Urls
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $urls = [];
|
||||
|
||||
/**
|
||||
* Types of documentation
|
||||
*
|
||||
* @var array<string,int>
|
||||
*/
|
||||
private $types = ['MYSQL' => 1, 'MARIADB' => 2];
|
||||
|
||||
/**
|
||||
* Types of variables
|
||||
*
|
||||
* @var array<string,int>
|
||||
*/
|
||||
private $varTypes = [
|
||||
'string' => 1,
|
||||
'boolean' => 2,
|
||||
'integer' => 3,
|
||||
'numeric' => 4,
|
||||
'enumeration' => 5,
|
||||
'set' => 6,
|
||||
'directory name' => 7,
|
||||
'file name' => 8,
|
||||
'byte' => 9,
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a slimData object
|
||||
*
|
||||
* @param float|null $version The version
|
||||
* @param array<string,int>|null $types The types of documentations
|
||||
* @param array<string,int>|null $varTypes The types of variables
|
||||
*/
|
||||
public function __construct(
|
||||
?float $version = null,
|
||||
?array $types = null,
|
||||
?array $varTypes = null
|
||||
) {
|
||||
if ($version !== null) {
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
if ($types !== null) {
|
||||
$this->types = $types;
|
||||
}
|
||||
|
||||
if ($varTypes !== null) {
|
||||
$this->varTypes = $varTypes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a variable
|
||||
*
|
||||
* @param string $name The name
|
||||
* @param string|null $type The type
|
||||
* @param bool|null $dynamic Is dynamic
|
||||
* @return KBEntry The newly created KBEntry
|
||||
*/
|
||||
public function addVariable(string $name, ?string $type, ?bool $dynamic): KBEntry
|
||||
{
|
||||
$kbe = new KBEntry($name, $type, $dynamic);
|
||||
$this->vars[] = $kbe;
|
||||
return $kbe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for json_encode function
|
||||
* This can seem useless, do not remove it.
|
||||
*
|
||||
* @phpstan-ignore-next-line
|
||||
* @return array<string,array|float|stdClass>
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
$outObj = [];
|
||||
if (count($this->vars) > 0) {
|
||||
$vars = new stdClass();
|
||||
foreach ($this->vars as $var) {
|
||||
$variable = new stdClass();
|
||||
$variable->d = $var->isDynamic();
|
||||
if ($variable->d === null) {
|
||||
unset($variable->d);
|
||||
}
|
||||
|
||||
if ($var->getType() !== null) {
|
||||
if (isset($this->varTypes[$var->getType()]) === false) {
|
||||
$this->varTypes[$var->getType()] = count($this->varTypes) + 1;
|
||||
}
|
||||
|
||||
$variable->t = $this->varTypes[$var->getType()];
|
||||
}
|
||||
|
||||
if ($var->hasDocumentations()) {
|
||||
$variable->a = [];
|
||||
foreach ($var->getDocumentations() as $kbd) {
|
||||
$entry = new stdClass();
|
||||
$entry->a = $kbd->getAnchor();
|
||||
if ($entry->a === null) {
|
||||
unset($entry->a);
|
||||
}
|
||||
if (preg_match('!^(https|http)://mariadb.com!', $kbd->getUrl())) {
|
||||
$entry->t = $this->types['MARIADB'];
|
||||
} elseif (preg_match('!^(https|http)://dev.mysql.com!', $kbd->getUrl())) {
|
||||
$entry->t = $this->types['MYSQL'];
|
||||
}
|
||||
if (isset($entry->t)) {// If has no valid type, skip.
|
||||
//Do not allow other urls.
|
||||
$keyIndex = array_search($kbd->getUrl(), $this->urls);
|
||||
if ($keyIndex === false) {
|
||||
$this->urls[] = $kbd->getUrl();
|
||||
}
|
||||
$keyIndex = array_search($kbd->getUrl(), $this->urls);
|
||||
$entry->u = $keyIndex;
|
||||
|
||||
$variable->a[] = $entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$vars->{$var->getName()} = $variable;
|
||||
}
|
||||
$outObj['vars'] = $vars;
|
||||
}
|
||||
$outObj['version'] = $this->version;
|
||||
if (count($this->vars) > 0) {
|
||||
$outObj['types'] = array_flip($this->types);
|
||||
$outObj['varTypes'] = array_flip($this->varTypes);
|
||||
$outObj['urls'] = $this->urls;
|
||||
}
|
||||
return $outObj;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue