/** * @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); }
/** * Generate GraphQL Schema. * * @return \GraphQL\Schema */ public function buildSchema() { // Initialize types $this->types()->each(function ($type, $key) { $type = $this->type($key); if (method_exists($type, 'getInterfaces') && !empty($type->getInterfaces())) { $this->typesWithInterfaces->push($type); } }); $queryFields = $this->queries()->merge($this->connections()->toArray()); $mutationFields = $this->mutations(); $queryType = $this->generateSchemaType($queryFields, 'Query'); $mutationType = $this->generateSchemaType($mutationFields, 'Mutation'); return new Schema(['query' => $queryType, 'mutation' => $mutationType, 'types' => $this->typesWithInterfaces->all()]); }
/** * Loads the Eloquent models for the indexed documents found by the search. * Uses eager loading for the specified relations array. * * @param array|null $with * @return \Elodex\Collection */ protected function loadItems(array $with = null) { $ids = array_keys($this->documents->all()); $class = $this->entityClass; // Eager load the index relations by default. if (is_null($with)) { $with = (new $class())->getIndexRelations(); } // Load the Eloquent models from the DB. $collection = $class::with($with)->find($ids); // The database query returns the items in a random order which means // a previously specified sort order in the document search will be lost. // So we need to manually bring the result in the desired order. $dictionary = $collection->getDictionary(); $sorted = []; foreach ($ids as $id) { $model = $dictionary[$id]; // Fill the model with index metadata. if (isset($this->metadata[$id]['_score'])) { $model->setIndexScore($this->metadata[$id]['_score']); } if (isset($this->metadata[$id]['_version'])) { $model->setIndexVersion($this->metadata[$id]['_version']); } $sorted[$id] = $model; } return new Collection($sorted); }
/** * Mutate an XML element based on the given data. * * @param Collection $data * @param SimpleXMLElement $element * @param object $object The object. * @param mixed $providedKey * @return SimpleXMLElement The new element. */ protected function prepareElement(Collection $data, SimpleXMLElement $element, $object, $providedKey = null) : SimpleXMLElement { foreach ($data->all() as $value) { $this->prepareWithReflection($value, $element, $object); } return $element; }
public function testBulkOperationException() { $bulkItems = new Collection([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]]); $items = [['create' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 1, 'status' => 409, 'error' => ['type' => 'document_already_exists_exception', 'reason' => '[my_index][1]: document already exists', 'shard' => '1', 'index' => 'my_index']]], ['update' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 2, 'status' => 404, 'error' => ['type' => 'document_missing_exception', 'reason' => '[my_index][2]: document missing', 'shard' => '-1', 'index' => 'my_index']]], ['delete' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 3, 'status' => 404, 'found' => false]], ['index' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 4, 'status' => 200]]]; $e = BulkOperationException::createForResults($items, $bulkItems->all()); $failedItems = $e->getFailedItems(); $failedIds = Arr::pluck($failedItems, 'id'); $this->assertEquals([1, 2], $failedIds); }
/** * @return string */ public function render() { $value = $this->choices->all(); if (!empty($this->label)) { $label = Element::create('label', $this->label); $this->nest($label, 'label'); $this->nest('<br>'); } $this->nest($value, 'choices'); return parent::render(); }
/** * 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, ''); } }
/** * Transform row column by collection. * * @param array $row * @param \Illuminate\Support\Collection $columns * @param string $type * @return array */ protected function buildColumnByCollection(array $row, Collection $columns, $type = 'printable') { $results = []; foreach ($columns->all() as $column) { if ($column[$type]) { $data = array_get($row, $column['data']); $results[$column['title']] = $type == 'exportable' ? strip_tags($data) : $data; } } return $results; }
public function run() { if ($this->rules instanceof Collection) { $this->rules = $this->rules->all(); } if (is_string($this->rules) && is_subclass_of($this->rules, BaseInterceptor::class)) { $this->rules = app($this->rules)->apply($this->actor, $this->data, $this->obj); } $validator = app('validator')->make($this->data->all(), $this->rules, $this->messages, $this->labels); if ($validator->fails()) { abort(400, json_encode($validator->errors()->all())); } return $validator; }
/** * Transform row column by collection. * * @param array $row * @param \Illuminate\Support\Collection $columns * @param string $type * @return array */ protected function buildColumnByCollection(array $row, Collection $columns, $type = 'printable') { $results = []; foreach ($columns->all() as $column) { if ($column[$type]) { $title = $column['title']; $data = array_get($row, $column['data']); if ($type == 'exportable') { $data = $this->decodeContent($data); $title = $this->decodeContent($title); } $results[$title] = $data; } } return $results; }
public function applyTransform() { $transforms = $this->transforms->all(); $datas = empty($this->inputDatas) ? [] : $this->inputDatas; if (empty($transforms) || empty($datas)) { $this->results = $datas; return $this; } $tmp = []; foreach ($transforms as $transform) { $tmp = Transform::make($transform, $datas); } $this->hasTransForm = TRUE; $this->results = new Collection($tmp); return $this; }
/** * Go * * Goes through all of the registered modules and attempts * to activate them. Performs checks to ensure that modules * that declare dependencies that have not been satisfied * will not be activated. * * Registers any directories with the class loader * * @return void */ public function go() { $this->handlePreRegistered(); $toActivate = $this->registeredModules->all(); // This 'while' loop runs continuously allowing for modules // to be checked multiple times which allows for dependencies. while (count($toActivate) > 0) { foreach ($toActivate as $name => $module) { $canActivate = true; $dependencies = $module->dependencies(); // If we've got dependencies, check them all to make sure all have been activated // before activating this particular module. if (!empty($dependencies)) { foreach ($dependencies as $dependency) { // First off, if this dependency hasn't even been register, we can never // activate this module, so let's skip it and not try again. if (!$this->registeredModules->has($dependency)) { $canActivate = false; $this->dispatcher->fire(self::EVENT_ACTIVATION_FAILED . ' ' . $name, $module); unset($toActivate[$name]); continue; } // At this point, the dependency has been registered but not activated, // so let's skip this module and come back to it. if (!$this->activeModules->has($dependency)) { $canActivate = false; } } } // Now let's activate this sucka! Also, we remove it from the list // so we don't try to activate it again. if ($canActivate) { $this->activeModules->put($name, $module->activate()); $this->dispatcher->fire(self::EVENT_ACTIVE . " {$name}", $module); unset($toActivate[$name]); } } } $this->classLoader->register(); }
/** * @param $value */ protected function handleiSortCol_0($value) { if (Input::get('sSortDir_0') == 'desc') { $direction[$value] = BaseEngine::ORDER_DESC; } else { $direction[$value] = BaseEngine::ORDER_ASC; } $columns = array(); //check if order is allowed if (empty($this->orderColumns)) { $columns[] = array(0 => $value, 1 => $this->getNameByIndex($value)); $this->order($columns, $direction); return; } //prepare order array $cleanNames = array(); foreach ($this->orderColumns as $c) { if (strpos($c, ':') !== FALSE) { $cleanNames[] = substr($c, 0, strpos($c, ':')); } else { $cleanNames[] = $c; } } $iSortingCols = Input::get('iSortingCols'); $sortingCols[] = $value; for ($i = 1; $i < $iSortingCols; $i++) { $isc = Input::get('iSortCol_' . $i); $sortingCols[] = $isc; $direction[$isc] = Input::get('sSortDir_' . $i); } $allColumns = array_keys($this->columns->all()); foreach ($sortingCols as $num) { if (isset($allColumns[$num]) && in_array($allColumns[$num], $cleanNames)) { $columns[] = array(0 => $num, 1 => $this->orderColumns[array_search($allColumns[$num], $cleanNames)]); } } $this->order($columns, $direction); return; }
/** * @return Collection */ public function getAllAttributes() { $all = new Collection(); foreach ($this->attributes as $attr) { $all->put($attr->name, $attr); } foreach ($this->sections->all() as $section) { foreach ($section->getAttributes() as $attr) { $all->put($attr->name, $attr); } } foreach ($this->tabs->all() as $tab) { foreach ($tab->getAttributes() as $attr) { $all->put($attr->name, $attr); } foreach ($tab->getSections() as $section) { foreach ($section as $attr) { $all->put($attr->name, $attr); } } } return $all; }
/** * Takes any kind of collection returned by Maatwebsite\Excel and turns it * into an array of RowCollections. * * This is needed because the library returns a SheetCollection if there are * multiple sheets and a RowCollection if there is only one. * * @see http://www.maatwebsite.nl/laravel-excel/docs/import#results * @param mixed $collection A RowCollection or SheetCollection. * @result \Maatwebsite\Excel\Collections\RowCollection[] */ protected function getSheetArrayFromAnyKindOfCollection(Collection $collection) { if ($collection instanceof RowCollection) { $sheets = [$collection]; } elseif ($collection instanceof SheetCollection) { $sheets = $collection->all(); } else { throw new Exception('Unknown class returned from Excel: ' . get_class($collection)); } return $sheets; }
/** * Return all found projects. * * @return Project[] */ public function getProjects() { return $this->projects->all(); }
public function testPullRemovesItemFromCollection() { $c = new Collection(['foo', 'bar']); $c->pull(0); $this->assertEquals([1 => 'bar'], $c->all()); }
/** * to create a lot of wrapper by using models in Eloquent Collection * * @param \Illuminate\Support\Collection $collection * @param \Illuminate\Database\Eloquent\Model|int $wantedLang language id or specific language model * @param \Illuminate\Database\Eloquent\Model|int $defaultLang language id or specific language model * @return \Illuminate\Support\Collection */ protected function createWrappersInCollection(Collection $collection, $wantedLang, $defaultLang) { $newCollection = new EloquentColl(); $tempCollection = new EloquentColl($collection->all()); while (!$tempCollection->isEmpty()) { $newCollection->add($this->wrapper->createNew($tempCollection->shift(), $wantedLang, $defaultLang)); } return $newCollection; }
public function all() { return $this->messages->all(); }
/** * @return string */ public function render() { $value = $this->choices->all(); $this->setValue($value); return $this->realRender(); }
public function testGettingCollectionAssetsWithDefaultOrdering() { $this->directory->shouldReceive('getAssets')->andReturn($expected = new IlluminateCollection(array($this->getAssetInstance('bar.css', 'path/to/bar.css', 'stylesheets', 1), $this->getAssetInstance('baz.css', 'path/to/baz.css', 'stylesheets', 2)))); $this->assertEquals($expected->all(), $this->collection->getAssets('stylesheets')->all()); }
/** * @inheritdoc */ public function results() { return $this->collection->all(); }
/** * Convert the given list into an array. * * @param array|\Illuminate\Support\Collection $list * @return array */ protected function toArray($list) { return $list instanceof Collection ? $list->all() : $list; }
/** * Setting the emails attribute * * @param \Illuminate\Support\Collection $value */ public function setEmailsAttribute($value) { //Json encode and return $this->attributes['emails'] = $value != '' && $value != null ? json_encode($value->all()) : ''; }
/** * Get an array representing the properties of a collection. * * @param \Illuminate\Support\Collection $collection * @return array */ public static function castCollection(Collection $collection) { return [Caster::PREFIX_VIRTUAL . 'all' => $collection->all()]; }
/** * Determine if the given item exists. * * @param mixed $key * @return bool */ public function offsetExists($key) { return array_key_exists($key, $this->items->all()); }
/** * Get an iterator for the items. * * @return \ArrayIterator */ public function getIterator() { return new ArrayIterator($this->items->all()); }
/** * Renders the menu as a HTML string and returns it. * * @return string */ public function toHtml() { return $this->viewFactory->make($this->config['view'], ['menuItems' => $this->items->all()])->render(); }
/** * Set values to collection. * * @param Collection $values */ public function setValues(Collection $values) { $this->items = $values->all(); }
/** * Check the results returned by a bulk operation. * * @param array $results * @param \Illuminate\Support\Collection $collection * @return void * @throws \Elodex\Exceptions\BulkOperationException */ protected function checkBulkResults(array $results, BaseCollection $collection) { if (isset($results['errors']) && $results['errors'] === true) { throw BulkOperationException::createForResults($results['items'], $collection->all()); } }