定制 delboy1978uk/bone-doctrine 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

delboy1978uk/bone-doctrine

Composer 安装命令:

composer require delboy1978uk/bone-doctrine

包简介

Doctrine functionality for Bone Framework

README 文档

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.

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.

delboy1978uk/bone-doctrine 适用场景与选型建议

delboy1978uk/bone-doctrine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.18k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 delboy1978uk/bone-doctrine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 delboy1978uk/bone-doctrine 我们能提供哪些服务?
定制开发 / 二次开发

基于 delboy1978uk/bone-doctrine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 14
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-12