PHP code example of atekushi / singleton
1. Go to this page and download the library: Download atekushi/singleton 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/ */
atekushi / singleton example snippets
use Atekushi\Singleton\Singleton;
class Config extends Singleton
{
private array $settings;
protected function __construct(array $settings = [])
{
$this->settings = $settings;
}
public function get(string $key, $default = null)
{
return $this->settings[$key] ?? $default;
}
}
// Usage
$config = Config::getInstance(['app_name' => 'MyApp', 'debug' => true]);
echo $config->get('app_name');