Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>there are number of options how to resolve dependencies problem (object A requires object B):</p> <p>constructor injection</p> <pre><code> class Sms { function __construct($db) .... } $sms = new Sms (new MyDbClass); </code></pre> <p>setter injection</p> <pre><code> class Sms { protected $db; } $sms = new Sms; $sms-&gt;db = new MyDbClass; </code></pre> <p>'registry' pattern</p> <pre><code> class Registry { static function get_db() { return new MyDbClass; }} class Sms { function doSomething() { $db = Registry::get_db(); $db-&gt;.... }} </code></pre> <p>'service locator' pattern</p> <pre><code> class Loader { function get_db() { return new MyDbClass; }} class Sms { function __construct($loader) { $this-&gt;loader = $loader; function doSomething() { $db = $this-&gt;loader-&gt;get_db(); $db-&gt;.... }} $sms = new Sms(new Loader); </code></pre> <p>automated container-based dependency injection, see for example <a href="http://www.sitepoint.com/blogs/2009/05/11/bucket-is-a-minimal-dependency-injection-container-for-php" rel="nofollow noreferrer">http://www.sitepoint.com/blogs/2009/05/11/bucket-is-a-minimal-dependency-injection-container-for-php</a></p> <pre><code> interface DataSource {...} class MyDb implements DataSource {...} class Sms { function __construct(DataSource $ds) .... $di = new Dependecy_Container; $di-&gt;register('DataSource', 'MyDb'); $sms = $di-&gt;get('Sms'); </code></pre> <p>to name a few ;)</p> <p>also the Fowler's article i gave you before is really worth reading</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload