php - Constructor Injection in Restler -


is possible pass along arguments api class sake of constructor injection? example, in index.php have following:

$r->addapiclass('contacts', ''); 

and contacts.php looks this:

class contacts {     private $v;      public function __construct(validation v)     {         $this->v = v;     } } 

how restler?

restler 3 rc5 has dependency injection container called scope responsible creating new instances of class name, comes in handy purpose.

once register contacts class dependency using register method, lazy instantiated when asked for

<?php include '../vendor/autoload.php';  use luracast\restler\scope; use luracast\restler\restler;  scope::register('contacts', function () {     return new contacts(scope::get('validation')); });  $r = new restler(); $r->addapiclass('contacts', ''); $r->handle(); 

by using scope::get('validation') can register validation if has dependencies


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -