Skip to content

Commit ccf2bb0

Browse files
committed
Merge branch 'release/1.0.0' into main
2 parents a68227d + 9e03c57 commit ccf2bb0

File tree

19 files changed

+2358
-3
lines changed

19 files changed

+2358
-3
lines changed

.github/workflows/tests.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
php: ['7.4', '8.0']
18+
laravel: ['^8.0']
19+
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v2
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
29+
tools: composer:v2
30+
coverage: none
31+
32+
- name: Set Laravel Version
33+
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-update -n
34+
35+
- name: Install dependencies
36+
uses: nick-invision/retry@v1
37+
with:
38+
timeout_minutes: 5
39+
max_attempts: 5
40+
command: composer install --no-suggest --prefer-dist -n -o
41+
42+
- name: Execute tests
43+
run: vendor/bin/phpunit

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
All notable changes to this project will be documented in this file. This project adheres to
44
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
55

6-
## Unreleased
6+
## [1.0.0] - 2021-07-21
7+
8+
Initial release. This brought in the code from `laravel-json-api/eloquent:1.0.0-beta.6`, with the only changes being new
9+
namespaces.

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
"php": "^7.4|^8.0",
2727
"ext-json": "*",
2828
"illuminate/database": "^8.0",
29+
"illuminate/pagination": "^8.0",
2930
"illuminate/support": "^8.0",
30-
"laravel-json-api/eloquent": "^1.0.0-stable"
31+
"laravel-json-api/eloquent": "^1.0.0"
3132
},
3233
"require-dev": {
3334
"orchestra/testbench": "^6.9",
@@ -50,7 +51,7 @@
5051
"dev-develop": "1.x-dev"
5152
}
5253
},
53-
"minimum-stability": "dev",
54+
"minimum-stability": "stable",
5455
"prefer-stable": true,
5556
"config": {
5657
"sort-packages": true

src/.gitkeep

Whitespace-only changes.

src/Cursor/Cursor.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/*
3+
* Copyright 2021 Cloud Creativity Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace LaravelJsonApi\CursorPagination\Cursor;
21+
22+
use InvalidArgumentException;
23+
24+
class Cursor
25+
{
26+
27+
/**
28+
* @var string|null
29+
*/
30+
private ?string $before;
31+
32+
/**
33+
* @var string|null
34+
*/
35+
private ?string $after;
36+
37+
/**
38+
* @var int|null
39+
*/
40+
private ?int $limit;
41+
42+
/**
43+
* Cursor constructor.
44+
*
45+
* @param string|null $before
46+
* @param string|null $after
47+
* @param int|null $limit
48+
*/
49+
public function __construct(string $before = null, string $after = null, int $limit = null)
50+
{
51+
if (is_int($limit) && 1 > $limit) {
52+
throw new InvalidArgumentException('Expecting a limit that is 1 or greater.');
53+
}
54+
55+
$this->before = $before ?: null;
56+
$this->after = $after ?: null;
57+
$this->limit = $limit;
58+
}
59+
60+
/**
61+
* @return bool
62+
*/
63+
public function isBefore(): bool
64+
{
65+
return !is_null($this->before);
66+
}
67+
68+
/**
69+
* @return string|null
70+
*/
71+
public function getBefore(): ?string
72+
{
73+
return $this->before;
74+
}
75+
76+
/**
77+
* @return bool
78+
*/
79+
public function isAfter(): bool
80+
{
81+
return !is_null($this->after) && !$this->isBefore();
82+
}
83+
84+
/**
85+
* @return string|null
86+
*/
87+
public function getAfter(): ?string
88+
{
89+
return $this->after;
90+
}
91+
92+
/**
93+
* Set a limit, if no limit is set on the cursor.
94+
*
95+
* @param int $limit
96+
* @return Cursor
97+
*/
98+
public function withDefaultLimit(int $limit): self
99+
{
100+
if (is_null($this->limit)) {
101+
$copy = clone $this;
102+
$copy->limit = $limit;
103+
return $copy;
104+
}
105+
106+
return $this;
107+
}
108+
109+
/**
110+
* @return int|null
111+
*/
112+
public function getLimit(): ?int
113+
{
114+
return $this->limit;
115+
}
116+
117+
}

0 commit comments

Comments
 (0)