PHP code example of stellarwp / foundation-container

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

    

stellarwp / foundation-container example snippets


 declare(strict_types=1);

namespace My\App;

use lucatume\DI52\Container;
use StellarWP\Foundation\Container\ContainerAdapter;

// Optionally, use the included vlucas/phpdotenv to load environment variables before the container.
$path = __DIR__;

if ( file_exists( $path . '/.env' )  ) {
    $dotenv = Dotenv::createImmutable( $path );
    $dotenv->load();
}

// This implements the Contracts/Container.php interface.
$container = new ContainerAdapter(new Container());

// Bind the concrete to the interface, so anytime we ask for a container we get this one.
$container->bind(Container::class, $container);

// Register our project's configuration. See "Making a config.php" below for more detail.
$container->bind(Dot::class, new Dot(

 declare(strict_types=1);

namespace StellarWP\YourProject\Client;

use lucatume\DI52\ContainerException;
use StellarWP\Foundation\Container\Contracts\Provider;
use StellarWP\Foundation\Storage\Contracts\Storage;
use StellarWP\Foundation\Storage\Drivers\LocalStorage;

final class ServiceProvider extends Provider
{
	/**
	 * @throws ContainerException
	 */
	public function register(): void {
		$this->container->bind(Storage::class, LocalStorage::class);
		$this->container->when(LocalStorage::class)
						->needs('$storagePath')
						->give($this->config->get('storage_path'));
	}
}

 declare(strict_types=1);

return [
	'some_key'    => $_ENV['SOME_KEY'] ?? '',
	'log'             => [
		'level'    => $_ENV['LOG_LEVEL'] ?? 'debug',
		'channel'  => $_ENV['LOG_CHANNEL'] ?? 'null',
		'channels' => [
			'errorlog' => [],
			'console'  => [
				'with' => [
					'stream' => 'php://stdout',
				],
			],
		],
	],
];

// Get the console log stream type from config.php.
$stream = $this->config->get('log.channels.console.with.stream');

// Get the log level.
$level = $this->config->get('log.level');

// Inside wp-config.php

// App configuration.
$_ENV['SOME_KEY'] = 'abcd-1234'; 
$_ENV['LOG_LEVEL'] = 'info';
$_ENV['LOG_CHANNEL'] = 'errorlog';