PhpTabs Documentation Build Status

Parse and write GuitarPro and MIDI files

Home Manual GitHub

IOFactory - Instanciate PhpTabs

IOFactory is done in order to:

Table of contents

All these methods return a PhpTabs resource.


create()

This method returns an empty PhpTabs resource.

Type

\PhpTabs\PhpTabs

Example


use PhpTabs\IOFactory;

// Equivalent to 'new PhpTabs()'
$tab = IOFactory::create();

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=0"

^ Table of contents


fromArray($data)

This method returns a PhpTabs resource, loaded from a PHP array.

Parameters

Type

\PhpTabs\PhpTabs

Example


use PhpTabs\IOFactory;

// Create an empty tabs
$tab = IOFactory::create();

// Export as an array
$data = $tab->export();

// Now you can reimport as an array
$tab = IOFactory::fromArray($data);

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=0"

^ Table of contents


fromFile($filename, $type)

This method returns a PhpTabs resource, loaded from a file.

Parameters

Type

\PhpTabs\PhpTabs

Examples


use PhpTabs\IOFactory;

// Create a PhpTabs instance
$tab = IOFactory::fromFile('mytabs.gp4');

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=2"

In case you need to force a parser type, use the second parameter.


use PhpTabs\IOFactory;

// Create a PhpTabs instance from a JSON file
$tab = IOFactory::fromFile('mytabs.dat', 'json');

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=2"

^ Table of contents


fromJsonFile($filename)

This method returns a PhpTabs resource, loaded from a JSON file.

Parameters

Type

\PhpTabs\PhpTabs

Examples


use PhpTabs\IOFactory;

// Create a PhpTabs instance
$tab = IOFactory::fromJsonFile('mytabs.json');

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=2"

^ Table of contents


fromSerializedFile($filename)

This method returns a PhpTabs resource, loaded from a PHP serialized file.

Parameters

Type

\PhpTabs\PhpTabs

Examples


use PhpTabs\IOFactory;

// Create a PhpTabs instance
$tab = IOFactory::fromSerializedFile('mytabs.ser');

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=2"

^ Table of contents


fromJson($string)

This method returns a PhpTabs resource, loaded from a JSON string.

Parameters

Type

\PhpTabs\PhpTabs

Examples


use PhpTabs\IOFactory;

// Create a PhpTabs instance
$tab = IOFactory::fromJson('{"song":{"name":null,"artist":null,"album":null,"author":null,"copyright":null,"writer":null,"comments":null,"channels":[],"measureHeaders":[],"tracks":[]}}');

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=0"

^ Table of contents


fromSerialized($string)

This method returns a PhpTabs resource, loaded from a PHP serialized string.

Parameters

Type

\PhpTabs\PhpTabs

Examples


use PhpTabs\IOFactory;

// Create a PhpTabs instance
$tab = IOFactory::fromSerialized('a:1:{s:4:"song";a:10:{s:4:"name";N;s:6:"artist";N;s:5:"album";N;s:6:"author";N;s:9:"copyright";N;s:6:"writer";N;s:8:"comments";N;s:8:"channels";a:0:{}s:14:"measureHeaders";a:0:{}s:6:"tracks";a:0:{}}}');

// Print track number
echo "Track count=" . $tab->countTracks();

// Should return "Track count=0"

^ Table of contents


Edit this document on GitHub