PHP code example of patienceman / deper

1. Go to this page and download the library: Download patienceman/deper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

patienceman / deper example snippets

 
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()
        ];
    }
}
 
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();
    }
}
 
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";
    }
}
 
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";
    }
}