@@ -257,6 +257,10 @@ $myObj = $injector->make('MyClass');
257257var_dump($myObj instanceof MyClass); // true
258258```
259259
260+ > ** NOTE:** Since this ` define() ` call is passing raw values (as evidenced by the colon ` : ` usage),
261+ you can achieve the same result by omitting the array key(s) and relying on parameter order rather
262+ than name. Like so: ` $injector->define('MyClass', [$dependencyInstance]); `
263+
260264###### Specifying Injection Definitions On the Fly
261265
262266You may also specify injection definitions at call-time with ` Auryn\Injector::make ` . Consider:
@@ -329,12 +333,12 @@ on type-hints, class name definitions and existing instances. But what happens i
329333a scalar or other non-object variable into a class? First, let's establish the following behavioral
330334rule:
331335
332- > ** IMPORTANT:** The Injector assumes all injection definitions are class names by default.
336+ > ** IMPORTANT:** The Injector assumes all named-parameter definitions are class names by default.
333337
334- If you want the Injector to treat a parameter definition as a "raw" value and not a class name, you
335- must prefix the parameter name in your definition with a colon character ` : ` . For example, consider
336- the following code in which we tell the Injector to share a ` PDO ` database connection instance and
337- define its scalar constructor parameters:
338+ If you want the Injector to treat a named- parameter definition as a "raw" value and not a class name,
339+ you must prefix the parameter name in your definition with a colon character ` : ` . For example,
340+ consider the following code in which we tell the Injector to share a ` PDO ` database connection
341+ instance and define its scalar constructor parameters:
338342
339343``` php
340344<?php
@@ -356,11 +360,17 @@ easily specified arrays or integers or any other data type in the above definiti
356360parameter name is prefixed with a ` : ` , Auryn will inject the value directly without attempting to
357361instantiate it.
358362
363+ > ** NOTE:** As mentioned previously, since this ` define() ` call is passing raw values, you may opt to
364+ assign the values by parameter order rather than name. Since PDO's first three parameters are ` $dsn ` ,
365+ ` $username ` , and ` $password ` , in that order, you could accomplish the same result by leaving out the
366+ array keys, like so:
367+ ` $injector->define('PDO', ['mysql:dbname=testdb;host=127.0.0.1', 'dbuser', 'dbpass']); `
368+
359369### Global Parameter Definitions
360370
361371Sometimes applications may reuse the same value everywhere. However, it can be a hassle to manually
362372specify definitions for this sort of thing everywhere it might be used in the app. Auryn mitigates
363- this problem by exposing the ` Injector::bindParam () ` method. Consider the following example ...
373+ this problem by exposing the ` Injector::defineParam () ` method. Consider the following example ...
364374
365375``` php
366376<?php
@@ -374,7 +384,7 @@ class MyClass {
374384}
375385
376386$injector = new Auryn\Injector;
377- $injector->bindParam ('myValue', $myUniversalValue);
387+ $injector->defineParam ('myValue', $myUniversalValue);
378388$obj = $injector->make('MyClass');
379389var_dump($obj->myValue === 42); // bool(true)
380390```
@@ -460,27 +470,15 @@ var_dump($person === $anotherPerson); // bool(true) because it's the same instan
460470
461471Defining an object as shared will store the provisioned instance in the Injector's shared cache and
462472all future requests to the provider for an injected instance of that class will return the
463- originally created object (unless you manually clear it from the cache) . Note that in the above code
464- we shared the class name ( ` Person ` ) instead of an actual instance. Sharing works with either a class
465- name or an instance of a class. The difference is that when you specify a class name the Injector
473+ originally created object. Note that in the above code, we shared the class name ( ` Person ` )
474+ instead of an actual instance. Sharing works with either a class name or an instance of a class.
475+ The difference is that when you specify a class name, the Injector
466476will cache the shared instance the first time it is asked to create it.
467477
468478> ** NOTE:** Once the Injector caches a shared instance, call-time definitions passed to
469479` Auryn\Injector::make ` will have no effect. Once shared, an instance will always be returned for
470480instantiations of its type until the object is un-shared or refreshed:
471481
472- ``` php
473- <?php
474- // Clears shared instance from the Injector cache and unshares future StdClass instantiations
475- $injector->unshare('StdClass');
476-
477- // Clears any currently shared StdClass instance, but maintains its status as a shared class.
478- // A new StdClass will be created and cached the next time the Injector is asked to instantiate
479- // an instance of StdClass.
480- $injector->refresh('StdClass');
481- ```
482-
483-
484482### Instantiation Delegates
485483
486484Often factory classes/methods are used to prepare an object for use after instantiation. Auryn
0 commit comments