aklump/default-value
最新稳定版本:0.0.6
Composer 安装命令:
composer require aklump/default-value
包简介
Calculates the default value based on variable type, including fully-qualified classnames.
README 文档
README
A small utility to return a default value or instance based on a variable type or classname.
Vanilla PHP
<?php $variable_types = [ 'array', 'bool', 'boolean', 'double', 'float', 'int', 'integer', 'null', 'number', 'object', 'string', // In addition you can pass fully-qualified class names, so long as their // constructors do not REQUIRE any parameters. '\Foo\Bar\Baz', ]; foreach ($variable_types as $variable_type) { $default_value = \AKlump\DefaultValue\DefaultValue::get($variable_type); }
Drupal 8+ Integration
When using within a Drupal installation use the
class \Drupal\Component\Utility\DefaultValue and you'll get special Drupal
support, in addition to the vanilla PHP explained above.
<?php $special_drupal_variable_types = [ // This is a service ID. '@current_user', // This class has a ::create method with no required arguments. '\Drupal\user\Entity\User', // This class implements ContainerInjectionInterface. '\Drupal\system\Controller\CsrfTokenController', ]; foreach ($special_drupal_variable_types as $variable_type) { $default_value = \Drupal\Component\Utility\DefaultValue::get($variable_type); }
统计信息
- 总下载量: 232
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2021-03-27