IOFactory is done in order to:
All these methods return a PhpTabs resource.
This method returns an empty PhpTabs resource.
use PhpTabs\IOFactory;
// Equivalent to 'new PhpTabs()'
$tab = IOFactory::create();
// Print track number
echo "Track count=" . $tab->countTracks();
// Should return "Track count=0"
This method returns a PhpTabs resource, loaded from a PHP array.
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"
This method returns a PhpTabs resource, loaded from a file.
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"
This method returns a PhpTabs resource, loaded from a JSON file.
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"
This method returns a PhpTabs resource, loaded from a PHP serialized file.
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"
This method returns a PhpTabs resource, loaded from a JSON string.
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"
This method returns a PhpTabs resource, loaded from a PHP serialized string.
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"