Git Product home page Git Product logo

yii2-domain's Introduction

Yii2 Domain

Domain Driven Design patters implementation for Yii2.

Includes realization of a following patters:

  • Repository
  • Entity
  • Specification (very rough implementation through ActiveQuery)
  • Strategy

Package information

Latest Stable Version Total downloads Monthly Downloads Licensing
Latest Stable Version Total Downloads Monthly Downloads License

Requirements

PHP >= 7.1 is required.

Getting Started

Run the following command to add Yii2 Domain to your project's composer.json. See Packagist for specific versions.

composer require php-kitchen/yii2-domain

Or you can copy this library from:

For additional information and guides go to the project documentation

Overview

Goal of this library is to introduce Domain Driven Design(DDD) principles to Yii2 projects and to fix ActiveRecord problem of domain layer in applications with medium and large domain area.

Each model represented as a standalone directory that contains repository, entity, record and query classes. All of these classes represent a domain model.

DIRECTORY STRUCTURE OF A TYPICAL MODEL(AS EXAMPLE - USER MODEL)

  user/                    contains all of the classes that represents domain model
        UserRepository     model repository
        UserEntity         model entity(represents domain entity - not the DB table that containd entity information) 
        UserRecord         DB record that contains entity information
        ProfileRecord      DB record with additional information thta also a part of the UserEntity.
        UserQuery          query class of model e.g. - specification of the entity

Code examples

Simple search and store:

$repository = new UserRepository();
$entity = $repository->findOneWithPk(1);
// do some manipulations with entity
$repository->validateAndSave($entity);

Complex criteria search and deleting:

$repository = new UserRepository();
$entity = $repository->find()
		->active()
		->withoutEmail()
		->one();
// do some manipulations with entity
$repository->delete($entity);

Note:

this library is designed to solve ActiveRecord problem of Yii 2. Don't use this library if you are starting a new project and looking for a solution that would allow you to build a decent architecture - you need a good framework that would allow you do build high-quality solution and Yii 2 is not a framework that would allow you to build high quality architecture and implement rich domain layer.

"Yii2Domain" library is a crutch designed to solve issues of domain layer caused by ActiveRecord in existing projects. There are few decent solutions to build domain layer in a new project:

Contributing

If you want to ask any questions, suggest improvements or just to talk with community and developers, join our server at Discord

Build status

CI status Code quality
Build Status Scrutinizer Code Quality

yii2-domain's People

Contributors

deathangel avatar miguelbemartin avatar prowwid avatar

Watchers

 avatar  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.