protected function generateFromConfigPath($configPath) { try { if (!file_exists($configPath)) { echo 'Config path does not exist: ' . $configPath . "\n"; return; } if (!is_dir($configPath)) { echo 'Config path is not a directory: ' . $configPath . "\n"; return; } // Which config to use? $schemaGeneratorConfigFile = $configPath . 'database_schema_generator.inc.php'; $coughGeneratorConfigFile = $configPath . 'cough_generator.inc.php'; // Get the database config $schemaGeneratorConfig = DatabaseSchemaGeneratorConfig::constructFromFile($schemaGeneratorConfigFile); // Load the schema into memory $schemaGenerator = new DatabaseSchemaGenerator($schemaGeneratorConfig); if ($this->verbose) { $schemaGenerator->enableVerbose(); } $schema = $schemaGenerator->generateSchema(); // Dump some verbose messages. // echo "\n"; // $schema->outputRelationshipCounts(); // echo "\n" . 'About to run the SchemaManipulator and re-output the relationships.' . "\n"; // Manipulate the schema (to add any missed relationships, e.g.) $manipulator = new SchemaManipulator($schemaGeneratorConfig); if ($this->verbose) { $manipulator->enableVerbose(); } $manipulator->manipulateSchema($schema); // Dump some verbose messages again to see if the manipulator added anything. // echo "\n"; // $schema->outputRelationshipCounts(); // Get the cough generator config $coughGeneratorConfig = CoughGeneratorConfig::constructFromFile($coughGeneratorConfigFile); // Generate files into memory $coughGenerator = new CoughGenerator($coughGeneratorConfig); $classes = $coughGenerator->generateCoughClasses($schema); // Add some spacing if verbose mode is on if ($this->verbose) { echo "\n"; } // Write files to disk $coughWriter = new CoughWriter($coughGeneratorConfig); if (!$coughWriter->writeClasses($classes)) { echo 'Trouble writing classes:' . "\n"; echo '------------------------' . "\n"; foreach ($coughWriter->getErrorMessages() as $message) { echo $message . "\n"; } echo "\n"; } else { $lineCount = 0; foreach ($classes as $class) { $lineCount += substr_count($class->getContents(), "\n"); } echo 'Success writing ' . count($classes) . ' classes (' . number_format($lineCount) . ' lines) with ' . $schema->getNumberOfHasOneRelationships() . ' one-to-one relationships and ' . $schema->getNumberOfHasManyRelationships() . ' one-to-many relationships!' . "\n"; } if ($this->verbose) { echo "\n" . 'PHP memory usage:' . "\n"; echo number_format(memory_get_usage()) . " used\n"; if (version_compare(phpversion(), '5.2.0', '>=')) { echo number_format(memory_get_usage(true)) . " allocated\n"; } } } catch (Exception $e) { echo $e->getMessage() . "\n"; } }