本文整理汇总了PHP中Zend\Stdlib\ArrayUtils::isList方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::isList方法的具体用法?PHP ArrayUtils::isList怎么用?PHP ArrayUtils::isList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Stdlib\ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils::isList方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildComponent
/**
* Build component
*
* @param array|string $component
* @return array
*/
protected function buildComponent($component)
{
$componentManager = $this->componentManager;
$transformObj = function ($item) use($componentManager) {
if (ArrayUtils::isHashTable($item) && isset($item['cmp'])) {
$itemObj = $componentManager->get($item['cmp']);
$itemObj->setProperties($item);
unset($itemObj['cmp'], $itemObj['extend']);
$item = $itemObj;
}
return $item;
};
// Recursive mapping, convert to class later
$map = function ($func, $arr) use(&$map, $transformObj) {
$result = array();
if (ArrayUtils::isHashTable($arr)) {
foreach ($arr as $k => $v) {
$result[$k] = $map($func, $v);
}
$result = $transformObj($result);
} elseif (ArrayUtils::isList($arr)) {
foreach ($arr as $b) {
$result[] = $transformObj($b);
}
} elseif (is_string($arr)) {
$result = $arr;
}
return $result;
};
return $map(function ($item) {
return $item;
}, $component);
}
示例2: setOption
/**
* Option setter with validation
* If option can have the specified value then it is set, otherwise this method throws exception
*
* Tip: call it into your setter methods.
*
* @param $key
* @param $value
* @return $this
* @throws Exception\DomainException
* @throws Exception\InvalidArgumentException
*/
protected function setOption($key, $value)
{
if (!isset($this->config[$key])) {
throw new Exception\DomainException(sprintf('Option "%s" does not exist; available options are (%s)', $key, implode(', ', array_map(function ($opt) {
return '"' . $opt . '"';
}, array_keys($this->config)))));
}
if (!ArrayUtils::isList($this->config[$key], false)) {
throw new Exception\DomainException(sprintf('Option "%s" does not have a list of allowed values', $key));
}
if (!ArrayUtils::inArray($value, $this->config[$key], true)) {
throw new Exception\InvalidArgumentException(sprintf('Option "%s" can not be set to value "%s"; allowed values are (%s)', $key, $value, implode(', ', array_map(function ($val) {
return '"' . $val . '"';
}, $this->config[$key]))));
}
$this->options[$key] = $value;
return $this;
}
示例3: write
/**
* Write a value
*
* @param mixed $value
* @throws Exception\RuntimeException on invalid or unrecognized value type
*/
protected function write($value)
{
if ($value === null) {
$this->writeNull();
} elseif (is_bool($value)) {
$this->writeBool($value);
} elseif (is_int($value)) {
$this->writeInt($value);
} elseif (is_float($value)) {
$this->writeFloat($value);
} elseif (is_string($value)) {
// TODO: write unicode / binary
$this->writeString($value);
} elseif (is_array($value)) {
if (ArrayUtils::isList($value)) {
$this->writeArrayList($value);
} else {
$this->writeArrayDict($value);
}
} elseif (is_object($value)) {
$this->writeObject($value);
} else {
throw new Exception\RuntimeException(sprintf('PHP-Type "%s" can not be serialized by %s', gettype($value), get_called_class()));
}
}
示例4: testEmptyArrayReturnsFalse
public function testEmptyArrayReturnsFalse()
{
$test = array();
$this->assertFalse(ArrayUtils::hasStringKeys($test, false));
$this->assertFalse(ArrayUtils::hasIntegerKeys($test, false));
$this->assertFalse(ArrayUtils::hasNumericKeys($test, false));
$this->assertFalse(ArrayUtils::isList($test, false));
$this->assertFalse(ArrayUtils::isHashTable($test, false));
}
示例5: isList
/**
* @return bool
*/
public function isList()
{
return ArrayUtils::isList($this->data());
}
示例6: extractResourceFromHal
/**
* @param array $data
* @return array
*/
protected function extractResourceFromHal(array $data, $promoteTopCollection = true)
{
if (array_key_exists('_links', $data)) {
unset($data['_links']);
}
if (array_key_exists('_embedded', $data)) {
$embedded = $data['_embedded'];
foreach ($embedded as $key => $resourceNode) {
if (ArrayUtils::isList($resourceNode, true)) {
//assume is a collection of resources
$temp = [];
foreach ($resourceNode as $resource) {
$temp[] = $this->extractResourceFromHal($resource, false);
}
if ($promoteTopCollection) {
if (count($embedded) > 1) {
throw new Exception\RuntimeException('Cannot promote multiple top collections');
}
$data = $temp;
break;
} else {
$data[$key] = $temp;
}
} else {
//assume is a single resource
$data[$key] = $this->extractResourceFromHal($resourceNode, false);
}
}
unset($data['_embedded']);
}
return $data;
}
示例7: setSearchFields
public function setSearchFields(array $fields)
{
if (ArrayUtils::isList($fields)) {
$this->searchFields = array_flip($fields);
} else {
$this->searchFields = $fields;
}
return $this;
}
示例8: processBulkData
/**
* Bulk Process Data, handles POST, PUT & DELETE
*
* @param array $data
* @param string $entityName
* @param string $entityIdentifier
* @return JsonModel
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
public function processBulkData(array $data, $entityName, $entityIdentifier = 'id')
{
$data = reset($data);
if (!ArrayUtils::isList($data)) {
throw new Exception\InvalidArgumentException('Invalid bulk data provided');
}
$errors = false;
$responses = array();
foreach ($data as $entityArray) {
try {
switch ($this->getRequest()->getMethod()) {
case 'POST':
$result = $this->create(array($entityName => $entityArray));
break;
case 'PUT':
$id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
$result = $this->update($id, array($entityName => $entityArray));
break;
case 'PATCH':
$id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
$result = $this->patch($id, array($entityName => $entityArray));
break;
case 'DELETE':
$id = isset($entityArray[$entityIdentifier]) ? $entityArray[$entityIdentifier] : null;
$result = $this->delete($id);
break;
default:
throw new Exception\RuntimeException('Invalid HTTP method specificed for bulk action');
break;
}
} catch (ServiceException\ExceptionInterface $ex) {
$result = new JsonModel(array('api-problem' => new ApiProblem($ex->getCode(), $ex)));
}
if (!$result instanceof JsonModel && !$result instanceof Response) {
throw new Exception\RuntimeException(sprintf('Expected to receive a JsonModel or Response object, received %s', is_object($result) ? get_class($result) : gettype($result)));
}
if ($result instanceof Response) {
$responses[] = array('code' => $result->getStatusCode(), 'headers' => $this->getResponse()->getHeaders()->toArray(), 'body' => null);
if (!$result->isSuccess()) {
$errors = true;
}
continue;
}
$problem = $result->getVariable('api-problem');
if ($problem instanceof ApiProblem) {
$responses[] = array('code' => $problem->status, 'headers' => array('content-type' => 'application/api-problem+json'), 'body' => $problem->toArray());
$errors = true;
} else {
$responses[] = array('code' => $this->getResponse()->getStatusCode(), 'headers' => $this->getResponse()->getHeaders()->toArray(), 'body' => $result->getVariables());
}
}
if ($errors) {
$this->getResponse()->setStatusCode(Response::STATUS_CODE_207);
} else {
switch ($this->getRequest()->getMethod()) {
case 'POST':
$this->getResponse()->setStatusCode(Response::STATUS_CODE_201);
break;
case 'PUT':
case 'PATCH':
$this->getResponse()->setStatusCode(Response::STATUS_CODE_200);
break;
case 'DELETE':
$this->getResponse()->setStatusCode(Response::STATUS_CODE_204);
break;
}
}
return new JsonModel(array('responses' => $responses));
}