本文整理汇总了PHP中Illuminate\Support\Collection::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::make方法的具体用法?PHP Collection::make怎么用?PHP Collection::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* 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;
}
示例2: isVulnerable
/**
* @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;
}
示例3: files
/**
* 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;
}
示例4: collectModels
/**
* 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);
});
}
示例5: checkType
protected static function checkType($types)
{
$types = Collection::make($types);
if (!$types->contains(static::TYPE)) {
throw new DomainException('Invalid contact type: ' . $types->implode(','));
}
}
示例6: store
/**
* 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();
}
}
示例7: getModels
public function getModels(array $models = [])
{
foreach ($models as &$model) {
$model = $this->model->newFromQuery($model);
}
return Collection::make($models);
}
示例8: LengthAwarePaginator
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()]);
}
示例9: collection
/**
* @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;
}
示例10: __construct
/**
* @param array|Collection $data
*/
public function __construct($data = [])
{
$this->data = $data;
if (!$this->data instanceof Collection) {
$this->data = Collection::make($this->data);
}
}
示例11: testModels
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'));
}
示例12: getAuditoriums
/**
* 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;
}
示例13: setUp
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);
}
示例14: getTemplateList
/**
* @return static
*/
public function getTemplateList()
{
$templates = Collection::make();
$templates->put('default::page.default', '默认模板');
static::$dispatcher->fire(new GetTemplateList($templates));
return $templates;
}
示例15: show_docket
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();
}