Format::factory PHP Method

factory() public method

Create an instance of the format class e.g: echo $this->format->factory(['foo' => 'bar'])->to_csv();
public factory ( mixed $data, string $from_type = NULL ) : object
$data mixed Data to convert/parse
$from_type string Type to convert from e.g. json, csv, html
return object Instance of the format class
    public function factory($data, $from_type = NULL)
    {
        // $class = __CLASS__;
        // return new $class();
        return new static($data, $from_type);
    }

Usage Example

 public function testMethod()
 {
     // Check if everything is ok
     $original_array = array('test', 'test2');
     $xml = Format::factory($original_array)->to_json();
     $this->assertEquals('["test","test2"]', $xml);
 }
All Usage Examples Of Format::factory