本文整理汇总了PHP中Illuminate\Support\Arr::isAssoc方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::isAssoc方法的具体用法?PHP Arr::isAssoc怎么用?PHP Arr::isAssoc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::isAssoc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: instanceFromRequest
/**
* Create instance from reques
*
* @param string $method
* @param null|int|string $id
* @param array|\Illuminate\Contracts\Support\Arrayable $params
* @return $this|array
*/
protected static function instanceFromRequest($method, $id = null, $params = [])
{
$response = static::requestToArray($method, $id, $params);
if (Arr::isAssoc($response)) {
return new static($response);
}
return Collection::makeOf(static::class, $response);
}
示例2: getPostgisFields
public function getPostgisFields()
{
if (property_exists($this, 'postgisFields')) {
return Arr::isAssoc($this->postgisFields) ? array_keys($this->postgisFields) : $this->postgisFields;
//Returns the non-associative array that doesn't define the geometry type.
} else {
throw new PostgisFieldsNotDefinedException(__CLASS__ . ' has to define $postgisFields');
}
}
示例3: buildMorphMapFromModels
/**
* Builds a table-keyed array from model class names.
*
* @param string[]|null $models
* @return array|null
*/
protected static function buildMorphMapFromModels(array $models = null)
{
if (is_null($models) || Arr::isAssoc($models)) {
return $models;
}
$tables = array_map(function ($model) {
return (new $model())->getEndpoint();
}, $models);
return array_combine($tables, $models);
}
示例4: setRows
public function setRows($rows = [])
{
if (Arr::isAssoc($rows)) {
foreach ($rows as $key => $item) {
$this->rows[] = [$key, $item];
}
return $this;
}
$this->rows = $rows;
return $this;
}
示例5: getFillable
/**
* Get the fillable attributes for the model.
*
* @return array
*/
public function getFillable()
{
if ($fillable = $this->fillable) {
if (Arr::isAssoc($fillable)) {
return $fillable;
}
$keys = array_values($fillable);
$types = array_fill(0, count($keys), 'string');
return array_combine($keys, $types);
}
}
示例6: macroSendHandler
/**
* Send email the handler method
*
* @param int|static $resource
* @param array $options
* @return bool
*/
protected static function macroSendHandler($resource, ...$options)
{
if (static::isResource($resource)) {
$resource = $resource->id;
}
if ($isAssoc = count($options) == 1 && Arr::isAssoc($options[0])) {
$options = $options[0];
}
if (!$isAssoc) {
$options = ['emails' => $options];
}
$response = static::request('POST', $resource . '/email', $options);
return $response->getStatusCode() === 200;
}
示例7: add
public function add($label, $data = [], $fillColor = '')
{
if (is_array($label)) {
if (Arr::isAssoc($label)) {
$this->data[] = $label;
} else {
foreach ($label as $item) {
call_user_func_array([$this, 'add'], $item);
}
}
return $this;
}
$this->data['datasets'][] = ['label' => $label, 'data' => $data, 'fillColor' => $fillColor];
return $this;
}
示例8: prepareArrayLines
/**
* Prepare array elements for formatting.
*
* @param array $array
* @return array
*/
protected static function prepareArrayLines(array $array)
{
$isAssoc = Arr::isAssoc($array);
array_walk($array, function (&$value, $index, $withIndexes = false) {
if (is_array($value)) {
$value = self::formatArray($value);
} else {
$value = self::formatScalar($value);
}
if ($withIndexes) {
$value = self::formatScalar($index) . ' => ' . $value;
}
}, $isAssoc);
return $array;
}
示例9: add
public function add($label, $value = '', $color = '', $highlight = '')
{
if (is_array($label)) {
if (Arr::isAssoc($label)) {
$this->data[] = $label;
} else {
foreach ($label as $item) {
call_user_func_array([$this, 'add'], $item);
}
}
return $this;
}
$this->data[] = ['label' => $label, 'value' => $value, 'color' => $color, 'highlight' => $highlight];
return $this;
}
示例10: prepareInsert
/**
* Prepare input data for insert.
*
* @param $inserts
* @return array
*/
public function prepareInsert($inserts)
{
$first = current($inserts);
if (is_array($first) && Arr::isAssoc($first)) {
$inserts = Arr::dot($inserts);
}
foreach ($inserts as $column => $value) {
if (is_null($field = $this->getFieldByColumn($column))) {
unset($inserts[$column]);
continue;
}
if (method_exists($field, 'prepare')) {
$inserts[$column] = $field->prepare($value);
}
}
$prepared = [];
foreach ($inserts as $key => $value) {
Arr::set($prepared, $key, $value);
}
return $prepared;
}
示例11: isValidValue
/**
* Validate the value as safe for this object
*
* @param mixed $value the value to test
* @return boolean
*/
private function isValidValue($value)
{
return is_scalar($value) || is_array($value) && !$this->arrHelper->isAssoc($value) && count($value) === count(array_filter($value, 'is_scalar'));
}
示例12: processRelationship
/**
* Process model relationship
*
* @param array $data
* @param array $relationships
* @param string $relationshipMethod
* @return void
*/
protected function processRelationship(&$data, $relationships, $relationshipMethod)
{
if (!isset($data['relationship'])) {
$data['relationship'] = [];
}
$relationships = Arr::isAssoc($relationships) ? [$relationships] : $relationships;
foreach ($relationships as $relationship) {
$method = $relationshipMethod . 'Relationship';
$data['relationship'][] = $this->grammar->{$method}($relationship);
}
}
示例13: structureMatches
/**
* Structure the matches array.
*
* @param \Phroggyy\Discover\Contracts\Searchable $model
* @param array $query
* @return array|string
*/
private function structureMatches(Searchable $model, $query)
{
// If the query is an array of arrays, we assume the
// developer knows exactly what they're doing and
// are providing a complete match query for us.
if (is_array($query) && !Arr::isAssoc($query)) {
return $query;
}
$key = '';
// If the search index turns out to actually be nested, we
// want to make sure we use the name of the subdocument
// when such a query is performed. This is necessary.
if ($this->indexIsNested($model->getSearchIndex())) {
$key = $this->retrieveNestedIndex($model->getSearchIndex())[1] . '.';
}
// If the query is just a string, we assume the user
// intends to just do a simple match query on the
// default search field defined in their model.
if (is_string($query)) {
return [['match' => [$key . $model->getDefaultSearchField() => $query]]];
}
$query = Collection::make($query);
return $query->map(function ($constraint, $property) use($key) {
if (strpos($property, '.') === false) {
$property = $key . $property;
}
return ['match' => [$property => $constraint]];
})->values()->all();
}
示例14: normalizeAclPresence
/**
* Normalizes ACL presence data to an array of ACLPresence instances.
*
* @param $data
* @return AclPresenceInterface[]
*/
protected function normalizeAclPresence($data)
{
if ($data instanceof AclPresenceInterface) {
$data = [$data];
} elseif (is_array($data) && !Arr::isAssoc($data)) {
$presences = [];
foreach ($data as $nestedData) {
$presences[] = new AclPresence($nestedData);
}
$data = $presences;
} else {
$data = [new AclPresence($data)];
}
/** @var AclPresenceInterface[] $data */
// Now normalized to an array with one or more ACL presences.
// Make sure the permission children are listed as simple strings.
foreach ($data as $index => $presence) {
$children = $presence->permissions() ?: [];
if ($children instanceof Arrayable) {
$children = $children->toArray();
}
if (!is_array($children)) {
$children = [$children];
}
$data[$index]->setPermissions($children);
}
return $data;
}
示例15: getCastFromFillable
/**
* Get casts from fillable attribute
* When fillable is assoc the value is the type
*
* @return array
*/
protected function getCastFromFillable()
{
$fillable = $this->fillable;
if (Arr::isAssoc($fillable)) {
return $fillable;
}
return [];
}