当前位置: 首页>>代码示例>>PHP>>正文


PHP Set::flatten方法代码示例

本文整理汇总了PHP中lithium\util\Set::flatten方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::flatten方法的具体用法?PHP Set::flatten怎么用?PHP Set::flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lithium\util\Set的用法示例。


在下文中一共展示了Set::flatten方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: _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

示例8: check

 /**
  * Checks a set of values against a specified rules list. This method may be used to validate
  * any arbitrary array of data against a set of validation rules.
  *
  * @param array $values An array of key/value pairs, where the values are to be checked.
  * @param array $rules An array of rules to check the values in `$values` against. Each key in
  *              `$rules` should match a key contained in `$values`, and each value should be a
  *              validation rule in one of the allowable formats. For example, if you are
  *              validating a data set containing a `'credit_card'` key, possible values for
  *              `$rules` would be as follows:
  *              - `array('credit_card' => 'You must include a credit card number')`: This is the
  *                simplest form of validation rule, in which the value is simply a message to
  *                display if the rule fails. Using this format, all other validation settings
  *                inherit from the defaults, including the validation rule itself, which only
  *                checks to see that the corresponding key in `$values` is present and contains
  *                a value that is not empty. _Please note when globalizing validation messages:_
  *                When specifying messages, it may be preferable to use a code string (i.e.
  *                `'ERR_NO_TITLE'`) instead of the full text of the validation error. These code
  *                strings may then be translated by the appropriate tools in the templating
  *                layer.
  *              - `array('credit_card' => array('creditCard', 'message' => 'Invalid CC #'))`:
  *                In the second format, the validation rule (in this case `creditCard`) and
  *                associated configuration are specified as an array, where the rule to use is
  *                the first value in the array (no key), and additional settings are specified
  *                as other keys in the array. Please see the list below for more information on
  *                allowed keys.
  *              - The final format allows you to apply multiple validation rules to a single
  *                value, and it is specified as follows:
  *
  * `array('credit_card' => array(
  * 	array('notEmpty', 'message' => 'You must include credit card number'),
  * 	array('creditCard', 'message' => 'Your credit card number must be valid')
  * ));`
  * @param array $options Validator-specific options.
  *
  * Each rule defined as an array can contain any of the following settings (in addition to the
  * first value, which represents the rule to be used):
  *  - `'message'` _string_: The error message to be returned if the validation rule fails. See
  *    the note above regarding globalization of error messages.
  *  - `'required`' _boolean_: Represents whether the value is required to be present in
  *    `$values`. If `'required'` is set to `false`, the validation rule will be skipped if the
  *     corresponding key is not present. Defaults to `true`.
  *  - `'skipEmpty'` _boolean_: Similar to `'required'`, this setting (if `true`) will cause the
  *    validation rule to be skipped if the corresponding value is empty (an empty string or
  *    `null`). Defaults to `false`.
  *  - `'format'` _string_: If the validation rule has multiple format definitions (see the
  *    `add()` or `__init()` methods), the name of the format to be used can be specified here.
  *    Additionally, two special values can be used: either `'any'`, which means that all formats
  *    will be checked and the rule will pass if any format passes, or `'all'`, which requires
  *    all formats to pass in order for the rule check to succeed.
  * @return array Returns an array containing all validation failures for data in `$values`,
  *         where each key matches a key in `$values`, and each value is an array of that
  *         element's validation errors.
  * @filter
  */
 public static function check(array $values, array $rules, array $options = array())
 {
     $defaults = array('notEmpty', 'message' => null, 'required' => true, 'skipEmpty' => false, 'format' => 'any', 'on' => null, 'last' => false);
     $options += $defaults;
     $params = compact('values', 'rules', 'options');
     return static::_filter(__FUNCTION__, $params, function ($self, $params) {
         $values = $params['values'];
         $rules = $params['rules'];
         $options = $params['options'];
         $errors = array();
         $events = (array) (isset($options['events']) ? $options['events'] : null);
         $values = Set::flatten($values);
         foreach ($rules as $field => $rules) {
             $rules = is_string($rules) ? array('message' => $rules) : $rules;
             $rules = is_array(current($rules)) ? $rules : array($rules);
             $errors[$field] = array();
             $options['field'] = $field;
             foreach ($rules as $key => $rule) {
                 $rule += $options + compact('values');
                 list($name) = $rule;
                 if ($events && $rule['on'] && !array_intersect($events, (array) $rule['on'])) {
                     continue;
                 }
                 if (!array_key_exists($field, $values)) {
                     if ($rule['required']) {
                         $errors[$field][] = $rule['message'] ?: $key;
                     }
                     if ($rule['last']) {
                         break;
                     }
                     continue;
                 }
                 if (empty($values[$field]) && $rule['skipEmpty']) {
                     continue;
                 }
                 if (!$self::rule($name, $values[$field], $rule['format'], $rule + $options)) {
                     $errors[$field][] = $rule['message'] ?: $key;
                     if ($rule['last']) {
                         break;
                     }
                 }
             }
         }
         return array_filter($errors);
     });
//.........这里部分代码省略.........
开发者ID:nashadalam,项目名称:lithium,代码行数:101,代码来源:Validator.php

示例9: delete

 /**
  * Delete value from the cookie
  *
  * @param string $key The key to be deleted
  * @param array $options Options array
  * @return boolean True on successful delete, false otherwise
  */
 public function delete($key, $options = array())
 {
     $config = $options + $this->_config;
     return function ($self, $params, $chain) use(&$config) {
         extract($params);
         $key = is_array($key) ? Set::flatten($key) : array($key);
         foreach ($key as $name) {
             $name = explode('.', $name);
             $name = $config['name'] ? array_merge(array($config['name']), $name) : $name;
             if (count($name) == 1) {
                 $name = current($name);
             } else {
                 $name = array_shift($name) . '[' . join('][', $name) . ']';
             }
             setcookie($name, "", time() - 1, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
         }
     };
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:25,代码来源:Cookie.php

示例10: testFlattenTwoLevels

	public function testFlattenTwoLevels() {
		$data = array(
			array(
				'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post'),
				'Author' => array('id' => '1', 'user' => 'nate', 'password' => 'foo')
			),
			array(
				'Post' => array(
					'id' => '2',
					'author_id' => '3',
					'title' => 'Second Post',
					'body' => 'Second Post Body'
				),
				'Author' => array('id' => '3', 'user' => 'joel', 'password' => null)
			)
		);

		$expected = array(
			'0.Post.id' => '1', '0.Post.author_id' => '1', '0.Post.title' => 'First Post',
			'0.Author.id' => '1', '0.Author.user' => 'nate', '0.Author.password' => 'foo',
			'1.Post.id' => '2', '1.Post.author_id' => '3', '1.Post.title' => 'Second Post',
			'1.Post.body' => 'Second Post Body', '1.Author.id' => '3',
			'1.Author.user' => 'joel', '1.Author.password' => null
		);
		$result = Set::flatten($data);
		$this->assertEqual($expected, $result);

		$result = Set::expand($result);
		$this->assertEqual($data, $result);

		$result = Set::flatten($data[0], array('separator' => '/'));
		$expected = array(
			'Post/id' => '1', 'Post/author_id' => '1', 'Post/title' => 'First Post',
			'Author/id' => '1', 'Author/user' => 'nate', 'Author/password' => 'foo'
		);
		$this->assertEqual($expected, $result);

		$result = Set::expand($expected, array('separator' => '/'));
		$this->assertEqual($data[0], $result);
	}
开发者ID:niel,项目名称:lithium,代码行数:40,代码来源:SetTest.php

示例11: message

 /**
  * generates a parsed message, depending on given $type
  *
  * @param string $type what type is this event
  * @param string $data additional data to be tracked for that event
  * @return string|boolean parsed string of message, or false in case of error
  */
 public static function message($type, $data = array())
 {
     if (!array_key_exists($type, Activity::$_events)) {
         return false;
     }
     return String::insert(Activity::$_events[$type], Set::flatten($data));
 }
开发者ID:bruensicke,项目名称:li3_activities,代码行数:14,代码来源:Activity.php

示例12: array

<?php

use lithium\net\http\Router;
$url = Router::match(array('library' => 'radium', 'controller' => 'assets', 'action' => 'show', 'id' => $this->scaffold->object->id()), $this->request(), array('absolute' => true));
?>
<div class="plaintext"><pre><?php 
echo $url;
?>
</pre></div>
<audio controls><source src="<?php 
echo $url;
?>
" type="<?php 
echo $this->scaffold->object['mime'];
?>
"></audio>
<hr />
<?php 
unset($this->scaffold->object['file']);
echo $this->scaffold->render('data', array('data' => \lithium\util\Set::flatten($this->scaffold->object->data())));
开发者ID:bruensicke,项目名称:radium,代码行数:20,代码来源:view.audio.html.php

示例13: clear

 /**
  * Clears all cookies.
  *
  * @param array $options Options array. Not used fro this adapter method.
  * @return boolean True on successful clear, false otherwise.
  */
 public function clear(array $options = array())
 {
     $options += array('destroySession' => true);
     $config = $this->_config;
     $cookieClass = get_called_class();
     return function ($self, $params) use(&$config, $options, $cookieClass) {
         if ($options['destroySession'] && session_id()) {
             session_destroy();
         }
         if (!isset($_COOKIE[$config['name']])) {
             return true;
         }
         $cookies = array_keys(Set::flatten($_COOKIE[$config['name']]));
         foreach ($cookies as $name) {
             $name = $cookieClass::keyFormat($name, $config);
             $result = setcookie($name, "", 1, $config['path'], $config['domain'], $config['secure'], $config['httponly']);
             if (!$result) {
                 throw new RuntimeException("There was an error clearing {$cookie} cookie.");
             }
         }
         unset($_COOKIE[$config['name']]);
         return true;
     };
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:30,代码来源:Cookie.php

示例14: check

 /**
  * Validates form data using an embedded form signature string. The form signature string
  * must be embedded in `security.signature` alongside the other data to check against.
  *
  * Note: Will ignore any other data inside `security.*`.
  *
  * @param array|object $data The form data as an array or an
  *        object with the data inside the `data` property.
  * @return boolean `true` if the form data is valid, `false` if not.
  */
 public static function check($data)
 {
     if (is_object($data) && isset($data->data)) {
         $data = $data->data;
     }
     if (!isset($data['security']['signature'])) {
         throw new Exception('Unable to check form signature. Cannot find signature in data.');
     }
     $signature = $data['security']['signature'];
     unset($data['security']);
     $parsed = static::_parse($signature);
     $data = Set::flatten($data);
     if (array_intersect_assoc($data, $parsed['locked']) != $parsed['locked']) {
         return false;
     }
     $fields = array_diff(array_keys($data), array_keys($parsed['locked']), $parsed['excluded']);
     return $signature === static::_compile($fields, $parsed['locked'], $parsed['excluded']);
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:28,代码来源:FormSignature.php

示例15: check

 public static function check($data)
 {
     if (is_object($data) && isset($data->data)) {
         $data = $data->data;
     }
     if (!isset($data['security']['signature'])) {
         return false;
     }
     $signature = $data['security']['signature'];
     unset($data['security']);
     $data = Set::flatten($data);
     $fields = array_keys($data);
     list($locked, $excluded, $hash) = explode('::', $signature, 3);
     $locked = unserialize(urldecode($locked));
     $excluded = unserialize(urldecode($excluded));
     $fields = array_diff($fields, $excluded);
     if (array_intersect_assoc($data, $locked) != $locked) {
         return false;
     }
     return $signature === static::key(compact('fields', 'locked', 'excluded'));
 }
开发者ID:beeckmpi,项目名称:permanentielijsten,代码行数:21,代码来源:FormSignature.php


注:本文中的lithium\util\Set::flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。