1. Go to this page and download the library: Download zachleigh/petrol library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zachleigh / petrol example snippets
namespace Petrol\Fillers;
use Petrol\Core\Database\Connection;
use Petrol\Core\Helpers\Traits\Parser;
use Petrol\Core\Helpers\Traits\User;
use Petrol\Core\Helpers\Traits\XmlParser;
class FillSimpleTable extends Filler
{
use Parser, User;
/**
* Database connection class.
*
* @var Petrol\Core\Database\Connection
*/
protected $connection;
/**
* Database filling method. If 'auto', Petrol will automatically insert one row
* every line. If 'manual', insertRow($data) must be called on $this->connection
* to insert a row. 'dump' will dump results to console instead of filling db.
*
* @var string ['auto, 'manual', 'dump']
*/
protected $fill = 'auto';
/**
* The file to be parsed by the Filler. File must be in Petrol/src/Files/.
*
* @var string
*/
protected $file = 'simple.txt';
/**
* The database table to be filled. Table must be created before filling.
*
* @var string
*/
protected $table = 'simple_table';
/**
* Database table columns excluding id.
*
* @var array
*/
protected $columns = [
//
];
/**
* Variables to be declared before loop begins. These variables will be stored
* on the object and can be accessed with $this->key.
*
* @var array
*/
protected $variables = [
//
];
/**
* Construct.
*
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
parent::__construct();
}
/**
* Parse the file. Petrol will go through $file line by line and send each line
* to this parse method.
*
* @param string $line [individual lines from file]
*
* @return array $data [array of columns => values for line]
*/
protected function parse($line)
{
// parse file
//
// return array;
}
}
protected function parse($line)
{
return array_combine($this->columns, $this->cleanExplode('/', $line));
}
public function register()
{
if ($this->app->environment() == 'local') {
$this->app->register('Petrol\Core\Providers\PetrolServiceProvider');
}
}
namespace App\Petrol\Fillers;
use Petrol\Core\Database\Connection;
use Petrol\Core\Helpers\Traits\Parser;
use Petrol\Core\Helpers\Traits\User;
use Petrol\Core\Helpers\Traits\XmlParser;
class FillSimpleTable extends Filler
{
use Parser, User;
/**
* Database connection class.
*
* @var Petrol\Core\Database\Connection
*/
protected $connection;
/**
* Database filling method. If 'auto', Petrol will automatically insert one row
* every line. If 'manual', insertRow($data) must be called on $this->connection
* to insert a row. 'dump' will dump results to console instead of filling db.
*
* @var string ['auto, 'manual', 'dump']
*/
protected $fill = 'auto';
/**
* The file to be parsed by the Filler. File must be in Petrol/src/Files/.
*
* @var string
*/
protected $file = 'simple.txt';
/**
* The database table to be filled. Table must be created before filling.
*
* @var string
*/
protected $table = 'simple_table';
/**
* Database table columns excluding id.
*
* @var array
*/
protected $columns = [
//
];
/**
* Variables to be declared before loop begins. These variables will be stored
* on the object and can be accessed with $this->key.
*
* @var array
*/
protected $variables = [
//
];
/**
* Construct.
*
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
parent::__construct();
}
/**
* Parse the file. Petrol will go through $file line by line and send each line
* to this parse method.
*
* @param string $line [individual lines from file]
*
* @return array $data [array of columns => values for line]
*/
protected function parse($line)
{
// parse file
//
// return array
}
}
protected function parse($line)
{
return array_combine($this->columns, $this->cleanExplode('/', $line));
}
namespace Petrol\Fillers;
use Petrol\Core\Database\Connection;
use Petrol\Core\Helpers\Traits\User;
use Petrol\Core\Helpers\Traits\Parser;
class FillSimpleTable extends Filler
{
use Parser, User;
/**
* Database connection class.
*
* @var Petrol\Core\Database\Connection
*/
protected $connection;
/**
* Database filling method. If 'auto', Petrol will automatically insert one row
* every line. If 'manual', insertRow($data) must be called on $this->connection
* to insert a row. 'dump' will dump results to console instead of filling db.
*
* @var string ['auto, 'manual', 'dump']
*/
protected $fill = 'auto';
/**
* The file to be parsed by the Filler. File must be in Petrol/src/Files/.
*
* @var string
*/
protected $file = 'simple.txt';
/**
* The database table to be filled. Table must be created before filling.
*
* @var string
*/
protected $table = 'simple_table';
/**
* Database table columns excluding id.
*
* @var array
*/
protected $columns = [
//
];
/**
* Variables to be declared before loop begins. These variables will be stored
* on the object and can be accessed with $this->key.
*
* @var array
*/
protected $variables = [
//
];
/**
* Construct.
*
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
parent::__construct();
}
/**
* Parse the file. Petrol will go through $file line by line and send each line
* to this parse method.
*
* @param string $line [individual lines from file]
*
* @return array $data [array of columns => values for line]
*/
protected function parse($line)
{
// parse file
//
// return $data;
}
}