delboy1978uk / bone-doctrine
Doctrine functionality for Bone Framework
Installs: 1 568
Dependents: 12
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 2
Requires
- php: ^8.2
- boneframework/contracts: ^1.3.3
- delboy1978uk/barnacle: ^2.3
- delboy1978uk/bone-console: ^1.4
- delboy1978uk/form: ^v2.6
- doctrine/data-fixtures: ^1.7
- doctrine/migrations: ^3.7
- doctrine/orm: ^3.1
- league/csv: ^9.0
- psr/http-message: ^2.0
- symfony/cache: ^7.0
Requires (Dev)
- delboy1978uk/dev-tools: ^v1.1
- roave/security-advisories: dev-latest
- dev-master
- v2.11.2
- v2.11.1
- v2.11.0
- v2.10.1
- v2.10.0
- v2.9.1
- v2.9.0
- v2.8.0
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.4
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-11-switch-to-attributes-for-v2
- dev-refactor
This package is auto-updated.
Last update: 2025-08-18 14:43:39 UTC
README
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.
admin panel
You can create a quick CRUD admin panel for your entities. Example:
use Bone\BoneDoctrine\Attributes\Cast; use Bone\BoneDoctrine\Attributes\Visibility; use Bone\BoneDoctrine\Traits\HasId; use Del\Form\Field\Attributes\Field; use Del\Form\Traits\HasFormFields; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] #[ORM\HasLifecycleCallbacks] class SomeEntity { use HasFormFields; use HasId; #[ORM\Column(type: 'float')] #[Field('float|required|max:6')] // form field validator rules #[Visibility('all') // visible on index,create,edit,delete #[Cast(prefix: '€')] // prefix or suffix table values private ?float $price = null; // etc }
Now that the entity is annotated, create a service, and an admin controller as follows:
<?php declare(strict_types=1); namespace Bone\App\Service; use Bone\App\Entity\Test; use Bone\BoneDoctrine\Service\RestService; class SomeEntityService extends RestService { public function getEntityClass(): string { return SomeEntity::class; } }
The Admin controller looks like this:
<?php declare(strict_types=1); namespace Bone\App\Http\Controller; use Bone\App\Entity\SomeEntity; use Bone\App\Service\SomeEntityService; use Bone\BoneDoctrine\Http\Controller\AdminController; class TestAdminController extends AdminController { public function getEntityClass(): string { return SomeEntity::class; } public function getServiceClass(): string { return SomeEntityService::class; } }
Finally add the routes in your package class:
public function addRoutes(Container $c, Router $router): Router { // other routes here.... $router->adminResource('some-entities', TestAdminController::class, $c); }
You can now browse to /admin/some-entities
and perform CRUD actions.
api controller
You can do the same to get an instant API. Here's an example for a Perdson class. Controller:
<?php declare(strict_types=1); namespace Bone\App\Http\Controller\Api; use Bone\App\Service\PersonService; use Bone\Http\Controller\ApiController; class PersonController extends ApiController { public function getServiceClass(): string { return PersonService::class; } }
Service:
<?php declare(strict_types=1); namespace Bone\App\Service; use Bone\App\Entity\Person; use Bone\BoneDoctrine\Service\RestService; class PersonService extends RestService { public function getEntityClass(): string { return Person::class; } }
Route:
public function addRoutes(Container $c, Router $router): Router { $router->apiResource('people', PersonController::class, $c); return $router; }
You now have API REST endpoints at /api/people
.
You can see all configured routes using the bone router:list
command.