delboy1978uk/bone-doctrine

Doctrine functionality for Bone Framework

v2.1.0 2024-10-27 14:14 UTC

README

Latest Stable Version Total Downloads License
build status Code Coverage Scrutinizer Code Quality

Doctrine functionality for Bone Framework

installation

Install via composer

composer require delboy1978uk/bone-doctrine

##Usage Simply add the Package to Bone's module config

<?php

// use statements here
use Bone\BoneDoctrine\BoneDoctrinePackage;

return [
    'packages' => [
        // packages here...,
        Bone\BoneDoctrine\BoneDoctrinePackage::class,
    ],
    // ...
];

You should already have a config/bone-db.php configuration file, as it comes by standard in the Bone Framework skeleton project.

<?php

return [
    'db' => [
        'driver' => 'pdo_mysql',
        'host' => 'mariadb',
        'dbname' => 'awesome',
        'user' => 'dbuser',
        'password' => '[123456]',
    ],
];

Also you must set paths for your proxy, cache and entity directories.

<?php

return [
    // other paths here....
    'proxy_dir' => 'data/proxies/',
    'cache_dir' => 'data/cache/',
    'entity_paths' => [],
];

entity manager

You can fetch and inject the Doctrine\ORM\EntityManager into your classes inside the package registration class:

$entityManager = $c->get(EntityManager::class);

Of course from there you can check the doctrine docs here https://www.doctrine-project.org/

database migrations

Bone Framework comes with the vendor/bin/bone command, which is essentially just Doctrine Migrations configured for Bone Framework. Not only will it scan your own entity folder for changes, but also those of any vendor packages you rely on.

Change your DB schema by updating the Doctrine annotations on your entity class, then run:

vendor/bin/bone migrant:diff
vendor/bin/bone migrant:migrate

https://github.com/delboy1978uk/user is a typical example, look in the entity folder to learn more. See Doctrine Fixtures documentation for more details.

fixtures

You can run data fixtures using the following command

vendor/bin/bone migrant:fixtures

In your Bone Framework config, add a fixtures.php and return classes that run your fixtures.

<?php
/**
 * Returns a list of fixtures by classname, in the order of their execution
 */

use Fixtures\LoadUsers;

return [
    'fixtures' => [
        LoadUsers::class,
    ],
];

See Doctrine Fixtures documentation for more details.