mkungla / standard-colors-php
0.9.7-RC3
2016-04-11 21:31 UTC
Requires
- php: >= 5.3
This package is not auto-updated.
Last update: 2020-01-24 16:08:09 UTC
README
这个库旨在简化您使用不同颜色标准的工作。
- 是mkungla/standard-colors的子模块
- 在父存储库下的问题跟踪: mkungla/standard-colors问题:
- 欢迎贡献。
独立的PHP库
尽管这个库是mkungla/standard-colors的子模块,但它是一个独立的库。 mkungla/standard-colors是父项目,用于为所有支持的编程语言设置标准,并在父存储库的langs/目录中找到。
安装和设置
- 使用Composer
$ composer require mkungla/standard-colors-php # You might want to check out minimum-stability of tags/releases! # If you want to install non-stable releases
然后您只需在项目中要求composers自动加载器。
require_once 'vendor'.DIRECTORY_SEPARATOR.'autoload.php'; use StandardColors\ColorSystems; // Load Standard Colors library $SC = new ColorSystems;
- 从源代码
$ git clone git@github.com:mkungla/standard-colors-php.git
当您使用源代码时,您必须要求包含的自动加载器。
require_once 'standard-colors-php'.DIRECTORY_SEPARATOR.'autoload.php'; use StandardColors\ColorSystems; // Load Standard Colors library $SC = new ColorSystems;
用法
- 获取和设置地区
如果颜色系统中某个颜色有名称,则可以从选定的地区获取该名称。默认地区是en_US
/** * Get supported locales * @return Array * ( * [0] => de_DE * [1] => en_US * [2] => es_ES * [3] => fr_FR * [4] => it_IT * [5] => nl_NL * ) */ $locales = $SC->getLocales(); // Set locale if(!$SC->setLocale('en_US')) die('Could not set locale, Locale not supported or check spelling!'."\n"); // Get current locale $current_locale = $SC->getLocale();
- 获取支持的颜色系统并初始化颜色系统在这些示例中,我们使用经典RAL系统(RAL)
/** * Get Suppored Color Systems * @return array * ( * [RAL] => Array * ( * [id] => RAL * [name] => Classic RAL System * [rev] => rev-1 * ) * ... *) */ $supported_color_systems = $SC->getSupportedColorSystems(); /** * Load Color System * * You don't have to load it explicitly since it will be loaded whenever you first call it. * @param string * RAL: Classic RAL System * FS-595: The Federal Standard color system * PMS: The Pantone Colour Matching System * BS: The British Standards */ if(!$SC->cs('RAL')) die("Could not load Classic RAL System"."\n");
- 从请求的颜色系统空间获取所有颜色对象
/** * Get array of color objects from color system * @return array of object StandardColors\objects\ColorObject * While iterating through array you can get access following public properties * Ex: key 1000 in RAl * [1000] => StandardColors\objects\ColorObject Object * ( * [ID] => RAL 1000 // Real color code * [KEY] => 1000 // KEY used in this library * [name] => Groenbeige // Name in selected locale if available * [red] => 214 // Color RGB red value * [green] => 199 // Color RGB green value * [blue] => 148 // Color RGB blue value * [hex] => #BEBD7F // Color HEX * [text_type] => dark // Foreground contrast type * [text_hex] => #000 // Foreground color HEX * [text_red] => 0 // Foreground RGB red * [text_green] => 0 // Foreground RGB green * [text_blue] => 0 // Foreground RGB blue * // CSS files can be found in dist directory * [css_fg_hex] => sc-ral-1000-fg-hex // Foreground css class using HEX * [css_fg_rgb] => sc-ral-1000-fg-rgb // Foreground css class using RGB * [css_bg_hex] => sc-ral-1000-bg-hex // Background css class using HEX * [css_bg_rgb] => sc-ral-1000-bg-rgb // Background css class using RGB * ) */ $all_colors_in_ral = $SC->cs('RAL')->getAll(); if(!$all_colors_in_ral) die('Failed to get data for Classic RAL System.'."\n");
- 通过库键获取单个颜色对象
$color = $SC->cs('RAL')->color(1000); if(!$color) die('Could not find requested color.'."\n");
HTML文档
HTML文档$SC->cs('RAL')->html()用于为颜色系统渲染不同的HTML元素。
HTML选择
配置和获取颜色系统的选择框。
/** * Set id attribute for select element * bool false: disabled * bool true: CS-RAL (CS- perfixed short colorsytem name) */ $SC->cs('RAL')->html()->select()->id(true); /** * Set name attribute for select element * bool false: disabled * bool true: Color Sytem name, whitespaces replaced with dash perfixed CS-, * string: custom name attribute */ $SC->cs('RAL')->html()->select()->name(true); /** * Set colors to be used * bool false: all (default) * array of color keys: ex: array('1000','2000') etc */ $SC->cs('RAL')->html()->select()->colors(false); /** * Add css class(es) to select element * bool false: none (default) * string css classes */ $SC->cs('RAL')->html()->select()->css('custom-css-class custom-css-class2'); // Add autofocus attribute (default false) $SC->cs('RAL')->html()->select()->autofocus(true); // Add disabled attribute (default false) $SC->cs('RAL')->html()->select()->disabled(true); // Add multiple attribute (default false) $SC->cs('RAL')->html()->select()->multiple(true); // Add required attribute (default false) $SC->cs('RAL')->html()->select()->required(true); // Add and set size attribute (int) - (default false) $SC->cs('RAL')->html()->select()->size(10); // Add any other attributes by key value ex: $SC->cs('RAL')->html()->select()->attr('data-id','custom-id'); $SC->cs('RAL')->html()->select()->attr('data-name','custom-name');
HTML选择选项
设置选择选项的文本值,您可以使用与自定义文本混合的标签
| 标签 | 描述 |
|---|---|
{ID} |
颜色真实ID |
{IDD} |
颜色真实ID,其中空白被替换为- |
{KEY} |
颜色ID(键),在库中使用 |
{NAME} |
如果当前地区可用,则颜色名称 |
// Option css classes 1-bool: add background class 2-bool: Add foreground class 3-string: add custom class $SC->cs('RAL')->html()->select()->option()->css(true,true,'custom-option-class'); // Add label attribute $SC->cs('RAL')->html()->select()->option()->label('{KEY} - {NAME}'); // Add value attribute $SC->cs('RAL')->html()->select()->option()->value('{IDD}'); // Add option text $SC->cs('RAL')->html()->select()->option()->text('{ID} - {NAME}'); // Set array of color keys which options are listed but disabled $SC->cs('RAL')->html()->select()->option()->disabled(array(1000,1001)); // Set which color by key is selected by default. Default non of the option have selected attribute $SC->cs('RAL')->html()->select()->option()->selected('1002'); // Add other attributes for option element Ex: $SC->cs('RAL')->html()->select()->option()->attr('data-id','{IDD}'); $SC->cs('RAL')->html()->select()->option()->attr('data-name','{NAME}'); $SC->cs('RAL')->html()->select()->option()->attr('data-description','Color ID: {ID} key is {KEY} and name is {NAME}. Id whithout whitespaces is {IDD}');
HTML选择渲染
// @param bool false (default) use HEX colors for disblay, bool true uses RGB colors for display $select_element = $SC->cs('RAL')->html()->select()->render(true);