1. Go to this page and download the library: Download inetprocess/neuralyzer 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/ */
inetprocess / neuralyzer example snippets
eate a container
$container = Edyan\Neuralyzer\ContainerFactory::createContainer();
// Configure DB Utils, .doctrine-project.org/projects/doctrine-dbal/en/2.7/reference/configuration.html
$dbUtils->configure([
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'dbname' => 'test_db',
'user' => 'root',
'password' => 'root',
]);
$writer = new \Edyan\Neuralyzer\Configuration\Writer;
$data = $writer->generateConfFromDB($dbUtils, new \Edyan\Neuralyzer\Guesser);
$writer->save($data, 'neuralyzer.yml');
// ...
$writer = new \Edyan\Neuralyzer\Configuration\Writer;
$writer->protectCols(true); // will protect primary keys
// define cols to protect (must be prefixed with the table name)
$writer->setProtectedCols([
'.*\.id',
'.*\..*_id',
'.*\.date_modified',
'.*\.date_entered',
'.*\.date_created',
'.*\.deleted',
]);
// Define tables to ignore, also with regexp
$writer->setIgnoredTables([
'acl_.*',
'config',
'email_cache',
]);
// Write the configuration
$data = $writer->generateConfFromDB($dbUtils, new \Edyan\Neuralyzer\Guesser);
$writer->save($data, 'neuralyzer.yml');
ill throw an exception if it's not valid
$reader = new Edyan\Neuralyzer\Configuration\Reader('neuralyzer.yml');
$tables = $reader->getEntities();
eate a container
$container = Edyan\Neuralyzer\ContainerFactory::createContainer();
$expression = $container->get('Edyan\Neuralyzer\Utils\Expression');
// Configure DB Utils, uration.html
$dbUtils->configure([
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'dbname' => 'test_db',
'user' => 'root',
'password' => 'root',
]);
$db = new \Edyan\Neuralyzer\Anonymizer\DB($expression, $dbUtils);
$db->setConfiguration(
new \Edyan\Neuralyzer\Configuration\Reader('neuralyzer.yml')
);
public function processEntity(string $entity, callable $callback = null): array;
// Limit of fake generated records for updates and creates.
// Default : 0 = everything to update / nothing to insert
public function setLimit(int $limit);
// Don't do anything, default true
public function setPretend(bool $pretend);
// Return or not a result, default false
public function setReturnRes(bool $returnRes);
eate a container
$container = Edyan\Neuralyzer\ContainerFactory::createContainer();
$expression = $container->get('Edyan\Neuralyzer\Utils\Expression');
// Configure DB Utils, uration.html
$dbUtils->configure([
'driver' => 'pdo_mysql',
'host' => 'mysql',
'dbname' => 'test_db',
'user' => 'root',
'password' => 'root',
]);
$reader = new \Edyan\Neuralyzer\Configuration\Reader('neuralyzer.yml');
$db = new \Edyan\Neuralyzer\Anonymizer\DB($expression, $dbUtils);
$db->setConfiguration($reader);
$db->setPretend(false);
// Get tables
$tables = $reader->getEntities();
foreach ($tables as $table) {
$total = $dbUtils->countResults($table);
if ($total === 0) {
fwrite(STDOUT, "$table is empty" . PHP_EOL);
continue;
}
fwrite(STDOUT, "$table anonymized" . PHP_EOL);
$db->processEntity($table);
}