pandaac/exporter

v2.1.2 2017-06-13 14:23 UTC

This package is not auto-updated.

Last update: 2022-09-17 08:05:50 UTC


README

The aim of the pandaac exporter is to provide a simple & quick interface to export data from the common XML files found within the data/ directory of your Open Tibia server.

It is strongly recommended that you cache the response rather than parsing it over and over again.

As of right now, this exporter assumes that you're using The Forgotten Server 1.1. I have no immediate plans to expand this to any other distrobutions until I expand the distrobution range for pandaac itself. However, if there's enough public pressure for a specific distrobution, I may reconsider.

Requirements

  • PHP 5.6.4+
  • PHP Extensions
    • libxml

Install

Via Composer
composer require pandaac/exporter

Usage

Pass the absolute path to your Open Tibia server as the first argument of the Exporter object and specify which parser you would like to use as the first argument of the parse method of the Exporter object.

The parse method also accepts a second argument for additional attributes (depends on the parser), and a third argument for overriding the default filepath (or providing a specific parser with a filepath).

use Exception;
use pandaac\Exporter\Parsers;
use pandaac\Exporter\Exporter;

try {
    $exporter = new Exporter('/home/pandaac/theforgottenserver');

    $response = $exporter->parse(new Parsers\Weapons);
} catch (Exception $e) {
    // Handle exceptions as you see fit...
}
Settings

Optionally, you may pass through engine specific settings as the second argument of the \pandaac\Exporter\Exporter object.

$exporter = new Exporter('/home/pandaac/theforgottenserver', $settings);

Available settings are as follows (the selected values are the default values):

$settings = [
    'xml' => [
        // The XML engine will automatically validate any file it tries to parse,
        // and if the data is invalid, an exception will be thrown. You may
        // disable this behaviour by setting `validate` to `false`.
        'validate' => true,

        // The XML engine will not throw exceptions on missing files when
        // parsing through a recursive structure. You may enable this
        // behaviour by setting `strict` to `true`.
        'strict' => false,
    ],
]

Response

Each parser returns an Illuminate Collection object. Please refer to the Laravel documentation for details on how to utilise it.

Parsers

Parsers are what decides how to parse a certain file, and how to structure its response. It is important you use the correct parser for the correct file.

XML Parsers

  • Actions

    $exporter->parse(new \pandaac\Exporter\Parsers\Actions);
  • Chat Channels

    $exporter->parse(new \pandaac\Exporter\Parsers\ChatChannels);
  • Commands

    $exporter->parse(new \pandaac\Exporter\Parsers\Commands);
  • Creature Scripts

    $exporter->parse(new \pandaac\Exporter\Parsers\CreatureScripts);
  • Events

    $exporter->parse(new \pandaac\Exporter\Parsers\Events);
  • Global Events

    $exporter->parse(new \pandaac\Exporter\Parsers\GlobalEvents);
  • Groups

    $exporter->parse(new \pandaac\Exporter\Parsers\Groups);
  • Items

    $exporter->parse(new \pandaac\Exporter\Parsers\Items);
  • Map Houses

    You must specify the relative filename as the third argument.

    $exporter->parse(new \pandaac\Exporter\Parsers\MapHouses, [], 'forgotten-house.xml');
  • Map Spawns

    You must specify the relative filename as the third argument.

    $exporter->parse(new \pandaac\Exporter\Parsers\MapSpawns, [], 'forgotten-spawn.xml');
  • Monster

    You must specify the relative filename as the third argument.

    $exporter->parse(new \pandaac\Exporter\Parsers\Monster, [], 'Demons/Demon.xml');
  • Monsters

    You may also load the data from within each individual monster file by setting the recursive attribute to true.

    $exporter->parse(new \pandaac\Exporter\Parsers\Monsters, [ 'recursive' => true ]);
  • Mounts

    $exporter->parse(new \pandaac\Exporter\Parsers\Mounts);
  • Movements

    $exporter->parse(new \pandaac\Exporter\Parsers\Movements);
  • NPC

    You must specify the relative filename as the third argument.

    $exporter->parse(new \pandaac\Exporter\Parsers\NPC, [], 'The Oracle.xml');
  • Outfits

    $exporter->parse(new \pandaac\Exporter\Parsers\Outfits);
  • Quests

    $exporter->parse(new \pandaac\Exporter\Parsers\Quests);
  • Raid

    You must specify the relative filename as the third argument.

    $exporter->parse(new \pandaac\Exporter\Parsers\Raid, [], 'testraid.xml');
  • Raids

    You may also load the data from within each individual raid file by setting the recursive attribute to true.

    $exporter->parse(new \pandaac\Exporter\Parsers\Raids, [ 'recursive' => true ]);
  • Spells

    $exporter->parse(new \pandaac\Exporter\Parsers\Spells);
  • Stages

    $exporter->parse(new \pandaac\Exporter\Parsers\Stages);
  • TalkActions

    $exporter->parse(new \pandaac\Exporter\Parsers\TalkActions);
  • Vocations

    $exporter->parse(new \pandaac\Exporter\Parsers\Vocations);
  • Weapons

    $exporter->parse(new \pandaac\Exporter\Parsers\Weapons);
  • XMLSource
    If you have a string containing XML, you may also parse that using the following setup.

    use pandaac\Exporter\Parsers\XMLSource;
    use pandaac\Exporter\Sources\StringContent;
    
    $exporter->parse(new XMLSource(
        new StringContent('<online><player id="1" /><player id="2" /></online>')
    ));

OTBM Parsers

The OTBM engine has not yet been developed, and thus the following parsers are rendered obsolete for the time being.

  • Towns

    $exporter->parse(new \pandaac\Exporter\Parsers\Towns);

Contributing

Please refer to the PSR-2 guidelines and squash your commits together into one before submitting a pull request.

Thank you.