本文整理汇总了PHP中Illuminate\Support\Collection::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::isEmpty方法的具体用法?PHP Collection::isEmpty怎么用?PHP Collection::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getModules
/**
* Modules of installed or not installed.
*
* @param bool $installed
*
* @return \Illuminate\Support\Collection
*/
public function getModules($installed = false)
{
if ($this->modules->isEmpty()) {
if ($this->files->isDirectory($this->getModulePath()) && !empty($directories = $this->files->directories($this->getModulePath()))) {
(new Collection($directories))->each(function ($directory) use($installed) {
if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
$package = new Collection(json_decode($this->files->get($file), true));
if (Arr::get($package, 'type') == 'notadd-module' && ($name = Arr::get($package, 'name'))) {
$module = new Module($name);
$module->setAuthor(Arr::get($package, 'authors'));
$module->setDescription(Arr::get($package, 'description'));
if ($installed) {
$module->setInstalled($installed);
}
if ($entries = data_get($package, 'autoload.psr-4')) {
foreach ($entries as $namespace => $entry) {
$module->setEntry($namespace . 'ModuleServiceProvider');
}
}
$this->modules->put($directory, $module);
}
}
});
}
}
return $this->modules;
}
示例2: getExtensions
/**
* Extension list.
*
* @return \Illuminate\Support\Collection
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function getExtensions()
{
if ($this->extensions->isEmpty()) {
if ($this->files->isDirectory($this->getExtensionPath()) && !empty($vendors = $this->files->directories($this->getExtensionPath()))) {
collect($vendors)->each(function ($vendor) {
if ($this->files->isDirectory($vendor) && !empty($directories = $this->files->directories($vendor))) {
collect($directories)->each(function ($directory) {
if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
$package = new Collection(json_decode($this->files->get($file), true));
if (Arr::get($package, 'type') == 'notadd-extension' && ($name = Arr::get($package, 'name'))) {
$extension = new Extension($name);
$extension->setAuthor(Arr::get($package, 'authors'));
$extension->setDescription(Arr::get($package, 'description'));
if ($entries = data_get($package, 'autoload.psr-4')) {
foreach ($entries as $namespace => $entry) {
$extension->setEntry($namespace . 'Extension');
}
}
$this->extensions->put($directory, $extension);
}
}
});
}
});
}
}
return $this->extensions;
}
示例3: victor
/**
* Get the winner of the Round
* @return bool|Player
*/
public function victor()
{
if ($this->battles->isEmpty()) {
return false;
}
return $this->battles->last()->victor();
}
示例4: getAllPermissions
/**
* @param GrantableInterface $grantable
*
* @return array
*/
public function getAllPermissions(GrantableInterface $grantable)
{
if (is_null($this->permissions) || $this->permissions->isEmpty()) {
$this->initialize($grantable);
}
$result = $this->permissions->all();
array_filter($result, function ($item) {
return $item;
});
return array_keys($result);
}
示例5: postProcess
/**
* Runs the result for retrieval calls to the repository
* through postprocessing.
*
* @param Collection|Model|null $result the result of the query, ready for postprocessing
* @return Model|Collection|null
*/
public function postProcess($result)
{
// determine whether there is anything to process
if (is_null($result) || is_a($result, Collection::class) && $result->isEmpty()) {
return $result;
}
// check if there is anything to do process it through
if ($this->postProcessors->isEmpty()) {
return $result;
}
// for each Model, instantiate and apply the processors
if (is_a($result, Collection::class)) {
$result->transform(function ($model) {
return $this->applyPostProcessorsToModel($model);
});
} elseif (is_a($result, AbstractPaginator::class)) {
// result is paginate() result
// do not apply postprocessing for now (how would we even do it?)
return $result;
} else {
// result is a model
$result = $this->applyPostProcessorsToModel($result);
}
return $result;
}
示例6: apply
/**
* @param Collection $collection
* @return Collection
*/
public function apply(Collection $collection)
{
if (!$collection->isEmpty() && !empty($this->criteria)) {
foreach ($this->criteria as $key => $parameters) {
// Парамментры могут быть пустыми
if (empty($parameters)) {
continue;
}
// Фильтруем значение
$collection = $collection->filter(function ($value, $k) use($key, $parameters) {
foreach ($parameters as $param) {
// Получем опреатор в зависимости от ключа
$exp = $this->getSign($key);
/** @var Parameters $param*/
if (count($param->getAttributes()) === 2) {
$attributes = $param->getAttributes();
return eval('return $value->{head($attributes)}' . $exp . ' $value->{last($attributes)};');
} else {
if (count($param->getAttributes()) === 1 && !empty($param->getValue())) {
return eval('return $value->{head($param->getAttributes())} ' . $exp . ' $param->getValue();');
}
}
}
return false;
});
}
}
return $collection;
}
示例7: validate
public function validate()
{
if ($this->row_orders->isEmpty()) {
$this->errors->add("row_orders", L::t("There is no product in the cart."));
return false;
}
return true;
}
示例8: determineBaseline
private function determineBaseline()
{
$baselines = BaselineFile::account($this->account)->orderBy('path', 'asc')->get();
//-- convert to File::class
$this->baseline = BaselineFile::toFiles($baselines);
if ($this->baseline->isEmpty() && !$this->first_scan) {
$this->alert("**Probable Compromise**<br> Empty baseline table (ALL baseline files are missing or deleted)!");
}
}
示例9: getFromIds
public function getFromIds(Collection $idCollection, $method, $force = false)
{
if ($idCollection->isEmpty()) {
return $idCollection;
}
return $idCollection->unique()->map(function ($item, $key) use($force, $method) {
return call_user_func([$this, $method], $item, $force);
});
}
示例10: collection
/**
* Bind a collection to a transformer and start building a response.
*
* @param \Illuminate\Support\Collection $collection
* @param object $transformer
* @param array $parameters
* @param \Closure $after
*
* @return \Dingo\Api\Http\ResponseBuilder
*/
public function collection(Collection $collection, $transformer, array $parameters = [], Closure $after = null)
{
if ($collection->isEmpty()) {
$class = get_class($collection);
} else {
$class = get_class($collection->first());
}
$binding = $this->transformer->register($class, $transformer, $parameters, $after);
return new ResponseBuilder($collection, $binding);
}
示例11: getPaymentTypes
/**
* @return \Illuminate\Support\Collection
* @throws \Artem328\LaravelYandexKassa\Exceptions\YandexKassaNoPaymentTypesProvidedException
*/
public function getPaymentTypes()
{
if ($this->paymentTypes === null) {
$this->paymentTypes = collect(config('yandex_kassa.payment_types', []));
}
if ($this->paymentTypes->isEmpty()) {
throw new YandexKassaNoPaymentTypesProvidedException();
}
return $this->paymentTypes;
}
示例12: __get
/**
* Gets the current flash level
* and message using accessor methods.
*
* @param string $attribute
* @return string|null
*/
public function __get($attribute)
{
if ($this->current->isEmpty()) {
return null;
}
$getter = 'get' . $attribute;
if (method_exists($this, $getter)) {
return $this->{$getter}();
}
return null;
}
示例13: getThemes
/**
* Themes of installed or not installed.
*
* @param bool $installed
*
* @return \Illuminate\Support\Collection
*/
public function getThemes($installed = false)
{
if ($this->themes->isEmpty()) {
if ($this->files->isDirectory($this->getThemePath()) && !empty($directories = $this->files->directories($this->getThemePath()))) {
(new Collection($directories))->each(function ($directory) use($installed) {
if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
$package = new Collection(json_decode($this->files->get($file), true));
if (Arr::get($package, 'type') == 'notadd-extension' && ($name = Arr::get($package, 'name'))) {
$module = new Theme($name, Arr::get($package, 'authors'), Arr::get($package, 'description'));
if ($installed) {
$module->setInstalled($installed);
}
$this->themes->put($directory, $module);
}
}
});
}
}
return $this->themes;
}
示例14: outputAssets
/**
* Output the collection assets
* @param \Illuminate\Support\Collection $collection
* @param string $type
* @return string
*/
public function outputAssets($collection, $type)
{
if (!$collection->isEmpty()) {
$link = $this->determineLinkingAttribute($type);
$output = array();
foreach ($collection->all() as $name => $attr) {
$output[$name] = $this->createAssetTag($type, $link, $attr);
}
return implode($output, '');
}
}
示例15: table
/**
* Set the table name or get the table name.
* @param $name string
* @return $this|string
*/
public function table($name = null)
{
if (!$name) {
return $this->table;
}
$this->table = $name;
if ($this->labels->isEmpty()) {
$this->guessLabels($name);
}
return $this;
}