-
-
Save r3sult/ec046ef010cfa9f3a68da0f69413d86b to your computer and use it in GitHub Desktop.
Composer project to generate PHP Doctrine 2 models from database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // bootstrap.php | |
| // Include Composer Autoload (relative to project root). | |
| use Doctrine\ORM\Tools\Setup; | |
| use Doctrine\ORM\EntityManager; | |
| date_default_timezone_set('America/Lima'); | |
| require_once "vendor/autoload.php"; | |
| // Create a simple "default" Doctrine ORM configuration for Annotations | |
| $isDevMode = true; | |
| //$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/src"), $isDevMode); | |
| // or if you prefer yaml or XML | |
| //$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode); | |
| $config = Setup::createYAMLMetadataConfiguration(array(__DIR__ . "/config/yaml"), $isDevMode); | |
| // the connection configuration | |
| $conn = array( | |
| 'driver' => 'pdo_mysql', | |
| 'user' => 'root', | |
| 'password' => 'password', | |
| 'dbname' => 'dbname', | |
| 'port' => '3306' | |
| ); | |
| // obtaining the entity manager | |
| $entityManager = EntityManager::create($conn, $config); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Doctrine\ORM\Tools\Console\ConsoleRunner; | |
| // Replace it to your own project bootstrap.php file | |
| require_once 'bootstrap.php'; | |
| return ConsoleRunner::createHelperSet($entityManager); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "require": { | |
| "doctrine/orm": "*", | |
| "symfony/yaml": "*" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Doctrine 2 Entities Generator v0.1 | |
| # ================================== | |
| # Requirements | |
| # ============ | |
| # It's necessary to create a composer project before exec this script. | |
| # More info about composer at https://getcomposer.org/doc/00-intro.md | |
| echo Doctrine 2 Entities Generator v0.1 | |
| echo ================================== | |
| # Remove ./config/yaml directory before | |
| rm -rf ./config/yaml | |
| # Create yaml directory | |
| mkdir ./config/yaml | |
| # Read the ./cli-config.php (by default) and generate mapping yaml files to ./config/yaml directory | |
| php vendor/bin/doctrine orm:convert-mapping --namespace="" --force --from-database yml ./config/yaml | |
| # Generated models to ./src directory | |
| php vendor/bin/doctrine orm:generate-entities --generate-annotations=false --update-entities=true --generate-methods=false ./src | |
| # Validate schema | |
| php vendor/bin/doctrine orm:validate-schema |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment