Dokumentacja TreeStructInfoExporter PHP
Eksporter struktury TreeStructInfo zapisanej w formie tablicy PHP do postaci tekstowej zgodnej z formatem TreeStructInfo. Wspiera wcięcia, atrybuty referencyjne i strukturę zagnieżdżonych węzłów.
Wersja: 1.0
Autor: Dariusz Rorat
Licencja: BSD 3-Clause
Spis treści
- Wymagania
- Instalacja
- Przykład użycia
- Funkcje publiczne
- Struktura danych wejściowych
- Format wyjściowy
- Licencja
Wymagania
- PHP 5.4 lub nowszy
- Brak zewnętrznych zależności
Instalacja
Wystarczy załączyć klasę do swojego projektu:
require_once 'TreeStructInfoExporter.php';
Przykład użycia
$exporter = new TreeStructInfoExporter();
$exporter->setIndent(" "); // opcjonalnie: zmień domyślne wcięcia (spacje/taby)
$exporter->setRefAttributes([
'author' => 'Jan Kowalski',
'license' => 'BSD 3-Clause'
]);
$data = [
'version' => '2.0',
'name' => 'MyTree',
'data' => [
'settings' => [
'enabled' => true,
'max' => 10
],
'info' => [
'description' => 'Sample tree'
]
]
];
$text = $exporter->export($data);
file_put_contents('output.tsi', $text);
Funkcje publiczne
export(array $obj): string
Eksportuje drzewo jako tekst w formacie TreeStructInfo.
- Parametry:
$obj
– tablica zawierająca przynajmniejversion
oraz opcjonalniename
idata
- Zwraca: string
- Wyjątek:
InvalidArgumentException
przy niepoprawnym wejściu
setIndent(string $indentString): void
Ustawia niestandardowy ciąg znaków jako wcięcie (np. "\t"
, " "
).
setRefAttributes(array $refs): void
Ustawia atrybuty referencyjne (ref attr
) do dodania po głównym drzewie.
Struktura danych wejściowych
Minimalna struktura:
[
'version' => '2.0',
'data' => [ ... ]
]
Pełna struktura z nazwą i danymi:
[
'version' => '2.0',
'name' => 'MyTree',
'data' => [
'nodeName' => [
'attrName' => 'value',
...
],
...
]
]
Format wyjściowy
Przykład wygenerowanego pliku .tsi
:
treestructinfo "2.0" name "MyTree"
node settings
attr enabled "true"
attr max "10"
end node
node info
attr description "Sample tree"
end node
end tree
ref attr author "Jan Kowalski"
ref attr license "BSD 3-Clause"
Licencja
Projekt udostępniony na licencji BSD 3-Clause.
BSD-3-Clause
Сopyright (c) 2025 Dariusz Rorat
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. -
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. - Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.