PHP code example of aatis / dependency-injection

1. Go to this page and download the library: Download aatis/dependency-injection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aatis / dependency-injection example snippets


(new ContainerBuilder($ctx))->build();

public function __construct(string $_my_env_var)
{
    // ...
}

// Env Variable
$container->get('APP_ENV_VAR_NAME');
$container->set('APP_ENV_VAR_NAME', 'value');

// Service
$container->get('Namespace\To\The\Service');

$service = $container->get(ServiceFactory::class)->create('Namespace\To\The\Service');
$container->set('Namespace\To\The\Service', $service);

$container->getByTag('tag_name');
$container->getByTags(['tag_name1', 'tag_name2']);

$container->getByTag('tag_name', true);
$container->getByTags(['tag_name1', 'tag_name2'], true);

$container->getByInterface('Namespace\To\The\Interface');
$container->getByInterfaces(['Namespace\To\The\Interface1', 'Namespace\To\The\Interface2']);

$container->getByInterface('Namespace\To\The\Interface', true);
$container->getByInterfaces(['Namespace\To\The\Interface1', 'Namespace\To\The\Interface2'], true);
yaml
# In config/services.yaml file :

exclude_paths:
  - '/Folder'
  - '/OtherFolder/file.txt'
  - <...>