Rechercher "create-project" - page 1 sur 3

  1. Strategy Dependency Injection - RedCat PHP Framework #classe ...
    https://redcatphp.com/strategy-dependency-injection#classes- ...
    ...Expander('B') object is used to tell Strategy to create an instance of 'B' in place of 'Iterator'. new Expander('B') can be read as 'An instance of B created by the Strategy'. The reason that ['substitutions' => ['iterator' => $di->create('B')]] is not used is that this creates a B object there and then. Using the Expander...
  2. Strategy Dependency Injection - RedCat PHP Framework #classe ...
    https://fr.redcatphp.com/strategy-dependency-injection#class ...
    ...Expander('B') object is used to tell Strategy to create an instance of 'B' in place of 'Iterator'. new Expander('B') can be read as 'An instance of B created by the Strategy'. The reason that ['substitutions' => ['iterator' => $di->create('B')]] is not used is that this creates a B object there and then. Using the Expander...
  3. Strategy Dependency Injection - RedCat PHP Framework #get-st ...
    https://redcatphp.com/strategy-dependency-injection#get-star ...
    ...Apply the rule to instances of PDO$di->addRule('PDO', $rule);//Now any time PDO is requested from Strategy, the same instance will be returned$pdo = $di->create('PDO');$pdo2 = $di->create('PDO');var_dump($pdo === $pdo2); //TRUE//And any class which asks for an instance of PDO will be given the same instance:class MyClass {    public $pdo;    function __construct(PDO $pdo) {        $this->pdo = $pdo;    }}$myobj = $di->create('MyClass');var_dump($pdo === $myobj->pdo); //TRUE         Here, both instances of...
  4. Strategy Dependency Injection - RedCat PHP Framework #get-st ...
    https://fr.redcatphp.com/strategy-dependency-injection#get-s ...
    ...Apply the rule to instances of PDO$di->addRule('PDO', $rule);//Now any time PDO is requested from Strategy, the same instance will be returned$pdo = $di->create('PDO');$pdo2 = $di->create('PDO');var_dump($pdo === $pdo2); //TRUE//And any class which asks for an instance of PDO will be given the same instance:class MyClass {    public $pdo;    function __construct(PDO $pdo) {        $this->pdo = $pdo;    }}$myobj = $di->create('MyClass');var_dump($pdo === $myobj->pdo); //TRUE         Here, both instances of...
  5. Strategy Dependency Injection - RedCat PHP Framework #config ...
    https://redcatphp.com/strategy-dependency-injection#config-r ...
    ...one tree but if another instance of the top level class is created, have a second instance of the tree. For instance, imagine a MVC triad where the model needs to be shared between the controller and view, but if another instance of the controller and view are created, they need a new instance of their model shared between them...
  6. Strategy Dependency Injection - RedCat PHP Framework #config ...
    https://fr.redcatphp.com/strategy-dependency-injection#confi ...
    ...one tree but if another instance of the top level class is created, have a second instance of the tree. For instance, imagine a MVC triad where the model needs to be shared between the controller and view, but if another instance of the controller and view are created, they need a new instance of their model shared between them...
  7. Strategy Dependency Injection - RedCat PHP Framework #scalab ...
    https://redcatphp.com/strategy-dependency-injection#scalabil ...
    ...that particular instance. For example: Here, the class needs an instance of B as well as a unique name. Strategy allows this: $a1 = $di->create('A', ['FirstA']);$a2 = $di->create('A', ['SecondA']);echo $a1->name; // "FirstA"echo $a2->name; // "SecondA"         The dependency of B is automatically resolved...
  8. Strategy Dependency Injection - RedCat PHP Framework #config ...
    https://redcatphp.com/strategy-dependency-injection#config-r ...
    ...method2', []]            ]        ];$di->addRule('A', $rule);$a = $di->create('A');         This will output: The methods defined in $rule['call'] will get called in the order of the supplied array. Practical example: PDO Here is a real world example for creating an instance of PDO. $rule = [    'construct' => ['mysql:host...
  9. Strategy Dependency Injection - RedCat PHP Framework #scalab ...
    https://fr.redcatphp.com/strategy-dependency-injection#scala ...
    ...that particular instance. For example: Here, the class needs an instance of B as well as a unique name. Strategy allows this: $a1 = $di->create('A', ['FirstA']);$a2 = $di->create('A', ['SecondA']);echo $a1->name; // "FirstA"echo $a2->name; // "SecondA"         The dependency of B is automatically resolved...
  10. Strategy Dependency Injection - RedCat PHP Framework #config ...
    https://fr.redcatphp.com/strategy-dependency-injection#confi ...
    ...method2', []]            ]        ];$di->addRule('A', $rule);$a = $di->create('A');         This will output: The methods defined in $rule['call'] will get called in the order of the supplied array. Practical example: PDO Here is a real world example for creating an instance of PDO. $rule = [    'construct' => ['mysql:host...
  11. Strategy Dependency Injection - RedCat PHP Framework #differ ...
    https://redcatphp.com/strategy-dependency-injection#differen ...
    3.2 Classes Instanciation $di->create('My\Class');RedCat\Strategy\Di::getInstance()->create('My\Class'); //global shared instance used via objectRedCat\Strategy\Di::make('My\Class'); //global shared instance used via static call        
  12. Strategy Dependency Injection - RedCat PHP Framework #mainta ...
    https://redcatphp.com/strategy-dependency-injection#maintain ...
    ...graph creation Which creates: A Object(    [b:A:private] => B Object        (            [c:B:private] => C Object                (                )            [d:B:private] => D Object                (                    [e:D:private] => E Object                        (                        )                )        ))         At its simplest level, this has removed a lot of the initialisation code that would otherwise be needed to create the object...
  13. Strategy Dependency Injection - RedCat PHP Framework #basic- ...
    https://redcatphp.com/strategy-dependency-injection#basic-us ...
    ...used to disable this behaviour: class A {}class B extends A {}//This time mark A as shared, but turn off rule inheritance$aRule = ['shared' => true, 'inherit' => false];$di->addRule('A', $rule);$bRule = $di->getRule('B');//Now, B won't be marked as shared as the rule applied to A is not inheritedvar_dump($bRule['shared']); //FALSE//And to test it:$b1 = $di->create('B');$b2 = $di->create('B');var_dump($b1 === $b2); //FALSE (they are not the same instance)        
  14. Strategy Dependency Injection - RedCat PHP Framework #basic- ...
    https://redcatphp.com/strategy-dependency-injection#basic-us ...
    ...addRule('A', $rule);$a = $di->create('A');         This is equivalent to: Constructor parameter order for dependencies does not matter: class A {    function __construct($foo, $bar, B $b) {    }}$rule = ['construct' => ['Foo', 'Bar']];$di->addRule('A', $rule);$a = $di->create('A')         Strategy is smart enough to work...
  15. Strategy Dependency Injection - RedCat PHP Framework #config ...
    https://redcatphp.com/strategy-dependency-injection#config-r ...
    6.5 Default rules Strategy also allows for a rule to apply to any object it creates by applying it to '*'. As it's impossible to name a class '*' in php this will not cause any compatibility issues. The default rule will apply to any object which isn't affected by another rule. The primary use for this is to...
Retour à l'accueil