Download the PHP package kdevhubin/pdoentitygenerator without Composer

On this page you can find all versions of the php package kdevhubin/pdoentitygenerator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pdoentitygenerator

PDO Entity Generator

A CLI tool to generate PHP PDO Entity and Repository classes from database tables. Works in any PHP project — no framework required.

Table of Contents


Requirements

Getting Started

Installation

Install the package via Composer:

This package is a Composer Plugin. On first install, Composer will prompt you to allow the plugin:

Type y to allow it. You can also pre-authorise the plugin by adding it to your project's composer.json:

Once allowed, the plugin automatically creates config/pdoentitygenerator.yaml with default settings. There is no manual setup step required.

Configuration

Open config/pdoentitygenerator.yaml in your project root and update it with your database credentials:

Important: The database.dbname field is required. The generator will not run without it.

Quick Start


Usage

Generating Entities

Run the CLI command with the table subcommand followed by the database table name:

The tool will:

  1. Read config/pdoentitygenerator.yaml for database connection details
  2. Connect to the database via PDO
  3. Inspect the table schema (column names, types, nullability)
  4. Generate an Entity class, a Repository class, and a PdoFactory class in the configured output directories

Example

This generates:

Generated Entity Example

For a table test_my_table with columns id, name, email, and created_at:

Generated Repository Example

CRUD Methods

Method Description Return Type
find($id) Finds a single entity by primary key ?Entity (null if not found)
findAll() Returns all entities from the table Entity[]
insert($entity) Inserts a new record and sets the generated ID on the entity Entity
update($entity) Updates an existing record by primary key Entity
delete($id) Deletes a record by primary key bool

All queries use prepared statements with bindValue() and explicit PDO::PARAM_* type constants to enforce data types and prevent SQL injection.

Generated PdoFactory

The generator also creates a PdoFactory class that reads your database credentials from config/pdoentitygenerator.yaml and returns a configured PDO instance. Uses a singleton pattern — subsequent calls to create() return the same connection, avoiding redundant connections. Call reset() to force a new connection. This is framework-agnostic and works in any PHP project.

Plain PHP Usage

Symfony Usage (services.yaml)

Register the factory as a service to enable autowiring for all repositories:

Using Generated Classes


Reference

Configuration Options

Key Description Default
database.host Database host 127.0.0.1
database.port Database port 3306
database.dbname Default database name (required) —
database.username Database username root
database.password Database password —
database.driver PDO driver mysql
output.entity_namespace Namespace for generated entities App\Entity
output.repository_namespace Namespace for generated repositories App\Repository
output.factory_namespace Namespace for generated factory class App\Factory
output.entity_directory Output directory for entity files src/Entity
output.repository_directory Output directory for repository files src/Repository
output.factory_directory Output directory for factory file src/Factory

Naming Conventions

The generator automatically converts between database snake_case and PHP naming conventions:

Database (snake_case) PHP (camelCase / PascalCase) Used For
test_my_table TestMyTable Class name
created_at createdAt Property name
first_name firstName Property name
id id Property name

Type Mapping

SQL Type PHP Type
int, integer, bigint, smallint, mediumint, tinyint int
varchar, char, text, tinytext, mediumtext, longtext, enum, set, json string
decimal, float, double, numeric, real float
datetime, timestamp, date \DateTimeImmutable
tinyint(1), boolean, bool bool
time string
year int

Architecture

How It Works

  1. CLI Entry Point (bin/pdoentitygenerator) — Resolves the Composer autoloader and delegates to GenerateEntityCommand
  2. Command (GenerateEntityCommand) — Parses argv, loads config, connects to the database, and orchestrates the generation pipeline
  3. Config Loader (ConfigLoader) — Reads config/pdoentitygenerator.yaml, merges with defaults, and validates required fields
  4. Table Inspector (TableInspector) — Executes DESCRIBE <table> to retrieve column metadata (name, type, nullability, primary key)
  5. Entity Generator (EntityGenerator) — Produces a POPO class with typed properties, getters, setters, and snake_case→camelCase conversion
  6. Repository Generator (RepositoryGenerator) — Produces a repository class with find, findAll, insert, update, delete methods using bindValue() with explicit PDO::PARAM_* type constants
  7. PdoFactory Generator (PdoFactoryGenerator) — Produces a framework-agnostic factory class that reads database credentials from config/pdoentitygenerator.yaml and returns a configured PDO instance
  8. Post-Install Handler (PostInstallHandler) — Composer Plugin (implements PluginInterface and EventSubscriberInterface) that subscribes to POST_INSTALL_CMD and POST_UPDATE_CMD events to auto-create config/pdoentitygenerator.yaml in the host project when the package is installed

Contributing

Development Setup

  1. Clone the repository:

  2. Install dependencies:

  3. Set up a test database (MySQL/MariaDB):

  4. Configure the tool:

    Create config/pdoentitygenerator.yaml with your test database credentials:

  5. Run the generator to verify everything works:

Project Structure

Directory / File Purpose
bin/pdoentitygenerator CLI entry point — edit to change autoloader resolution logic
src/Command/ CLI command handling and argument parsing
src/Composer/ Composer Plugin — subscribes to install/update events to auto-create config
src/Config/ Configuration loading and validation
src/Database/ Database introspection (schema reading)
src/Generator/ Code generation — Entity, Repository, and PdoFactory templates

Coding Standards

This project follows the PHP Coding Standards and Best Practices document. Key rules are summarised below.

General

PHPDoc

Imports and Namespaces

Class Structure

PHP 8.4 Features

Strings and Arrays

Best Practices

Adding a New SQL Type Mapping

To add support for a new SQL data type:

  1. Open src/Database/TableInspector.php
  2. Add the mapping to the TYPE_MAP constant:

  3. If the type requires special handling in generated code (e.g. custom hydration or parameter binding), update the corresponding match expressions in:
    • src/Generator/RepositoryGenerator.php → buildHydrateBody() for reading from DB
    • src/Generator/RepositoryGenerator.php → buildBindValueLine() for writing to DB
    • src/Generator/RepositoryGenerator.php → resolvePdoParamType() if a new PDO parameter type is needed

Modifying Generated Code Templates

The generated Entity and Repository code is built using PHP heredoc templates within the generator classes:

When modifying templates:

Testing Changes Locally

After making changes, verify the generator produces valid output:

Submitting Changes

  1. Create a feature branch from test-generator:

  2. Make your changes and verify generated output
  3. Ensure all PHPDoc comments are complete with @param, @return, and @throws tags
  4. Verify imports are alphabetised and no FQNs are used in code
  5. Commit with a descriptive message
  6. Push and create a pull request targeting test-generator

Troubleshooting

"Configuration file not found" error

The config/pdoentitygenerator.yaml file was not created during installation. This usually happens when the Composer Plugin was not allowed. Either:

  1. Re-run composer install and type y when prompted to trust the plugin, or
  2. Manually create the file:

Then create config/pdoentitygenerator.yaml with the contents shown in the Configuration section.

"Database name must be specified" error

The database.dbname field in config/pdoentitygenerator.yaml is empty or missing. Update it with your database name.

"Database connection failed" error

Verify your database credentials in config/pdoentitygenerator.yaml. Ensure:

"Table not found or has no columns" error

The specified table does not exist in the configured database. Check:

Generated files have incorrect namespace

Update the output.entity_namespace, output.repository_namespace, and output.factory_namespace values in config/pdoentitygenerator.yaml to match your project's PSR-4 autoload configuration.


Licence

This project is licensed under the MIT Licence — see the LICENSE file for details.


All versions of pdoentitygenerator with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
ext-pdo Version *
composer-plugin-api Version ^2.0
symfony/yaml Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kdevhubin/pdoentitygenerator contains the following files

Loading the files please wait ...