本文整理汇总了PHP中Cake\Utility\Hash::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::filter方法的具体用法?PHP Hash::filter怎么用?PHP Hash::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Hash
的用法示例。
在下文中一共展示了Hash::filter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeDispatch
/**
* Callback for Routing.beforeDispatch event.
*
* @param \Cake\Event\Event $event The event instance.
*
* @return \Cake\Network\Response Response instance.
*/
public function beforeDispatch(Event $event)
{
$request = $event->data['request'];
$response = $event->data['response'];
$path = urldecode($request->url);
if (Configure::read('Glide.secureUrls')) {
SignatureFactory::create(Security::salt())->validateRequest('/' . $path, $request->query);
}
$server = ServerFactory::create(Configure::read('Glide.serverConfig'));
$cache = Configure::read('Glide.cache');
if ($cache) {
$timestamp = $server->getSource()->getTimestamp($server->getSourcePath($path));
$response->modified($timestamp);
if (!$response->checkNotModified($request)) {
$response = $server->getImageResponse($path, $request->query);
}
$response->cache($timestamp, $cache);
} else {
$response = $server->getImageResponse($path, $request->query);
}
$headers = Hash::filter((array) Configure::read('Glide.headers'));
foreach ($headers as $key => $value) {
$response->header($key, $value);
}
return $response;
}
示例2: _filterParams
/**
* Filters the params from POST data and merges in the whitelisted query string ones.
*
* @return array
*/
protected function _filterParams()
{
$params = Hash::filter($this->request->data);
if (!$this->config('queryStringWhitelist')) {
return $params;
}
foreach ($this->config('queryStringWhitelist') as $field) {
if (!isset($params[$field]) && $this->request->query($field) !== null) {
$params[$field] = $this->request->query($field);
}
}
return $params;
}
示例3: _getErrors
/**
* Extracts nested validation errors
*
* @param EntityInterface $entity Entity to extract
*
* @return array
*/
protected function _getErrors(EntityInterface $entity)
{
$errors = $entity->errors();
foreach ($entity->visibleProperties() as $property) {
$v = $entity[$property];
if ($v instanceof EntityInterface) {
$errors[$property] = $this->_getErrors($v);
} elseif (is_array($v)) {
foreach ($v as $key => $varValue) {
if ($varValue instanceof EntityInterface) {
$errors[$property][$key] = $this->_getErrors($varValue);
}
}
}
}
return Hash::filter($errors);
}
示例4: _secure
/**
* Determine which fields of a form should be used for hash.
* Populates $this->fields
*
* @param bool $lock Whether this field should be part of the validation
* or excluded as part of the unlockedFields.
* @param string|array $field Reference to field to be secured. Can be dot
* separated string to indicate nesting or array of fieldname parts.
* @param mixed $value Field value, if value should not be tampered with.
* @return void
*/
protected function _secure($lock, $field, $value = null)
{
if (empty($field) && $field !== '0') {
return;
}
if (is_string($field)) {
$field = Hash::filter(explode('.', $field));
}
foreach ($this->_unlockedFields as $unlockField) {
$unlockParts = explode('.', $unlockField);
if (array_values(array_intersect($field, $unlockParts)) === $unlockParts) {
return;
}
}
$field = implode('.', $field);
$field = preg_replace('/(\\.\\d+)+$/', '', $field);
if ($lock) {
if (!in_array($field, $this->fields)) {
if ($value !== null) {
return $this->fields[$field] = $value;
} elseif (isset($this->fields[$field]) && $value === null) {
unset($this->fields[$field]);
}
$this->fields[] = $field;
}
} else {
$this->unlockField($field);
}
}
示例5: testFilter
/**
* testFilter method
*
* @return void
*/
public function testFilter()
{
$result = Hash::filter(['0', false, true, 0, ['one thing', 'I can tell you', 'is you got to be', false]]);
$expected = ['0', 2 => true, 3 => 0, 4 => ['one thing', 'I can tell you', 'is you got to be']];
$this->assertSame($expected, $result);
$result = Hash::filter([1, [false]]);
$expected = [1];
$this->assertEquals($expected, $result);
$result = Hash::filter([1, [false, false]]);
$expected = [1];
$this->assertEquals($expected, $result);
$result = Hash::filter([1, ['empty', false]]);
$expected = [1, ['empty']];
$this->assertEquals($expected, $result);
$result = Hash::filter([1, ['2', false, [3, null]]]);
$expected = [1, ['2', 2 => [3]]];
$this->assertEquals($expected, $result);
$this->assertSame([], Hash::filter([]));
}
示例6: _extractParams
/**
* Extracts all parameters for wich a filter with a matching field
* name exists.
*
* @param array $params The parameters array to extract from.
* @param \Search\Model\Filter\Base[] $filters The filters to match against.
* @return array The extracted parameters.
*/
protected function _extractParams($params, $filters)
{
return array_intersect_key(Hash::filter($params), $filters);
}
示例7: _getNamespace
/**
* Get the namespace for a given class.
*
* @param string $className The class you want a namespace for.
* @param string $pluginPath The plugin path.
* @param string $prefixPath The prefix path.
* @return string
*/
protected function _getNamespace($className, $pluginPath = null, $prefixPath = null)
{
$namespace = preg_replace('/(.*)Controller\\//', '', $className);
$namespace = preg_replace('/\\//', '\\', $namespace);
$namespace = preg_replace('/\\.php/', '', $namespace);
$prefixPath = preg_replace('/\\//', '\\', Inflector::camelize($prefixPath));
if (!$pluginPath) {
$rootNamespace = Configure::read('App.namespace');
} else {
$rootNamespace = preg_replace('/\\//', '\\', $pluginPath);
}
$namespace = [$rootNamespace, 'Controller', $prefixPath, $namespace];
return implode('\\', Hash::filter($namespace));
}
示例8: testFilter
/**
* testFilter method
*
* @return void
*/
public function testFilter()
{
$result = Hash::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false)));
$expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be'));
$this->assertSame($expected, $result);
$result = Hash::filter(array(1, array(false)));
$expected = array(1);
$this->assertEquals($expected, $result);
$result = Hash::filter(array(1, array(false, false)));
$expected = array(1);
$this->assertEquals($expected, $result);
$result = Hash::filter(array(1, array('empty', false)));
$expected = array(1, array('empty'));
$this->assertEquals($expected, $result);
$result = Hash::filter(array(1, array('2', false, array(3, null))));
$expected = array(1, array('2', 2 => array(3)));
$this->assertEquals($expected, $result);
$this->assertSame(array(), Hash::filter(array()));
}
示例9: cleanup
protected function cleanup($rows)
{
$rows = Hash::filter($rows);
foreach ($rows as $key => $row) {
unset($rows[$key]['id'], $rows[$key]['value']);
}
return $rows;
}