ilyaplot/containers

此包已被废弃,不再维护。未建议替代包。

简单的容器包

0.0.5 2017-06-19 11:30 UTC

This package is not auto-updated.

Last update: 2023-05-30 08:19:40 UTC


README

GitHub tag Packagist Packagist GitHub issues

安装

安装此扩展的首选方式是通过 Composer。只需运行

php composer.phar require --prefer-dist ilyaplot/containers

或者将以下内容添加到你的 composer.json 文件的 require 部分:

"ilyaplot/containers": "*"

to the require section of your composer.json file.

使用示例:容器

$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}

使用示例:配置

文件:config.php

<?php 
  return ['hostname' => '127.0.0.1', 'username' => 'guest'];

使用

// 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.