PHP code example of mouf / schema-analyzer

1. Go to this page and download the library: Download mouf/schema-analyzer 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/ */

    

mouf / schema-analyzer example snippets


// $conn is the DBAL connection.
$schemaAnalyzer = new SchemaAnalyzer($conn->getSchemaManager());

// Let's detect all junctions tables
$tables = $schemaAnalyzer->detectJunctionTables();
// This will return an array of Doctrine\DBAL\Schema\Table objects

// Get all junction tables except the ones that are references by a foreign key.
$tables = $schemaAnalyzer->detectJunctionTables(true);

$parentKeyConstraint = $schemaAnalyzer->getParentRelationship("user");
/* @var $parentKeyConstraint ForeignKeyConstraint */
$parent = $parentKeyConstraint->getForeignTableName();
// This will return the "contact" table (as a string)

$childrenKeyConstraints = $schemaAnalyzer->getChildrenRelationships("contact");
/* @var $childrenKeyConstraints ForeignKeyConstraint[] */
$children = array_map(function($item) { return $item->getLocalTableName(); }, $childrenKeyConstraints);
// This will return an array of tables whose parent is contact: ["user"]

// $conn is the DBAL connection.
$schemaAnalyzer = new SchemaAnalyzer($conn->getSchemaManager());

// Let's detect the shortest path between 2 tables:
$fks = $schemaAnalyzer->getShortestPath("users", "rights");
// This will return an array of Doctrine\DBAL\Schema\ForeignKeyConstraint objects

// $conn is the DBAL connection.
// Let's use the ApcCache (or any other Doctrine cache...)
$cache = new ApcCache();
$schemaAnalyzer = new SchemaAnalyzer($conn->getSchemaManager(), $cache, "my_prefix");

$schemaAnalyzer->setForeignKeyCost($tableName, $columnName, $cost);

$schemaAnalyzer->setTableCostModifier($tableName, $cost);