2017 © Pedro Peláez
 

yii2-extension yii2-services

Extension provide very simply use services for models and controllers

image

matthew-p/yii2-services

Extension provide very simply use services for models and controllers

  • Monday, June 25, 2018
  • by hellboymxb@gmail.com
  • Repository
  • 1 Watchers
  • 1 Stars
  • 212 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 91 % Grown

The README.md

yii2-services

Extension provide very simply use services for models and controllers, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist matthew-p/yii2-services "*"

or add, (*4)

"matthew-p/yii2-services": "*"

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

Usage

Once the extension is installed, simply use it in your code by:, (*6)

Create service for model (must implement IService or extend any of services in MP\Services):, (*7)

use MP\Services\BaseModelService;

/**
 * ...
 *
 * @property SampleModel $model
 */
class MyCustomService extends BaseModelService
{
    /**
     * My simple method
     *
     * @return array
     */
    public function getSampleMethod(): array
    {
        return [];
    }
}

Create model:, (*8)

...

use MP\Services\ImplementServices;

/**
 * Use services in model
 * ...
 *
 * Services
 * @property MyCustomService $customService
 */
class SampleModel extends ActiveRecord
{
    use ImplementServices;

    /**
     * @inheritdoc
     */
    public static function services(): array
    {
        return [
            'customService' => MyCustomService::class,
        ];
    }

    ...
}

And use:, (*9)

$model = new SampleModel();
$model->customService->getSampleMethod();

For controllers, everything is the same, only the service is inherited from BaseControllerService, (*10)

Tests

Run tests with command:, (*11)

./vendor/bin/phpunit

The Versions

25/06 2018

dev-master

9999999-dev

Extension provide very simply use services for models and controllers

  Sources   Download

MIT

The Requires

 

by Matthew Patell

services extension yii2 model controller

25/06 2018

2.0

2.0.0.0

Extension provide very simply use services for models and controllers

  Sources   Download

MIT

The Requires

 

by Matthew Patell

services extension yii2 model controller

12/03 2018

1.2

1.2.0.0

Extension provide very simply use services for models and controllers

  Sources   Download

MIT

The Requires

 

by Matthew Patell

services extension yii2 model controller

05/03 2018

1.1

1.1.0.0

Extension provide very simply use services for models and controllers

  Sources   Download

MIT

The Requires

 

by Matthew Patell

services extension yii2 model controller

22/02 2018

1.0

1.0.0.0

Extension provide very simply use services for models and controllers

  Sources   Download

MIT

The Requires

 

by Matthew Patell

services extension yii2 model controller