本文整理汇总了PHP中lithium\util\Set类的典型用法代码示例。如果您正苦于以下问题:PHP Set类的具体用法?PHP Set怎么用?PHP Set使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Set类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* returns rendered content
*
* @param string $content input content
* @param string $data field to retrieve from configuration
* @param array $options an array with additional options
* @return string content as given
* @filter
*/
public function get($content, $data = null, array $options = array())
{
$defaults = array('default' => null, 'flat' => false);
$options += $defaults;
$params = compact('content', 'data', 'options');
return $this->_filter(__METHOD__, $params, function ($self, $params) {
extract($params);
try {
$config = IniFormat::parse($content);
} catch (IniFormatException $e) {
return $options['default'];
} catch (Exception $e) {
return $options['default'];
}
if (empty($data)) {
return $options['flat'] ? Set::flatten($config) : $config;
}
if (is_scalar($data) && isset($config[$data])) {
return $config[$data];
}
$data = '/' . str_replace('.', '/', (string) $data) . '/.';
$result = current(Set::extract((array) $config, $data));
if (!empty($result)) {
return $result;
}
return $options['default'];
});
}
示例2: parse
/**
* parses an ini-style string into an array
*
* when entering data into ini-style input fields, make sure, that you comply with the following
* rules (read up on http://php.net/parse_ini_string):
*
* There are reserved words which must not be used as keys for ini files. These include:
*
* `null`, `yes`, `no`, `true`, `false`, `on`, `off` and `none`
*
* Values `null`, `no` and `false` results in "", `yes` and `true` results in "1".
* Characters ?{}|&~![()^" must not be used anywhere in the key and have a special meaning
* in the value. So better not use them.
*
* @see http://php.net/parse_ini_string
* @see lithium\util\Set::expand()
* @param string|array $data the string to be parsed, or an array thereof
* @param array $options an array of options currently supported are
* - `default` : what to return, if nothing is found, defaults to an empty array
* - `process_sections` : to enable process_sections, defaults to true
* - `scanner_mode` : set scanner_mode to something different than INI_SCANNER_NORMAL
* @return array an associative, eventually multidimensional array or the `default` option.
*/
public static function parse($data = null, array $options = array())
{
$defaults = array('default' => array(), 'scanner_mode' => INI_SCANNER_NORMAL, 'process_sections' => true);
$options += $defaults;
if (empty($data)) {
return $options['default'];
}
if (is_array($data)) {
foreach ($data as $key => $value) {
$data[$key] = static::parse($value, $options);
}
return $data;
}
$raw = parse_ini_string(static::filter($data), $options['process_sections'], $options['scanner_mode']);
if (empty($raw)) {
return $options['default'];
}
try {
$result = Set::expand($raw);
} catch (Exception $e) {
$error = $e->getMessage();
$e = new IniFormatException(sprintf('IniFormat Error: %s', $error));
$e->setData(compact('data', 'raw', 'options'));
throw $e;
}
return $result;
}
示例3: __invoke
/**
* Magic method to make Controller callable.
*
* @see lithium\action\Dispatcher::_callable()
* @param \lithium\action\Request $request
* @param array $dispatchParams Array of params after being parsed by router.
* @param array $options Some basic options for this controller.
* @return string
* @filter
*/
public function __invoke($request, $dispatchParams, array $options = array())
{
$dispatchParamsDefaults = array('args' => array());
$dispatchParams += $dispatchParamsDefaults;
$defaults = array('format' => 'html', 'timeout' => 0);
$options += (array) $request->query + $defaults;
$params = compact('request', 'dispatchParams', 'options');
return $this->_filter(__METHOD__, $params, function ($self, $params) {
$request = $params['request'];
$options = $params['options'];
$params = $params['dispatchParams'];
set_time_limit((int) $options['timeout']);
$group = join('\\', (array) $params['args']);
if ($group === "all") {
$group = Group::all();
$options['title'] = 'All Tests';
}
$self->invokeMethod('_saveCtrlContext');
$report = Dispatcher::run($group, $options);
$self->invokeMethod('_restoreCtrlContext');
$filters = Libraries::locate('test.filter');
$menu = Libraries::locate('tests', null, array('filter' => '/cases|integration|functional/', 'exclude' => '/mocks/'));
sort($menu);
$menu = Set::expand(array_combine($menu, $menu), array('separator' => "\\"));
$result = compact('request', 'report', 'filters', 'menu');
return $report->render('layout', $result);
});
}
示例4: get
/**
* returns rendered content
*
* @param string $content input content
* @param string $data field to retrieve from configuration
* @param array $options an array with additional options
* @return string content as given
* @filter
*/
public function get($content, $data = null, array $options = array())
{
$defaults = array('default' => array(), 'flat' => false);
$options += $defaults;
$params = compact('content', 'data', 'options');
return $this->_filter(__METHOD__, $params, function ($self, $params) {
extract($params);
try {
$config = NeonFormatter::decode($content);
} catch (NeonException $e) {
return $options['default'];
} catch (Exception $e) {
return $options['default'];
}
if (!empty($data) && is_scalar($data)) {
if (array_key_exists($data, (array) $config)) {
return $config[$data];
}
}
if ($data) {
$data = '/' . str_replace('.', '/', $data) . '/.';
$result = current(Set::extract((array) $config, $data));
return !empty($result) ? $result : null;
}
return $options['flat'] ? Set::flatten($config) : $config;
});
}
示例5: find
public static function find(array $options = array())
{
$defaults = array('collect' => true);
$options += $defaults;
$data = array();
$libs = Libraries::get(null, 'path');
$recursive = true;
foreach ($libs as $lib => $path) {
$result = array();
$path .= '/views/widgets';
$files = StaticContents::available(compact('path', 'recursive'));
if (!$files) {
continue;
}
$temp = array_keys(Set::flatten($files, array('separator' => '/')));
foreach ($temp as $key => $value) {
if (strpos($value, 'admin.') !== false) {
continue;
}
if (strpos($value, 'inc.') !== false) {
continue;
}
$result[$key] = str_replace('.html.php', '', $value);
}
$data[$lib] = $result;
}
return $data;
}
示例6: __construct
/**
* Object constructor.
* Instantiates the Memcached object, adds appropriate servers to the pool,
* and configures any optional settings passed.
*
* @see lithium\storage\Cache::config()
* @param array $config Configuration parameters for this cache adapter.
* These settings are indexed by name and queryable
* through `Cache::config('name')`.
* @return void
*/
public function __construct(array $config = array())
{
$defaults = array('prefix' => '', 'expiry' => '+1 hour', 'servers' => array(array('127.0.0.1', 11211, 100)));
if (is_null(static::$connection)) {
static::$connection = new \Memcached();
}
$configuration = Set::merge($defaults, $config);
parent::__construct($configuration);
static::$connection->addServers($this->_config['servers']);
}
示例7: testArrayConfiguration
public function testArrayConfiguration()
{
$result = Configurations::create(Set::merge($this->_default, array('type' => 'array', 'value' => 'foo=bar')));
$this->assertEqual(array('foo' => 'bar'), $result->val());
$this->assertEqual('bar', $result->val('foo'));
$result = Configurations::create(Set::merge($this->_default, array('type' => 'array', 'value' => "foo.bar=baz\nfoo.baz=bar")));
$this->assertEqual(array('foo' => array('bar' => 'baz', 'baz' => 'bar')), $result->val());
$this->assertEqual(array('bar' => 'baz', 'baz' => 'bar'), $result->val('foo'));
$this->assertEqual('baz', $result->val('foo.bar'));
}
示例8: data
/**
* Parses an associative array into an array, containing one
* array for each row, that has 'key' and 'value' filled
* as expected. That makes rendering of arbitrary meta-data
* much simpler, e.g. if you do not know, what data you are
* about to retrieve.
*
* @param array $data an associative array containing mixed data
* @return array an numerical indexed array with arrays for each
* item in $data, having 'key' and 'value' set accordingly
*/
public function data(array $data = array(), array $options = array())
{
$defaults = array('flatten' => true);
$options += $defaults;
if ($options['flatten']) {
$data = Set::flatten($this->_extract($data));
}
return array_map(function ($key, $value) {
return compact('key', 'value');
}, array_keys($data), $data);
}
示例9: _init
/**
* Initializes the record set and uses the database connection to get the column list contained
* in the query that created this object.
*
* @see lithium\data\collection\RecordSet::$_columns
* @return void
* @todo The part that uses _handle->schema() should be rewritten so that the column list
* is coming from the query object.
*/
protected function _init()
{
parent::_init();
if ($this->_result) {
$this->_columns = $this->_columnMap();
if ($this->_query) {
$columns = array_filter(array_keys($this->_columns));
$this->_dependencies = Set::expand(Set::normalize($columns));
$this->_keyIndex = $this->_keyIndex('');
}
}
}
示例10: connections
public function connections()
{
$data = Connections::get();
$connections = new Collection(compact('data'));
if (true || $this->request->is('json')) {
$connections->each(function ($name) {
$config = Connections::get($name, array('config' => true));
unset($config['object']);
return array_merge(compact('name'), Set::flatten($config));
});
}
return compact('connections');
}
示例11: _recaptchaOptions
/**
* Create `RecaptchaOptions` javascript object if you have additional options configured
* @param array $options `'key' => 'value'` pairs to be converted to javascript
* object as `RecaptchaOptions`
* @see https://developers.google.com/recaptcha/docs/customization
* @return null|string Return null if you don't have additional options
* or script with `RecaptchaOptions` object
*/
protected function _recaptchaOptions(array $options = array())
{
$defaults = Libraries::get('li3_recaptcha', 'options');
if ($defaults) {
$options = Set::merge($defaults, $options);
}
if (empty($options)) {
return null;
}
$script = '<script type="text/javascript">';
$script .= 'var RecaptchaOptions = ' . json_encode($options) . ';';
$script .= '</script>';
return $script;
}
示例12: _init
/**
* Initializes the record set and uses the database connection to get the column list contained
* in the query that created this object.
*
* @see lithium\data\collection\RecordSet::$_columns
* @return void
* @todo The part that uses _handle->schema() should be rewritten so that the column list
* is coming from the query object.
*/
protected function _init()
{
parent::_init();
if (!$this->_result) {
return;
}
$this->_columns = $this->_columnMap();
if (!$this->_query) {
return;
}
$this->_keyIndex = $this->_keyIndex();
$this->_dependencies = Set::expand(Set::normalize(array_filter(array_keys($this->_columns))));
$this->_relationships = $this->_query->relationships();
}
示例13: run
/**
* Runs a test group or a specific test file based on the passed
* parameters.
*
* @param string $group If set, this test group is run. If not set, a group test may
* also be run by passing the 'group' option to the $options parameter.
* @param array $options Options array for the test run. Valid options are:
* - 'case': The fully namespaced test case to be run.
* - 'group': The fully namespaced test group to be run.
* - 'filters': An array of filters that the test output should be run through.
* @return array A compact array of the title, an array of the results, as well
* as an additional array of the results after the $options['filters']
* have been applied.
*/
public static function run($group = null, $options = array())
{
$defaults = array('title' => $group, 'filters' => array(), 'reporter' => 'text');
$options += $defaults;
$items = (array) $group;
$isCase = preg_match('/Test$/', $group);
if ($isCase) {
$items = array(new $group());
}
$options['filters'] = Set::normalize($options['filters']);
$group = static::_group($items);
$report = static::_report($group, $options);
$report->run();
return $report;
}
示例14: parse
public static function parse($conditions, $data, array $options = array())
{
$params = compact('conditions', 'data', 'options');
return static::_filter(__METHOD__, $params, function ($self, $params) {
extract($params);
$defaults = array();
$options += $defaults;
$check = String::insert($conditions, Set::flatten($data));
if (strpbrk($check, '&|')) {
return eval("return (boolean)({$check});");
}
// TODO: take care, that spaces are around operator
return $self::invokeMethod('compare', explode(" ", $check, 3));
});
}
示例15: run
/**
* Runs a test group or a specific test file based on the passed
* parameters.
*
* @param string $group If set, this test group is run. If not set, a group test may
* also be run by passing the 'group' option to the $options parameter.
* @param array $options Options array for the test run. Valid options are:
* - 'case': The fully namespaced test case to be run.
* - 'group': The fully namespaced test group to be run.
* - 'filters': An array of filters that the test output should be run through.
* @return array A compact array of the title, an array of the results, as well
* as an additional array of the results after the $options['filters']
* have been applied.
* @filter
*/
public static function run($group = null, array $options = array())
{
$defaults = array('title' => $group, 'filters' => array(), 'reporter' => 'text');
$options += $defaults;
$isCase = is_string($group) && preg_match('/Test$/', $group);
$items = $isCase ? array(new $group()) : (array) $group;
$options['filters'] = Set::normalize($options['filters']);
$group = static::_group($items);
$report = static::_report($group, $options);
return static::_filter(__FUNCTION__, compact('report'), function ($self, $params, $chain) {
$environment = Environment::get();
Environment::set('test');
$params['report']->run();
Environment::set($environment);
return $params['report'];
});
}