2017 © Pedro Peláez
 

yii2-extension yii2-core

image

nullref/yii2-core

  • Saturday, May 26, 2018
  • by ZAYEC77
  • Repository
  • 6 Watchers
  • 3 Stars
  • 2,009 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 0 Forks
  • 7 Open issues
  • 4 Versions
  • 4 % Grown

The README.md

Yii2-core

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

WIP, (*2)

Module for administration, (*3)

Installation

The preferred way to install this extension to use composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist nullref/yii2-core "*"

or add, (*6)

"nullref/yii2-core": "*"

to the require section of your composer.json file., (*7)

Config structure

This module designed to work with special config file., (*8)

In case when you use module/install command it creates installed_modules.php file in condif folder if it doesn't exist., (*9)

This file will contain config array of installed modules (obviously)., (*10)

You need to merge this config with your applications config (web, console, etc)., (*11)

I recommend using the structure that described below, it used at our application template., (*12)

  • installed_modules.php
<?php return [];
  • modules.php
<?php 
$config = require(__DIR__ . '/installed_modules.php');
return array_merge($config, []);
  • web.php
<?php
$modules = require(__DIR__ . '/modules.php');
$config = [
//...
    'modules' => $modules,
//...
];
return $config;

When you are using this config structure you are able to override installed modules cofiguration in modules.php., (*13)

Also, modules.php file could be included to console.php config file., (*14)

App-specific configs could be added directly in corresponding config file., (*15)

Modules system

This module provides basic tools for creating system of modules., (*16)

Available modules:, (*17)

For full integration, you have to run console command:, (*18)

php yii module/install <module-name>

Content

Core module for fast web development based on Yii2. This package contains:, (*19)

  • components:, (*20)

    • EntityManager - component for simple managing of entities (models)
  • interfaces:, (*21)

    • IAdminModule - interface for modules which can be used by nullref\yii2-admin
    • IRoleContainer - interface which provide roles for RBAC
    • IEntityManager - interface EntityManager
    • IEntityManageble - interface for classes which contain EntityManager

Translation overriding

Core package contain PhpMessageSource class that allows to merge default module's and application's messages. Example for admin module, (*22)

[
 /** App config **/
 'components' => [
  'i18n' => [
      'translations' => [
          '*' => ['class' => 'yii\i18n\PhpMessageSource'],
          'admin' => ['class' => 'nullref\core\components\i18n\PhpMessageSource'],
      ],
  ],
 ]
]

In this case messages from category admin from application directory will be merged with default messages from module., (*23)

Modules migrations

Module contains MigrateController controller which allows work with migrations of modules., (*24)

e.g.:, (*25)

php yii core/module --moduleId=admin -- apply migrations for module with id admin, (*26)

Keep in mind: Migrations should have namespaces, (*27)

Also, is possible work with migrations off all modules:, (*28)

php yii core/module -- collect all possible places of migrations., (*29)

By default, migrations are looked for directory migrations in directory of module class., (*30)

If you want to override this behavior, you can implement IHasMigrateNamespace interface by module class., (*31)

EntityManager

Component for simple work with models, which have soft delete and typification., (*32)

Config:, (*33)

/** module config **/
'productManager' => [
    "class" => "nullref\\product\\components\\EntityManager",
    'hasImage' => false,
    'hasStatus' => false,
    'model' => [
        'class' => 'app\\models\\Product',
        'relations' => [
            'category' => 'nullref\\category\\behaviors\\HasCategory',
            'vendor' => 'app\\behaviors\\HasVendor',
        ],
    ],
    'searchModel' => 'app\\models\\ProductSearch',
],
/** ... **/

Available methods:, (*34)

  • createModel() - create new model
  • createSearchModel() - create new search model
  • findOne($condition) - find one model by condition
  • findAll($condition) - find all models by condition
  • find($condition = []) - create ActiveQuery with condition
  • getMap($index = 'id', $value = 'title', $condition = [], $asArray = true) - get key=>value array of model by condition
  • delete($model) - delete model
  • decorateQuery($query) decorate query by settings of entity manger

The Versions