本文整理汇总了PHP中Illuminate\Support\Collection::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::has方法的具体用法?PHP Collection::has怎么用?PHP Collection::has使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
/**
* @param WithInterface|DataInterface|ModelInterface $config
* @return mixed
*/
public function apply($config)
{
if (!($config instanceof WithInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
return;
}
if ($config->with()->isEmpty()) {
return;
}
$this->config = $config;
$this->allowed = $config->with();
foreach ($this->allowed as $key => $value) {
if (is_numeric($key)) {
$this->allowed->forget($key)->put($value, '*');
}
}
foreach (explode('|', $config->data()->get('with', '')) as $with) {
$parts = explode(':', $with);
if (count($parts) == 0) {
continue;
}
if (!$this->allowed->has($parts[0])) {
continue;
}
$this->processWith($parts[0], isset($parts[1]) ? $parts[1] : '');
}
if (count($this->approved) > 0) {
$config->model($config->model()->with($this->approved));
}
}
示例2: loadRules
/**
* @param string $key
*
* @return array
*/
protected function loadRules($key)
{
if (!$this->rules->has($key)) {
$this->rules->put($key, $this->loadRulesFromFile($key));
}
return $this->rules->get($key);
}
示例3: instance
/**
* Get instance of type.
*
* @param string $name
* @param bool $fresh
* @return \GraphQL\Type\Definition\ObjectType
*/
public function instance($name, $fresh = false)
{
if (!$fresh && $this->instances->has($name)) {
return $this->instances->get($name);
}
$type = $this->getType($name)->resolve();
$instance = $type instanceof Model ? (new EloquentType($type, $name))->toType() : $type->toType();
$this->instances->put($name, $instance);
return $instance;
}
示例4: item
/**
* Add a new Item (or edit an existing item) to the Group
*
* @param string $name
* @param callable $callback
*
* @return Item
*/
public function item($name, Closure $callback = null)
{
if ($this->items->has($name)) {
$item = $this->items->get($name);
} else {
$item = $this->container->make('Maatwebsite\\Sidebar\\Item');
$item->name($name);
}
$this->call($callback, $item);
$this->addItem($item);
return $item;
}
示例5: mutateRecords
/**
* @param $records
*
* @return mixed
*/
public function mutateRecords($records)
{
$_ignored = ['id', 'sortorder', 'updated_at', 'created_at'];
foreach ($records as $model) {
$toLoop = array_except($model->toArray(), $_ignored);
foreach ($toLoop as $k => $r) {
if ($this->attributes->has($k)) {
$model->{$k} = $this->attributes[$k]->getDisplayValue($model);
}
}
}
return $records;
}
示例6: instance
/**
* Get instance of connection type.
*
* @param string $name
* @param string|null $parent
* @param bool $fresh
* @return \Nuwave\Lighthouse\Support\Definition\Fields\ConnectionField
*/
public function instance($name, $parent = null, $fresh = false)
{
$instanceName = $this->instanceName($name);
$typeName = $this->typeName($name);
if (!$fresh && $this->instances->has($instanceName)) {
return $this->instances->get($instanceName);
}
$key = $parent ? $parent . '.' . $instanceName : $instanceName;
$nodeType = $this->getSchema()->typeInstance($typeName);
$instance = $this->getInstance($name, $nodeType);
$this->instances->put($key, $instance);
return $instance;
}
示例7: preInstall
/**
* @return void
*/
public function preInstall()
{
if ($this->extension->has('autoload')) {
$autoload = collect($this->extension->get('autoload'));
$autoload->has('classmap') && collect($autoload->get('classmap'))->each(function ($value) {
$path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value)) . '/';
if (!in_array($path, $this->backup['autoload']['classmap'])) {
$this->backup['autoload']['classmap'][] = $path;
}
});
$autoload->has('files') && collect($autoload->get('files'))->each(function ($value) {
$path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value));
if (!in_array($path, $this->backup['autoload']['files'])) {
$this->backup['autoload']['files'][] = $path;
}
});
$autoload->has('psr-0') && collect($autoload->get('psr-0'))->each(function ($value, $key) {
$path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value)) . '/';
$this->backup['autoload']['psr-0'][$key] = $path;
});
$autoload->has('psr-4') && collect($autoload->get('psr-4'))->each(function ($value, $key) {
$path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value)) . '/';
$this->backup['autoload']['psr-4'][$key] = $path;
});
}
if ($this->extension->has('require')) {
$require = collect($this->extension->get('require'));
$require->each(function ($version, $name) {
$this->backup['require'][$name] = $version;
});
}
}
示例8: getFilter
/**
* Get single filter by key
*
* @param $key
* @param string $default_value Default value if key is not found
*
* @return mixed|string
*/
public function getFilter($key, $default_value = '')
{
if ($this->filters->has($key)) {
return $this->filters[$key];
}
return $default_value;
}
示例9: parse
/**
* Parse parameters and return the altering classes
*
* @param mixed $parameters
* @return \Illuminate\Support\Collection
*/
public function parse($parameters)
{
// Fetch parameters. If the variable is an array nothing will happen.
// If it's a string, it will be tokenized and will return as an array.
$params = $this->getParameters($parameters);
$collection = new Collection();
foreach ($params as $token => $value) {
// create the manipulator
$manipulator = $this->createManipulator($token);
$className = get_class($manipulator);
// get the classname
if ($collection->has($className)) {
$manipulator = $collection->get($className);
}
// set values
if ($token === self::REQUEST_PARAM_WIDTH) {
$manipulator->setWidth($value);
} elseif ($token === self::REQUEST_PARAM_HEIGHT) {
$manipulator->setHeight($value);
}
// put in the colllection
$collection->put($className, $manipulator);
}
return $collection;
}
示例10: getUserThrottles
/**
* Returns the user throttles collection.
*
* @param \Cartalyst\Sentinel\Users\UserInterface $user
* @return \Illuminate\Support\Collection
*/
protected function getUserThrottles(UserInterface $user)
{
if (!$this->userThrottles->has($user->getUserId())) {
$this->userThrottles[$user->getUserId()] = $this->loadUserThrottles($user);
}
return $this->userThrottles[$user->getUserId()];
}
示例11: instance
/**
* Get instance of edge type.
*
* @param string $name
* @param bool $fresh
* @param ObjectType|null $type
* @return \GraphQL\Type\Definition\ObjectType|null
*/
public function instance($name, $fresh = false, ObjectType $type = null)
{
$instanceName = $this->instanceName($name);
if (!$fresh && $this->instances->has($instanceName)) {
return $this->instances->get($instanceName);
}
if ($name instanceof ConnectionEdge) {
$instance = $this->createEdge($name);
$this->instances->put($instanceName, $instance);
return $instance;
} elseif ($type) {
$instance = $this->createInstance($name, $type);
$this->instances->put($name, $instance);
return $instance;
}
return null;
}
示例12: __call
public function __call($name, $arguments)
{
$prefix = substr($name, 0, 3);
$property = snake_case(substr($name, 3));
if ($prefix === 'get' && $this->attributes->has($property)) {
return $this->get($property);
}
throw new \InvalidArgumentException();
}
示例13: addOrCreateIncome
/**
* @param TransactionJournal $entry
*/
public function addOrCreateIncome(TransactionJournal $entry)
{
$accountId = $entry->account_id;
if (!$this->incomes->has($accountId)) {
$newObject = new stdClass();
$newObject->amount = strval(round($entry->amount, 2));
$newObject->name = $entry->name;
$newObject->count = 1;
$newObject->id = $accountId;
$this->incomes->put($accountId, $newObject);
} else {
bcscale(2);
$existing = $this->incomes->get($accountId);
$existing->amount = bcadd($existing->amount, $entry->amount);
$existing->count++;
$this->incomes->put($accountId, $existing);
}
}
示例14: removeCriteriaOnce
/**
* Removes Criteria, but only for the next call, resets to default afterwards
* Note that this does NOT work for specific criteria exclusively, it resets
* to default for ALL Criteria.
*
* In effect, this adds a NullCriteria to onceCriteria by key, disabling any criteria
* by that key in the normal criteria list.
*
* @param string $key
* @return $this
*/
public function removeCriteriaOnce($key)
{
// if not present in normal list, there is nothing to override
if (!$this->criteria->has($key)) {
return $this;
}
// override by key with Null-value
$this->onceCriteria->put($key, new NullCriteria());
return $this;
}
示例15: setOptions
/**
* Mass-assign options for given fields.
* @param $array array column=>options
* @return $this
*/
public function setOptions($array)
{
foreach ($array as $field => $options) {
if (!$this->fields->has($field)) {
continue;
}
$this->getField($field)->options = $options;
}
return $this;
}