patienceman/deper 问题修复 & 功能扩展

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

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

patienceman/deper

最新稳定版本:v1.0.2

Composer 安装命令:

composer require patienceman/deper

包简介

One line Dependencies Injections for laravel and php

README 文档

README

Deper is a dependency injector, which is able to inject even more than 4 classes in a simple way and is reliable, So now we are able to use multiple classes functions at once, 💯 🎆

Installation

Installing the package doesn't require much requirement except to paste the following command in the laravel terminal, and you're good to go.

composer require patienceman/deper

Usage

It is easy to deal with this package, however, when you start to inject heavy classes, like thousand functions, it will take a while to find your function, and adds up to API / execution time. So once the installation is done! you need to create a new class file! for example

namespace App\Dependencies;

use Patienceman\Deper\Dependencies;

class PatientDependencies extends Dependencies {
    /**
     * Class constructor.
     */
    public function __construct() {
        return $this->boot();
    }

    /**
     * Resources to be injected
     *
     * @return array
     */
    public function injections(): array {
        return [
            \App\Services\Mood::class, // or new Mood()
            \App\Services\Energy::class, // or new Energy()
            \App\Actions\Move::class // or new Move()
        ];
    }
}

You can apply even to many classes to be injected, Just put it inside the injection return array. So now on let's use our dependencies anywhere we want!

namespace App\Http\Controllers;

use App\Dependencies\PatientDependencies;
use Illuminate\Http\Request;

class TestController extends Controller {
    /**
     * Store a newly created resource in storage.
     *
     * @param PatientDependencies $dependency
     * @return \Illuminate\Http\Response
     */
    public function store(PatientDependencies $dependency) {
       return $dependency->mood(); // or $dependency->energy();
    }
}

Woow 😄 ⭐ 🌟 , that amazing step forward we made! See!, easy-peasy!

class inheritance

So now that was the easy step to use!, let see how the inheritance work for dependencies!, Note: we will use the above example

namespace App\Services;

use App\Dependencies\PatientDependencies;

class Human extends PatientDependencies {
    /**
     * Class constructor.
     */
    public function __construct() {
        parent::__construct();
    }

   /**
     * Possess a new spirit
     *
     * @return string
     */
    public function Spirit () {
        $this->mood();
        $this->energy();
        return "spirit created and possessed successfully";
    }
}

That was awesome right? 👍 🤙 🚑

Let use trait

So now on let's use traits to make it easier, Note: with current example

namespace App\Services;

use Patienceman\Deper\Injectable;

class Human {
    use Injectable;

    protected $dependencies = [
         \App\Services\Mood::class, // or new Mood()
         \App\Services\Energy::class, // or new Energy()
         \App\Actions\Move::class // or new Move()
    ];

    /**
     * Class constructor.
     */
    public function __construct() {
        $this->inject($this->dependencies);
    }

   /**
     * Possess a new spirit
     *
     * @return string
     */
    public function Spirit () {
        $this->mood();
        $this->energy();
        return "spirit created and possessed successfully";
    }
}

This is so amazing! 💯 😄

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固