tangoman/entity-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tangoman/entity-helper

Composer 安装命令:

composer require tangoman/entity-helper

包简介

Symfony Entity Helper

README 文档

README

TangoMan Entity Helper provides a collection of traits for common properties to use in your project entities.

Features

  • Included asserts with custom messages (french) for property validation.
  • Fluent setters for all properties, allowing chaining.
  • Magic JsonSerialisable.

Installation

Step 1: Download the Helper

Open a command console, enter your project directory and execute the following command to download the latest stable version of this helper:

$ composer require tangoman/entity-helper

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable VichUploader

Since TangoMan Entity Helper requires VichUploaderBundle, if you plan to use UploadableDocument, or UploadableImage traits, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Vich\UploaderBundle\VichUploaderBundle(),
        );

        // ...
    }
}

Step 3: Implement your entities

Add "use" statements inside your entities for desired traits. See below for full list of availlable traits.

Step 4: Update your database schema

Open a command console, enter your project directory and execute the following command to update your database schema:

$ php bin/console schema:update

Usage

Inside your entity class: Some traits will require your entity class to use Symfony\Component\Validator\Constraints for validation. UploadableDocument and UploadableImage traits will require your entity class to use Vich\UploaderBundle\Mapping\Annotation as Vich annotation.

src\AppBundle\Entity\FooBar.php

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

// ...

use TangoMan\EntityHelper\Traits\Categorized;
use TangoMan\EntityHelper\Traits\Embeddable;
use TangoMan\EntityHelper\Traits\Featurable;
use TangoMan\EntityHelper\Traits\HasAddress;
use TangoMan\EntityHelper\Traits\HasBirthDate;
use TangoMan\EntityHelper\Traits\HasClickDate;
use TangoMan\EntityHelper\Traits\HasEmail;
use TangoMan\EntityHelper\Traits\HasFirstAndLastName;
use TangoMan\EntityHelper\Traits\HasFontAwesomeIcon;
use TangoMan\EntityHelper\Traits\HasGender;
use TangoMan\EntityHelper\Traits\HasGlyphicon;
use TangoMan\EntityHelper\Traits\HasIcon;
use TangoMan\EntityHelper\Traits\HasLabel;
use TangoMan\EntityHelper\Traits\HasMobile;
use TangoMan\EntityHelper\Traits\HasName;
use TangoMan\EntityHelper\Traits\HasPhone;
use TangoMan\EntityHelper\Traits\HasRoles;
use TangoMan\EntityHelper\Traits\HasSummary;
use TangoMan\EntityHelper\Traits\HasText;
use TangoMan\EntityHelper\Traits\HasTimePeriod;
use TangoMan\EntityHelper\Traits\HasTitle;
use TangoMan\EntityHelper\Traits\HasType;
use TangoMan\EntityHelper\Traits\HasViews;
use TangoMan\EntityHelper\Traits\HasWebsite;
use TangoMan\EntityHelper\Traits\HasWork;
use TangoMan\EntityHelper\Traits\Illustrable;
use TangoMan\EntityHelper\Traits\JsonSerializable;
use TangoMan\EntityHelper\Traits\Privatable;
use TangoMan\EntityHelper\Traits\Publishable;
use TangoMan\EntityHelper\Traits\Sluggable;
use TangoMan\EntityHelper\Traits\Slugify;
use TangoMan\EntityHelper\Traits\Timestampable;
use TangoMan\EntityHelper\Traits\UploadableDocument;
use TangoMan\EntityHelper\Traits\UploadableImage;

/**
 * Class Foobar
 *
 * @package AppBundle\Entity
 */
class Foobar
{
    use Categorized;
    use Embeddable;
    use Featurable;
    use HasAddress;
    use HasBirthDate;
    use HasClickDate;
    use HasEmail;
    use HasFirstAndLastName;
    use HasFontAwesomeIcon;
    use HasGender;
    use HasGlyphicon;
    use HasIcon;
    use HasLabel;
    use HasMobile;
    use HasName;
    use HasPhone;
    use HasRoles;
    use HasSummary;
    use HasText;
    use HasTimePeriod;
    use HasTitle;
    use HasType;
    use HasViews;
    use HasWebsite;
    use HasWork;
    use Illustrable;
    use JsonSerializable;
    use Privatable;
    use Publishable;
    use Sluggable;
    use Slugify;
    use Timestampable;
    use UploadableDocument;
    use UploadableImage;

    // ...
}

Trait JsonSerializable

Magic method to make your entities jsonserializable. Allows to use php json_encode() function on your object.

$fooBar = new FooBar;
$json = json_encode($fooBar, JSON_PRETTY_PRINT);
echo $json;

In order to use php JsonSerializable interface on your object your class must implement \JsonSerializable src\AppBundle\Entity\FooBar.php

namespace AppBundle\Entity;

use TangoMan\EntityHelper\Traits\JsonSerializable;

class FooBar implements \JsonSerializable {
    use JsonSerializable;

    // ...

Note

If you find any bug please report here : Issues

License

Copyright (c) 2018 Matthias Morin

License Distributed under the MIT license.

If you like TangoMan Entity Helper please star! And follow me on GitHub: TangoMan75 ... And check my other cool projects.

Matthias Morin | LinkedIn

统计信息

  • 总下载量: 180
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固