Containers extensions
, (*1)
Installation
The preferred way to install this extension is through composer. Just run, (*2)
php composer.phar require --prefer-dist ilyaplot/containers
or add, (*3)
"ilyaplot/containers": "*"
to the require section of your composer.json file., (*4)
Usage Container exaple:
$container = new \ilyaplot\Container(['value' => 100]);
$container->value1 = 200;
echo $container->value; // 100
echo $container->value1; // 200
echo $container['value1']; // 200
foreach ($container as $key=>$value) {
echo $key . ':' . $value; // value:100 and value1:200
}
echo count($container); // 2
echo (string) $container; // {"value":100, "value2":200}
Usage Config exaple:
File: config.php:, (*5)
<?php
return ['hostname' => '127.0.0.1', 'username' => 'guest'];
Usage:, (*6)
// Example config.php:
$config = new \ilyaplot\Config('config.php', ['password' => 'qwe123', 'username' => 'admin']);
echo $config->hostname; // 127.0.0.1
echo $config->password; // qwe123
echo $config->username; // guest
echo count($config); // 3
$config = new \ilyaplot\Config('config.php', [], ['required_param']);
// throws ContainerException with message: Required param(s) "required_param" has not been set.