Skip to content

Instantly share code, notes, and snippets.

@lividgreen
Created February 27, 2014 20:39
Show Gist options
  • Save lividgreen/9259070 to your computer and use it in GitHub Desktop.
Save lividgreen/9259070 to your computer and use it in GitHub Desktop.
<?php
/**
* @property-read DbConnection $db
* @di $db
*/
class BlaBla1 {
public function doIt() {
$this->db->query('SELECT NOW()');
}
}
class BlaBla2 {
/**
* @di
* @var DbConnection
*/
protected $db;
public function doIt() {
$this->db->query('SELECT NOW()');
}
}
@DavertMik
Copy link

<?php
class BlaBla implements DiInjected
{
   public $needs = ['db'];

  /**
   * @di
   * @var DbConnection
   */
   protected $db;

   // declared in interface
   function injectServices($services)
   { 
      foreach ($services as $name => $val) {
         if (isset($this->needs[$name]) $this->$name = $val;
      }
   }

}
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment