Giter VIP home page Giter VIP logo

ibexa-content-as-dto's Introduction

Ibexa content as DTO

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Introduction

This bundle give the possibility to visualize your contents data as a DTO (data transform object). A DTO (Data Transform Object) is a simple object with properties and getters/setters who store data. Ibexa Content object are complex and have a lot of information. A content object transformed into a DTO will be easier to read and use because it will contain only fields value (in current language for multiple languages).

Requirements

  • PHP 8.1 or later
  • Ibexa 4.0 (Ibexa DXP) / Symfony 5.*

Installation

Step 1: Install Bundle

$ composer require HamHamFonFon/ibexa-content-dto

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php
return [
    // ...
    HamHamFonFon\IbexaContentDto\IbexaContentDtoBundle::class => ['all' => true],
];

Step 3 : Configure the Bundle

Configure directory_repository , directory_dto and content_type_groups values :

  • directory_repository: path where repositories will be created (e.g.: src/Repository/)
  • directory_dto: path where DTO will be created (e.g.: src/Entity/DTO/)
  • content_type_groups: list of content-groups ("Content" by default)
# config/packages/ibx_content_dto.yaml
ibx_content_dto:
  directory_repository: src/Path/To/Repository/Directory
  directory_dto: src/Path/To/Dto/Directory
  content_type_groups: 
    - Content
    - Custom group...   

Basic usages

DTO works in couple with a repository linked to it. DTO contains only fields values and repository retrieve data from your back-office helped with Ibexa repositories service.

Step 1: Create a couple DTO/Repository

There is two ways to create a couple DTO/repository

Manually:

Create your DTO class, add properties (camelcase-style). Properties name must be same as fields identifier but in camel-case style. Your DTO needs to extend AbstractDto class and implements DtoInterface interface. Add getters/setters and mandatory methods.

Example, you have a content-type article with fields title (ezstring), title_long (ezstring), image_header (ezimage), text (ezrichtext), related_articles (ezobjectrelationlist) Your DTO will be like this :

use HamHamFonFon\IbexaContentDto\Entity\DtoInterface;
use HamHamFonFon\IbexaContentDto\Entity\Dto\AbstractDto;

class Article extends AbstractDto implements DtoInterface
{
    protected ?string $title;
    protected ?string $titleLong;
    protected $image;
    protected ?DOMDocument $text;
    protected ListDto $relatedArticles;

    // List of getters and setters...

    /**
     * @return array|null
     */
    public function listObjectRelationListFields(): ?array
    {
        return ['relatedArticles'];
    }
}

You can add your own methods in the DTO if you have specific needs.

Automatically

Just use symfony command php bin/console dto:create, both classes will be generated.

Step 2: Complete DTO

Step 3: Get an ibexa content into DTO

Step 4: Get a list of content into collection of DTO

Future evolution

  • Create or update content from a DTO

Contributes

I accept contributions, please fork the project and submit pull requests.

Bugs and issues

In case you find some bugs or have question about this repository, open an issue and I will answer you as soon as possible.

Authors

Stéphane MEAUDRE [email protected]

ibexa-content-as-dto's People

Contributors

astro-otter-space avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.