reject() public method

Create a collection of all elements that do not pass a given truth test.
public reject ( callable | mixed $callback ) : static
$callback callable | mixed
return static
Example #1
0
 /**
  * Compile the final form
  *
  * @return string
  */
 protected function generateForm()
 {
     $form = $this->generateTag($this->form->pull(0));
     /**
      * Remove Empty Items
      */
     $this->form = $this->form->reject(function ($obj) {
         return $obj instanceof Collection ? $obj->isEmpty() : false;
     });
     return $this->form->map(function ($item) {
         /**
          * Remove ErrorBox if there is no error
          */
         if ($item instanceof Collection && $item->get('element') == 'errorMessage' && $item->get('errors') === null) {
             return false;
         }
         /**
          * Generate tag if $item is not empty
          */
         if ($item instanceof Collection) {
             /**
              * Detect Errors
              */
             $error = $this->appendErrors($item);
             return $this->wrap($item, $error);
         }
         /**
          * Return item if it`s just an string
          */
         return $item;
     })->prepend($form)->implode('');
 }
Example #2
0
 /**
  * @param array $query
  * @return array
  */
 public function removeItems(array $query)
 {
     $result = [];
     $items = $this->_items->reject(function ($value) use($query, $result) {
         foreach ($query as $k => $v) {
             if (isset($value['buyable'][$k]) and $value['buyable'][$k] != $v) {
                 return false;
             }
         }
         $this->_totalPrice -= $value['buyable']['price'] * $value['amount'];
         $result[] = $value;
         return true;
     });
     $this->_items = $items;
     return $result;
 }
 /**
  * Pop Criteria
  *
  * @param $criteria
  *
  * @return $this
  */
 public function popCriteria($criteria)
 {
     $this->criteria = $this->criteria->reject(function ($item) use($criteria) {
         if (is_object($item) && is_string($criteria)) {
             return get_class($item) === $criteria;
         }
         if (is_string($item) && is_object($criteria)) {
             return $item === get_class($criteria);
         }
         return get_class($item) === get_class($criteria);
     });
     return $this;
 }
Example #4
0
 protected function displayConnectionErrors(Collection $backupDestinationStatuses)
 {
     $unreachableBackupDestinationStatuses = $backupDestinationStatuses->reject(function (BackupDestinationStatus $backupDestinationStatus) {
         return $backupDestinationStatus->isReachable();
     });
     if ($unreachableBackupDestinationStatuses->isEmpty()) {
         return;
     }
     $this->warn('');
     $this->warn('Unreachable backup destinations');
     $this->warn('-------------------------------');
     $unreachableBackupDestinationStatuses->each(function (BackupDestinationStatus $backupStatus) {
         $this->warn("Could not reach backups for {$backupStatus->backupName()} on disk {$backupStatus->getFilesystemName()} because:");
         $this->warn($backupStatus->connectionError()->getMessage());
         $this->warn('');
     });
 }
Example #5
0
 /**
  * @param $level
  *
  * @return \Illuminate\Support\Collection|static
  */
 protected function filterNotifications($level)
 {
     if (is_string($level)) {
         $level = explode('|', $level);
     }
     if (is_array($level)) {
         $levels = [0 => 0];
         foreach ($level as $l) {
             $l = array_get($this->levels, $l, 0);
             $levels[$l] = $l;
         }
         $notifications = $this->messages->reject(function ($notification) use($levels) {
             return !array_key_exists($notification['sort'], $levels);
         });
         return $notifications;
     }
     return new Collection();
 }
 /**
  * @param CommandContextInterface $commandContext
  * @return Collection
  */
 protected function compile(CommandContextInterface $commandContext)
 {
     $this->logFile = storage_path('logs/async/' . (string) round(microtime(true) * 1000) . mt_rand(1, 10000) . '.log');
     $memoryLimit = config('satis.memory_limit');
     $buildVerbosity = config('satis.build_verbosity');
     $chunks = new Collection(['php' . ($memoryLimit !== null ? ' -dmemory_limit=' . $memoryLimit : ''), sprintf($this->executable, DIRECTORY_SEPARATOR), $this->command . ($buildVerbosity !== null ? ' -' . $buildVerbosity : ''), $this->configPath, $this->buildDirectory]);
     if ($this->item !== null) {
         $chunks->push($this->item);
     }
     $chunks->push($commandContext->getOutputRedirection($this->logFile));
     $chunks->push($commandContext->getShouldUnlockOnCompletion());
     foreach (['http', 'https'] as $protocol) {
         $proxy = $this->proxySettings->get($protocol);
         if ($proxy !== null) {
             $chunks->prepend(strtoupper($protocol) . '_PROXY=' . $proxy);
         }
     }
     $chunks->reject(function ($commandChunk) {
         return trim($commandChunk) === '';
     });
     return $chunks;
 }
Example #7
0
 /**
  * Remove permission by id
  * 
  * @param mixed $id
  * @return void
  */
 public function remove($id)
 {
     $this->items->reject(function ($value, $key) use($id) {
         return $value[$this->id] != $id;
     });
 }
Example #8
0
 public function testRejectRemovesElementsPassingTruthTest()
 {
     $c = new Collection(['foo', 'bar']);
     $this->assertEquals(['foo'], $c->reject('bar')->values()->all());
     $c = new Collection(['foo', 'bar']);
     $this->assertEquals(['foo'], $c->reject(function ($v) {
         return $v == 'bar';
     })->values()->all());
     $c = new Collection(['foo', null]);
     $this->assertEquals(['foo'], $c->reject(null)->values()->all());
     $c = new Collection(['foo', 'bar']);
     $this->assertEquals(['foo', 'bar'], $c->reject('baz')->values()->all());
     $c = new Collection(['foo', 'bar']);
     $this->assertEquals(['foo', 'bar'], $c->reject(function ($v) {
         return $v == 'baz';
     })->values()->all());
     $c = new Collection(['id' => 1, 'primary' => 'foo', 'secondary' => 'bar']);
     $this->assertEquals(['primary' => 'foo', 'secondary' => 'bar'], $c->reject(function ($item, $key) {
         return $key == 'id';
     })->all());
 }
Example #9
0
 public function removeProcessedUrlsFromPending()
 {
     $this->pending = $this->pending->reject(function (CrawlUrl $crawlUrl) {
         return $this->contains($this->processed, $crawlUrl);
     })->values();
 }
Example #10
0
 protected function includedDirectories() : array
 {
     return $this->includeFilesAndDirectories->reject(function ($path) {
         return is_file($path);
     })->toArray();
 }