make() public static method

Create a new collection instance if the value isn't one already.
public static make ( mixed $items = [] ) : static
$items mixed
return static
 /**
  * QueryFilter constructor.
  *
  * @param InputParser $parser
  * @param Collection $collection
  * @param Container $app
  */
 public function __construct(InputParser $parser, Collection $collection, Container $app)
 {
     $this->parser = $parser;
     $this->collection = $collection;
     $this->filters = $parser->getFilters();
     $this->sorts = $parser->getSorts();
     $this->appliedFilters = $collection->make();
     $this->appliedSorts = $collection->make();
     $this->app = $app;
 }
Example #2
0
 /**
  * @param      $vulnerabilities
  * @param      $version
  * @param null $found_vulnerabilities
  *
  * @return bool
  */
 public function isVulnerable($vulnerabilities, $version, &$found_vulnerabilities = null)
 {
     $found_vulnerabilities = Collection::make($vulnerabilities)->filter(function ($v) use($version) {
         return $this->semver->lessThan($version, $v->fixed_in);
     });
     return $found_vulnerabilities->count() > 0;
 }
Example #3
0
 /**
  * Array of language files grouped by file name.
  *
  * ex: ['user' => ['en' => 'user.php', 'nl' => 'user.php']]
  *
  * @return array
  */
 public function files()
 {
     $files = Collection::make($this->disk->allFiles($this->path));
     $filesByFile = $files->groupBy(function ($file) {
         $fileName = $file->getBasename('.' . $file->getExtension());
         if (Str::contains($file->getPath(), 'vendor')) {
             $fileName = str_replace('.php', '', $file->getFileName());
             $packageName = basename(dirname($file->getPath()));
             return "{$packageName}::{$fileName}";
         } else {
             return $fileName;
         }
     })->map(function ($files) {
         return $files->keyBy(function ($file) {
             return basename($file->getPath());
         })->map(function ($file) {
             return $file->getRealPath();
         });
     });
     // If the path does not contain "vendor" then we're looking at the
     // main language files of the application, in this case we will
     // neglect all vendor files.
     if (!Str::contains($this->path, 'vendor')) {
         $filesByFile = $this->neglectVendorFiles($filesByFile);
     }
     return $filesByFile;
 }
Example #4
0
 /**
  * Get the results as a collection of model instances.
  *
  * @return Collection
  */
 protected function collectModels()
 {
     $modelClass = get_class($this->model);
     return Collection::make($this->query())->map(function ($result) use($modelClass) {
         return new $modelClass($result);
     });
 }
Example #5
0
 protected static function checkType($types)
 {
     $types = Collection::make($types);
     if (!$types->contains(static::TYPE)) {
         throw new DomainException('Invalid contact type: ' . $types->implode(','));
     }
 }
Example #6
0
 /**
  * Create order record.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function store()
 {
     try {
         \DB::beginTransaction();
         $items = Collection::make(\Input::get('items'));
         $order = new Order();
         // create the order
         $order->save();
         // Attach items to order
         $items->each(function ($item) use($order) {
             $order->addItem($item);
         });
         // Calculate commission & profit
         /** @var \Paxifi\Support\Commission\CalculatorInterface $calculator */
         $calculator = \App::make('Paxifi\\Support\\Commission\\CalculatorInterface');
         $calculator->setCommissionRate($order->OrderDriver()->getCommissionRate());
         $order->setCommission($calculator->calculateCommission($order));
         $order->setProfit($calculator->calculateProfit($order));
         // save order
         $order->save();
         \DB::commit();
         return $this->setStatusCode(201)->respondWithItem(Order::find($order->id));
     } catch (ModelNotFoundException $e) {
         return $this->errorWrongArgs('Invalid product id');
     } catch (\InvalidArgumentException $e) {
         return $this->errorWrongArgs($e->getMessage());
     } catch (\Exception $e) {
         return $this->errorInternalError();
     }
 }
Example #7
0
 public function getModels(array $models = [])
 {
     foreach ($models as &$model) {
         $model = $this->model->newFromQuery($model);
     }
     return Collection::make($models);
 }
Example #8
0
 function length_aware_paginator($items, $perPage, $currentPage = null, array $options = [])
 {
     $currentPage = $currentPage ?: LengthAwarePaginator::resolveCurrentPage();
     $startIndex = $currentPage * $perPage - $perPage;
     $paginatedItems = Collection::make($items)->slice($startIndex, $perPage);
     return new LengthAwarePaginator($paginatedItems, $items->count(), $perPage, $currentPage, ['path' => LengthAwarePaginator::resolveCurrentPath()]);
 }
Example #9
0
 /**
  * @param Collection $collection
  * @return \Illuminate\Support\Collection
  */
 public function collection(Collection $collection)
 {
     $activities = $collection->map(function ($item) {
         return self::single(Collection::make($item));
     });
     return $activities;
 }
Example #10
0
 /**
  * @param array|Collection $data
  */
 public function __construct($data = [])
 {
     $this->data = $data;
     if (!$this->data instanceof Collection) {
         $this->data = Collection::make($this->data);
     }
 }
 public function testModels()
 {
     $this->search->shouldReceive('config->models')->with([1, 2, 3, 4, 5], ['limit' => 2, 'offset' => 3])->andReturn([[1, 2, 3, 4, 5], 5]);
     $this->assertEquals(Collection::make([1, 2, 3, 4, 5]), $this->runner->models('test', ['limit' => 2, 'offset' => 3]));
     $this->assertEquals(5, $this->runner->getCachedCount('test'));
     $this->assertEquals(0, $this->runner->getCachedCount('other test'));
 }
 /**
  * Devuelve una lista de los distintas salas de la colección de
  * exhibiciones dada.
  *
  *
  * @param $exhibitions Lista de exhibiciones.
  * @return  Collection Lista de todas las distintas salas de las exhibiciones dadas.
  */
 public function getAuditoriums($exhibitions)
 {
     $auditoriums = $exhibitions->reduce(function ($accum, $exhibition) {
         return $accum->merge($exhibition->auditoriums);
     }, Collection::make([]));
     return $auditoriums;
 }
Example #13
0
 public function setUp()
 {
     $claims = ['sub' => new Subject(1), 'iss' => new Issuer('http://example.com'), 'exp' => new Expiration(time() + 3600), 'nbf' => new NotBefore(time()), 'iat' => new IssuedAt(time()), 'jti' => new JwtId('foo')];
     $this->validator = Mockery::mock('Tymon\\JWTAuth\\Validators\\PayloadValidator');
     $this->validator->shouldReceive('setRefreshFlow->check');
     $this->payload = new Payload(Collection::make($claims), $this->validator);
 }
Example #14
0
 /**
  * @return static
  */
 public function getTemplateList()
 {
     $templates = Collection::make();
     $templates->put('default::page.default', '默认模板');
     static::$dispatcher->fire(new GetTemplateList($templates));
     return $templates;
 }
 public function show_docket($id)
 {
     $delivery_history = DeliveryHistory::find($id);
     $input = unserialize($delivery_history->input);
     $quote = QuoteRequest::find($delivery_history->qr_id);
     $delivery_address = CustomerAddress::find($input['delivery_address']);
     // Create PDF
     $qtys = isset($input['number']) ? $input['number'] : '';
     if (isset($input['number'])) {
         // Quantities are not equal
         $collection = Collection::make($input['number']);
         $numbers = $collection->flip()->map(function () {
             return 0;
         });
         foreach ($collection as $item) {
             $numbers[$item] += 1;
         }
         $html = view('jobs.docket', compact('input', 'quote', 'delivery_address', 'qtys', 'numbers'));
     } else {
         // Quantities are equal
         $html = view('jobs.docket', compact('input', 'quote', 'delivery_address', 'qtys'));
     }
     $dompdf = PDF::loadHTML($html);
     return $dompdf->stream();
 }
Example #16
0
 /**
  * @param \Illuminate\Support\Collection|IComponent[]|array $components
  * @return $this
  */
 public function setComponents($components)
 {
     $this->components = Collection::make($components);
     foreach ($components as $component) {
         $component->attachTo($this);
     }
     return $this;
 }
 /**
  * Run query and get all finding models.
  *
  * @param $query
  * @param $options
  * @return array
  */
 public function models($query, array $options = [])
 {
     $hits = $this->run($query);
     list($models, $totalCount) = $this->search->config()->models($hits, $options);
     // Remember total number of results.
     $this->setCachedCount($query, $totalCount);
     return Collection::make($models);
 }
Example #18
0
 /**
  * Find and initialise the extensions.
  *
  * @param  array $paths
  * @return array
  */
 public function findAndInitialiseExtensions(array $paths)
 {
     // Find the extensions.
     $extensions = $this->finder->findExtensions($paths);
     // Create the collection of extensions.
     $this->collection = Collection::make($extensions);
     return $extensions;
 }
 public function addColumn($column)
 {
     if (NULL === $this->columns) {
         $this->columns = Collection::make([]);
     }
     $this->columns->push($column);
     return $this;
 }
Example #20
0
 /**
  * @test
  */
 public function it_can_set_a_new_order()
 {
     $newOrder = Collection::make(Dummy::all()->lists('id'))->shuffle()->toArray();
     Dummy::setNewOrder($newOrder);
     foreach (Dummy::orderBy('order_column')->get() as $i => $dummy) {
         $this->assertEquals($newOrder[$i], $dummy->id);
     }
 }
 /**
  * Get the html boolean attributes.
  *
  * @return \Illuminate\Support\Collection
  */
 public function getAttributes()
 {
     if (self::$attributes === null) {
         $attributes = $this->loadJson($this->resource('HtmlBooleanAttributes.json'))->attributes;
         self::$attributes = Collection::make($attributes);
     }
     return self::$attributes;
 }
Example #22
0
 public static function byYear($year)
 {
     $values = self::all()[2016];
     foreach ($values as $key => $value) {
         $values[$key]['year'] = $year;
     }
     return Collection::make($values);
 }
Example #23
0
 protected function plucked($data)
 {
     return Collection::make($data)->map(function ($item) {
         $key = $item[$this->pluck_key];
         $value = $item[$this->pluck_value];
         return [$key => $value];
     })->toArray();
 }
 /**
  * Replace the bound URL generator.
  *
  * @return void
  */
 protected function replaceBoundUrlGenerator()
 {
     $this->app->bindShared('url', function ($app) {
         $routes = Collection::make($app['router']->getRoutes())->merge($app['router']->getApiGroups()->getRoutes());
         return new UrlGenerator($routes, $app->rebinding('request', function ($app, $request) {
             $app['url']->setRequest($request);
         }));
     });
 }
 public function getPersonTypeByRole($role)
 {
     $m = PersonType::where('role', $role)->first();
     if (count($m) > 0) {
         return $m->persons()->lists('name', 'id_person')->prepend('Selecione', 0);
     } else {
         return Collection::make([0 => 'Selecione']);
     }
 }
Example #26
0
 public static function getArray($array, $key)
 {
     self::$key = $key;
     $collection = Collection::make($array);
     $id = $collection->map(function ($od) {
         return $od[self::$key];
     });
     return $id->flatten()->toArray();
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if ($this->systemAdmin) {
         $departments = Department::all();
     } else {
         $departments = Collection::make([Auth::user()->department]);
     }
     return view('admin.department.index', ['departments' => $departments, 'title' => trans('admin.departments'), 'url' => $this->systemAdmin ? action('Admin\\DepartmentController@create') : '']);
 }
 /**
  * InstallCommand constructor.
  * @param \Illuminate\Contracts\Foundation\Application $application
  * @param \Illuminate\Filesystem\Filesystem $filesystem
  */
 public function __construct(Application $application, Filesystem $filesystem)
 {
     parent::__construct();
     $this->notadd = $application;
     $this->config = $this->notadd->make('config');
     $this->data = Collection::make();
     $this->filesystem = $filesystem;
     $this->setting = $this->notadd->make('setting');
 }
Example #29
0
 protected static function registerRelations()
 {
     if (!static::$relations) {
         $supported = [HasOne::class => HasOneWrapper::class, BelongsTo::class => BelongsToWrapper::class, BelongsToMany::class => BelongsToManyWrapper::class, HasMany::class => HasManyWrapper::class];
         static::$relations = Collection::make([]);
         foreach ($supported as $rel => $wrapperName) {
             static::$relations[$rel] = ['className' => $wrapperName];
         }
     }
 }
Example #30
0
 /** @test */
 public function it_can_set_a_new_order_without_trashed_models()
 {
     $this->setUpSoftDeletes();
     DummyWithSoftDeletes::first()->delete();
     $newOrder = Collection::make(DummyWithSoftDeletes::pluck('id'))->shuffle();
     DummyWithSoftDeletes::setNewOrder($newOrder);
     foreach (DummyWithSoftDeletes::orderBy('order_column')->get() as $i => $dummy) {
         $this->assertEquals($newOrder[$i], $dummy->id);
     }
 }