PHP code example of robert430404 / rc-container

1. Go to this page and download the library: Download robert430404/rc-container 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/ */

    

robert430404 / rc-container example snippets




use RcContainer\Container;

ontainer->registerParameter('test-parameter', function () {
    return 'this-is-the-test-param';
});

$container->registerService('test-service', function () {
    return new stdClass();
});

$container->registerFactory('test-factory', function () {
    return new stdClass();
});



use RcContainer\Container;

ontainer->registerServices([
    'test-service-1' => function () {
        return new stdClass();
    },
    'test-service-2' => function () {
        return new stdClass();
    }
]);

$container->registerParameters([
    'test-parameter-1' => function () {
        return 'parameter variable';
    },
    'test-parameter-2' => function () {
        return 'second parameter variable';
    }
]);

$container->registerFactories([
    'test-factory-1' => function () {
        return new stdClass();
    },
    'test-factory-2' => function () {
        return new stdClass();
    }
]);



use RcContainer\Container;

ontainer->registerServices([
    'test-service-1' => 'stdClass',
    'test-service-2' => 'stdClass'
]);

$container->registerParameters([
    'test-parameter-1' => 'parameter variable',
    'test-parameter-2' => 'second parameter variable'
]);

$container->registerFactories([
    'test-factory-1' => 'stdClass',
    'test-factory-2' => 'stdClass'
]);



$container->parameter('test-parameter'); // Returns your param
$container->service('test-service'); // Returns the service (Same Instance)
$container->factory('test-factory'); // Returns the factory's object (New Instance)



use RcContainer\Container;
use Vendor\SDKObject; // Made Up Namespace

api-key', function () {
    return '000-000-000-000-0000';
});

// Services
$container->registerService('the-api', function () use ($container) {
    $apiKey = $container->parameter('api-key'); // Retrieves Registered Key
    
    return new SDKObject($apiKey); // Made Up Object
});



use RcContainer\Container;
use Vendor\SDKObject; // Made Up Namespace
use Vendor\DataFactory; // Made Up Namespace

00-000-0000';
});

// Services
$container->registerService('the-api', function () use ($container) {
    $apiKey = $container->parameter('api-key'); // Retrieves Registered Key
    
    return new SDKObject($apiKey); // Made Up Object
});

// Factories
$container->registerFactory('data-factory', function () use ($container) {
    $apiSdk = $container->service('the-api');
    
    return new DataFactory($apiSdk);
});