本文整理汇总了PHP中JInput::getArray方法的典型用法代码示例。如果您正苦于以下问题:PHP JInput::getArray方法的具体用法?PHP JInput::getArray怎么用?PHP JInput::getArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JInput
的用法示例。
在下文中一共展示了JInput::getArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetArrayNested
/**
* Test the JInput::get method using a nested data set.
*/
public function testGetArrayNested()
{
$filterMock = new JFilterInputMockTracker();
$input = new JInput(array('var2' => 34, 'var3' => array('var2' => 'test'), 'var4' => array('var1' => array('var2' => 'test'))), array('filter' => $filterMock));
$this->assertThat($input->getArray(array('var2' => 'filter2', 'var3' => array('var2' => 'filter3'))), $this->equalTo(array('var2' => 34, 'var3' => array('var2' => 'test'))), 'Line: ' . __LINE__ . '.');
$this->assertThat($input->getArray(array('var4' => array('var1' => array('var2' => 'filter1')))), $this->equalTo(array('var4' => array('var1' => array('var2' => 'test')))), 'Line: ' . __LINE__ . '.');
$this->assertThat($filterMock->calls['clean'][0], $this->equalTo(array(34, 'filter2')), 'Line: ' . __LINE__ . '.');
$this->assertThat($filterMock->calls['clean'][1], $this->equalTo(array(array('var2' => 'test'), 'array')), 'Line: ' . __LINE__ . '.');
}
示例2: testGetArrayWithoutSpecifiedVariables
/**
* Test the JInput::getArray method without specified variables.
*
* @return void
*
* @since 12.3
*/
public function testGetArrayWithoutSpecifiedVariables()
{
$array = array('var2' => 34, 'var3' => array('var2' => 'test'), 'var4' => array('var1' => array('var2' => 'test')), 'var5' => array('foo' => array()), 'var6' => array('bar' => null), 'var7' => null);
$input = new JInput($array);
$this->assertEquals($input->getArray(), $array);
}
示例3: getPostedData
/**
* Returns posted data in array format
*
* @return array
*
* @since 1.2
*/
public static function getPostedData()
{
$input = JFactory::getApplication()->input;
$inputData = file_get_contents("php://input");
if (is_object($inputData)) {
$inputData = JArrayHelper::fromObject($inputData);
} elseif (is_string($inputData)) {
$inputData = trim($inputData);
$parsedData = null;
// We try to transform it into JSON
if ($data_json = @json_decode($inputData, true)) {
if (json_last_error() == JSON_ERROR_NONE) {
$parsedData = (array) $data_json;
}
}
// We try to transform it into XML
if (is_null($parsedData) && ($xml = @simplexml_load_string($inputData))) {
$json = json_encode((array) $xml);
$parsedData = json_decode($json, true);
}
// We try to transform it into Array
if (is_null($parsedData) && !empty($inputData) && !is_array($inputData)) {
parse_str($inputData, $parsedData);
}
$inputData = $parsedData;
} else {
$inputData = $input->post->getArray();
}
// Filter data with JInput default filter
$postedData = new JInput($inputData);
return $postedData->getArray();
}