Search by

daycry / doctrine

daycry

Standalone Doctrine ORM toolkit with an optional CodeIgniter 4 adapter

Package info

github.com/daycry/doctrine

pkg:composer/daycry/doctrine

Statistics

Installs: 3 396

Dependents: 1

Suggesters: 0

Stars: 9

Open Issues: 0

v6.0.0 2026-10-29 09:14 UTC

README

Donate

Doctrine ORM Toolkit for PHP and CodeIgniter 4

Standalone Doctrine ORM toolkit for PHP 8.5, with an optional CodeIgniter 4 adapter.

PHPUnit PHPStan Psalm Rector Code Style Coverage Status Downloads Monthly Downloads GitHub release (latest by date) GitHub stars GitHub license Documentation

📖 Documentation: https://daycry.github.io/doctrine/

Packages and release status

This documentation describes version 6.0, with breaking API and namespace changes. See the migration guide before upgrading. Published package badges can refer to an earlier release.

Package Role
daycry/doctrine Standalone core: ORM configuration, DataTables, PSR-6 caching, PSR-3 logging, named managers and console tools
daycry/doctrine-codeigniter4 Optional adapter: CI4 configuration/services, database groups, cache backends, helpers, toolbar and Spark

The core has no CodeIgniter runtime dependency. Both packages require PHP ^8.5; the core uses ORM ^3.7, DBAL ^4.5, Symfony Cache/Console ^8 and DoctrineExtensions ^1.5. The adapter also requires CI4 ^4.7.

Installation

Choose one package from Packagist:

# Standalone core
composer require daycry/doctrine:^6.0

# CodeIgniter application: installs the core and framework too
composer require daycry/doctrine-codeigniter4:^6.0

Local path repositories are also available for development.

Standalone quick start

require __DIR__ . '/vendor/autoload.php';

use Daycry\Doctrine\Configuration;
use Daycry\Doctrine\Doctrine;

$config = new Configuration();
$config->connection = ['driver' => 'pdo_sqlite', 'memory' => true];
$doctrine = new Doctrine($config);

echo $doctrine->getEm()->getConnection()->fetchOne('SELECT 1');

For mapped entities, assign existing directories to $config->entities before constructing Doctrine. Native lazy objects are always enabled; no proxy files are generated. See standalone usage for persistent cache pools, logging, named managers and lifecycle handling.

CodeIgniter quick start

php spark doctrine:publish

The publisher writes app/Config/Doctrine.php and cli-config.php. The config extends Daycry\Doctrine\CodeIgniter4\Config\Doctrine and contains application overrides. Configure connections through Config\Database and caches through Config\Cache.

$doctrine = service('doctrine');
$em = $doctrine->getEm();

// An explicitly named database group:
$reporting = \Daycry\Doctrine\CodeIgniter4\Config\Services::doctrine(true, 'reporting');

See CI4 usage for shared services, helpers and group resets, and debug toolbar for collector/filter registration.

DataTables

The Builder works in either package and accepts an ORM QueryBuilder and a request array. It does not require an HTTP framework:

use Daycry\Doctrine\DataTables\Builder;

$response = Builder::create()
    ->withQueryBuilder($queryBuilder)
    ->withColumnAliases(['id' => 'p.id', 'name' => 'p.name'])
    ->withSearchableColumns(['p.name'])
    ->withRequestParams($requestParams)
    ->getResponse();

The query must use the p alias in this example. The response contains draw, recordsTotal, recordsFiltered and data. The default page cap is 200; length=-1 is clamped to it, and the cap must remain positive. Use getPage() for a WindowPage with items and filtered total. See Builder API and search operators.

Caching, logging and extension points

  • Inject CachePools into the core for query/result/metadata/SLC storage; defaults are independent process-local ArrayAdapters. The CI4 adapter creates pools from its framework backend.
  • Use Cache\CacheAside directly in standalone code. The adapter also autoloads the namespaced Daycry\Doctrine\CodeIgniter4\Helpers\getFromCacheOrQuery function.
  • Enable SLC, statistics, custom DBAL types, SQL filters, event listeners/subscribers, DBAL middlewares and a default repository through configuration.
  • Query logging accepts a PSR-3 logger and a slow-query threshold. The core requires an injected logger; the adapter resolves CI4's logger service.

See SLC configuration and cache statistics.

Console

The standalone console loads an application bootstrap returning Doctrine or a ManagerRegistry. Spark commands use the CI4 adapter:

php vendor/bin/daycry-doctrine doctrine-bootstrap.php orm:info
php vendor/bin/daycry-doctrine doctrine-bootstrap.php doctrine:doctor --json
php vendor/bin/daycry-doctrine doctrine-bootstrap.php doctrine:cache:warmup

php spark doctrine:doctor --group reporting --json
php spark doctrine:cache:warmup --group reporting

Doctor and warmup do not change the schema. They report connection/mapping/cache failures through nonzero exit codes. The console guide explains the bootstrap, named managers and native ORM commands.

Development

composer install
composer test
php vendor/bin/phpunit -c phpunit.standalone.xml.dist --no-coverage
composer analyze
composer cs
python -m mkdocs build --strict --site-dir build/docs

The integration suite needs its configured test database and optional cache services. The native core suite uses SQLite and a separate bootstrap. CI also installs isolated consumers to verify the core without CI4 installed and the adapter's framework discovery. See validation records.

Documentation

License

MIT.