tixelrocks/class-constants-helper
Composer 安装命令:
composer require tixelrocks/class-constants-helper
包简介
A tiny package that makes working with PHP class constants easier
关键字:
README 文档
README
A tiny package that makes working with PHP class constants easier
Have you ever noticed yourself doing stuff like this:
<?php class Artist { const ARTIST_TYPE_MUSICIAN = 0; const ARTIST_TYPE_COMEDIAN = 1; const ARTIST_TYPE_MAGICIAN = 2; }
And then somewhere later, maybe in the views:
<select> <option value="{{ Artist::ARTIST_TYPE_MUSICIAN }}">Musician</option> <option value="{{ Artist::ARTIST_TYPE_COMEDIAN }}">Comedian</option> <option value="{{ Artist::ARTIST_TYPE_MAGICIAN }}">Magician</option> </select>
Now, wouldn't you want to just iterate through them instead? They all have the same prefix after all. This package does exactly that:
$ composer require tixelrocks/class-constants-helper
Now you have a new helper function constants() loaded through composer's auto-load. We can simplify our select input now:
<select> @foreach (constants(Artist::class, 'ARTIST_TYPE') as $value) <option value="{{ $value }}">{{ $value }}</option> @endforeach </select>
统计信息
- 总下载量: 9.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-13