本文整理汇总了PHP中lithium\util\Set类的典型用法代码示例。如果您正苦于以下问题:PHP Set类的具体用法?PHP Set怎么用?PHP Set使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Set类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'];
});
}
开发者ID:bruensicke,项目名称:radium,代码行数:37,代码来源:Ini.php
示例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;
}
开发者ID:bruensicke,项目名称:radium,代码行数:50,代码来源:IniFormat.php
示例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);
});
}
开发者ID:fedeisas,项目名称:lithium,代码行数:38,代码来源:Controller.php
示例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;
});
}
开发者ID:bruensicke,项目名称:radium,代码行数:36,代码来源:Neon.php
示例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;
}
开发者ID:bruensicke,项目名称:radium,代码行数:28,代码来源:Widgets.php
示例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']);
}
开发者ID:EHER,项目名称:chegamos,代码行数:21,代码来源:Memcache.php
示例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'));
}
开发者ID:bruensicke,项目名称:radium,代码行数:10,代码来源:ConfigurationsTest.php
示例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);
}
开发者ID:bruensicke,项目名称:li3_mustache,代码行数:22,代码来源:Mustache.php
示例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('');
}
}
}
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:21,代码来源:RecordSet.php
示例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');
}
开发者ID:bruensicke,项目名称:radium,代码行数:13,代码来源:RadiumController.php
示例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;
}
开发者ID:djordje,项目名称:li3_recaptcha,代码行数:22,代码来源:Recaptcha.php
示例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();
}
开发者ID:fedeisas,项目名称:lithium,代码行数:23,代码来源:RecordSet.php
示例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;
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:29,代码来源:Dispatcher.php
示例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));
});
}
开发者ID:bruensicke,项目名称:radium,代码行数:15,代码来源:Conditions.php
示例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'];
});
}
开发者ID:nashadalam,项目名称:lithium,代码行数:32,代码来源:Dispatcher.php
示例16: _toString
/**
* Renders `$data` into an easier to understand, or flat, array.
*
* @param array $data Data to traverse.
* @return array
*/
protected function _toString($data)
{
foreach ($data as $key => $val) {
switch (true) {
case is_object($val) && !$val instanceof Closure:
try {
$data[$key] = (string) $val;
} catch (Exception $e) {
$data[$key] = '';
}
break;
case is_array($val):
$data = array_merge($data, Set::flatten($val));
break;
}
}
return $data;
}
开发者ID:rapzo,项目名称:lithium,代码行数:24,代码来源:Simple.php
示例17: loadMetadataForClass
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{
if (!$metadata->reflClass instanceof SchemaReflection) {
$metadata->reflClass = new SchemaReflection(get_class($metadata));
}
$metadata->primaryTable['name'] = $className::meta('source');
$primaryKey = $className::meta('key');
$bindings = static::bindings($className);
$relations = array();
if (!empty($bindings)) {
foreach ($bindings as $type => $set) {
foreach ($set as $key => $relation) {
$mapping = array('fetch' => \Doctrine\ORM\Mapping\AssociationMapping::FETCH_EAGER, 'fieldName' => $relation['fieldName'], 'sourceEntity' => $className, 'targetEntity' => $relation['class'], 'mappedBy' => null, 'cascade' => !empty($relation['dependent']) ? array('remove') : array(), 'optional' => $type != 'belongsTo');
if (in_array($type, array('hasOne', 'hasMany'))) {
$inverse = $type == 'belongsTo';
$mapping['joinColumns'][] = array('fieldName' => !$inverse ? $relation['key'] : $relation['fieldName'], 'name' => !$inverse ? $relation['fieldName'] : $relation['key'], 'referencedColumnName' => $relation['class']::meta('key'));
}
if (in_array($type, array('belongsTo', 'hasOne', 'hasMany'))) {
$mapping['mappedBy'] = static::_fieldName($mapping);
}
$relations[$type][$key] = $mapping;
}
}
}
$schema = (array) $className::schema();
$metadata->reflClass->setRelations($relations);
$metadata->reflClass->setSchema($schema);
$belongsToFields = !empty($bindings['belongsTo']) ? Set::combine(array_values($bindings['belongsTo']), '/key', '/fieldName') : array();
foreach ($schema as $field => $column) {
$mapping = array_merge(array('id' => $field == $primaryKey, 'fieldName' => !empty($belongsToFields[$field]) ? $belongsToFields[$field] : $field, 'columnName' => $field), (array) $column);
$metadata->mapField($mapping);
if ($mapping['id']) {
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_AUTO);
}
}
foreach ($relations as $type => $set) {
foreach ($set as $key => $mapping) {
$metadata->{static::$_bindingMapping[$type]}($mapping);
$mapping = $metadata->associationMappings[$mapping['fieldName']];
}
}
}
开发者ID:ncud,项目名称:sagalaya,代码行数:42,代码来源:ModelDriver.php
示例18: run
public function run($id = null)
{
$id = !is_null($id) ? $id : $this->request->id;
$model = $this->scaffold['model'];
$object = $model::first($id);
if (!$object) {
$url = array('action' => 'index');
return $this->redirect($url);
}
list($temp, $options) = Set::slice($this->request->data, array('validate', 'strict'));
switch ($this->request->data['mode']) {
case 'keep':
$options['overwrite'] = false;
break;
case 'remove':
$options['prune'] = true;
break;
}
$result = $object->run($options);
$url = array('action' => 'view', 'args' => array((string) $object->{$model::key()}));
return $this->redirect($url);
}
开发者ID:bruensicke,项目名称:radium,代码行数:22,代码来源:AssetsController.php
示例19: _init
/**
* Pulls request data from superglobals.
*
* @return void
*/
protected function _init()
{
parent::_init();
$mobile = array('iPhone', 'MIDP', 'AvantGo', 'BlackBerry', 'J2ME', 'Opera Mini', 'DoCoMo', 'NetFront', 'Nokia', 'PalmOS', 'PalmSource', 'portalmmm', 'Plucker', 'ReqwirelessWeb', 'iPod', 'SonyEricsson', 'Symbian', 'UP\\.Browser', 'Windows CE', 'Xiino', 'Android');
if (!empty($this->_config['detectors']['mobile'][1])) {
$mobile = array_merge($mobile, (array) $this->_config['detectors']['mobile'][1]);
}
$this->_detectors['mobile'][1] = $mobile;
$this->_env += (array) $_SERVER + (array) $_ENV + array('REQUEST_METHOD' => 'GET');
$envs = array('isapi' => 'IIS', 'cgi' => 'CGI', 'cgi-fcgi' => 'CGI');
$this->_env['PLATFORM'] = isset($envs[PHP_SAPI]) ? $envs[PHP_SAPI] : null;
$this->_base = isset($this->_base) ? $this->_base : $this->_base();
$this->url = '/';
if (isset($this->_config['url'])) {
$this->url = rtrim($this->_config['url'], '/');
} elseif (!empty($_GET['url'])) {
$this->url = rtrim($_GET['url'], '/');
unset($_GET['url']);
}
if (!empty($this->_config['query'])) {
$this->query = $this->_config['query'];
}
if (isset($_GET)) {
$this->query += $_GET;
}
if (!empty($this->_config['data'])) {
$this->data = $this->_config['data'];
} elseif (isset($_POST)) {
$this->data += $_POST;
}
if (isset($this->data['_method'])) {
$this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'] = strtoupper($this->data['_method']);
unset($this->data['_method']);
}
if (!empty($this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
$this->_env['REQUEST_METHOD'] = $this->_env['HTTP_X_HTTP_METHOD_OVERRIDE'];
}
$method = strtoupper($this->_env['REQUEST_METHOD']);
if (($method == 'POST' || $method == 'PUT') && !$this->data) {
if (($type = $this->type()) && $type !== 'html') {
$this->_stream = $this->_stream ?: fopen('php://input', 'r');
$media = $this->_classes['media'];
$this->data = (array) $media::decode($type, stream_get_contents($this->_stream));
fclose($this->_stream);
}
}
if (isset($_FILES) && $_FILES) {
$result = array();
$normalize = function ($key, $value) use($result, &$normalize) {
foreach ($value as $param => $content) {
foreach ($content as $num => $val) {
if (is_numeric($num)) {
$result[$key][$num][$param] = $val;
continue;
}
if (is_array($val)) {
foreach ($val as $next => $one) {
$result[$key][$num][$next][$param] = $one;
}
continue;
}
$result[$key][$num][$param] = $val;
}
}
return $result;
};
foreach ($_FILES as $key => $value) {
if (isset($value['name'])) {
if (is_string($value['name'])) {
$result[$key] = $value;
continue;
}
if (is_array($value['name'])) {
$result += $normalize($key, $value);
}
}
}
$this->data = Set::merge((array) $this->data, $result);
}
}
开发者ID:Nys,项目名称:lithium,代码行数:85,代码来源:Request.php
示例20: _prepareMatchParams
protected static function _prepareMatchParams($parameters)
{
foreach (Set::normalize($parameters) as $token => $scope) {
if (strpos($token, 'T_') !== 0) {
unset($parameters[$token]);
foreach (array('before', 'after') as $key) {
if (!isset($scope[$key])) {
continue;
}
$items = array();
foreach ((array) $scope[$key] as $item) {
$items[] = strpos($item, 'T_') !== 0 ? static::token($item) : $item;
}
$scope[$key] = $items;
}
$parameters[static::token($token)] = $scope;
}
}
return $parameters;
}
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:20,代码来源:Parser.php
注:本文中的lithium\util\Set类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论