Skip to content

Commit f117679

Browse files
committed
Merge pull request #20 from Art4/Bug_Pagination
Bugfix: Add tests and code for pagination links
2 parents 5c135f3 + 651a4ab commit f117679

16 files changed

+564
-449
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
### Fixed
9+
10+
- **BREAKING**: pagination links moved from `Pagination` to `DocumentLink` and `RelationshipLink`
11+
12+
### Removed
13+
14+
- **BREAKING**: object `Pagination` was removed
15+
816
## [0.5] - 2015-10-12
917

1018
### Added

docs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* [Document Link object](objects-document-link.md)
1919
* [Relationship Link object](objects-relationship-link.md)
2020
* [Error Link object](objects-error-link.md)
21-
* [Pagination object](objects-pagination.md)
2221
* [Jsonapi object](objects-jsonapi.md)
2322
* [Meta object](objects-meta.md)
2423

docs/objects-document-link.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ _[Symbols definition](objects-introduction.md#symbols)_
1616
--- | ---- | ----- | ----
1717
? | self | `string` |
1818
? | related | `string` |
19-
? | pagination | [Pagination object](objects-pagination.md) |
19+
? | first | - `null`<br />- `string` |
20+
? | last | - `null`<br />- `string` |
21+
? | prev | - `null`<br />- `string` |
22+
? | next | - `null`<br />- `string` |

docs/objects-introduction.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ All possible objects and their hierarchical structure are listet below.
3434
1. [Document Link object](objects-document-link.md)
3535
1. [Relationship Link object](objects-relationship-link.md)
3636
1. [Error Link object](objects-error-link.md)
37-
1. [Pagination object](objects-pagination.md)
3837
1. [Jsonapi object](objects-jsonapi.md)
3938
1. [Meta object](objects-meta.md)
4039

docs/objects-pagination.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

docs/objects-relationship-link.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ _[Symbols definition](objects-introduction.md#symbols)_
1616
--- | ---- | ----- | ----
1717
# | self | `string` |
1818
# | related | `string` |
19-
? | pagination | [Pagination object](objects-pagination.md) | Only exists if the parent relationship object represents a to-many relationship
19+
? | first | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |
20+
? | last | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |
21+
? | prev | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |
22+
? | next | - `null`<br />- `string` | Only exists if the parent relationship object represents a to-many relationship |

src/DocumentLink.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,58 @@ public function __construct($object, FactoryManagerInterface $manager)
7070
$this->container->set('related', $object->related);
7171
}
7272

73-
if ( property_exists($object, 'pagination') )
73+
// Pagination links
74+
75+
if ( property_exists($object, 'first') )
76+
{
77+
if ( ! is_string($object->first) and ! is_null($object->first) )
78+
{
79+
throw new ValidationException('property "first" has to be a string or null, "' . gettype($object->first) . '" given.');
80+
}
81+
82+
if ( ! is_null($object->first) )
83+
{
84+
$this->container->set('first', strval($object->first));
85+
}
86+
}
87+
88+
if ( property_exists($object, 'last') )
89+
{
90+
if ( ! is_string($object->last) and ! is_null($object->last) )
91+
{
92+
throw new ValidationException('property "last" has to be a string or null, "' . gettype($object->last) . '" given.');
93+
}
94+
95+
if ( ! is_null($object->last) )
96+
{
97+
$this->container->set('last', strval($object->last));
98+
}
99+
}
100+
101+
if ( property_exists($object, 'prev') )
74102
{
75-
$this->container->set('pagination', $this->manager->getFactory()->make(
76-
'Pagination',
77-
[$object->pagination, $this->manager]
78-
));
103+
if ( ! is_string($object->prev) and ! is_null($object->prev) )
104+
{
105+
throw new ValidationException('property "prev" has to be a string or null, "' . gettype($object->prev) . '" given.');
106+
}
107+
108+
if ( ! is_null($object->prev) )
109+
{
110+
$this->container->set('prev', strval($object->prev));
111+
}
112+
}
113+
114+
if ( property_exists($object, 'next') )
115+
{
116+
if ( ! is_string($object->next) and ! is_null($object->next) )
117+
{
118+
throw new ValidationException('property "next" has to be a string or null, "' . gettype($object->next) . '" given.');
119+
}
120+
121+
if ( ! is_null($object->next) )
122+
{
123+
$this->container->set('next', strval($object->next));
124+
}
79125
}
80126
}
81127

src/Pagination.php

Lines changed: 0 additions & 128 deletions
This file was deleted.

src/PaginationInterface.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/RelationshipLink.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,58 @@ public function __construct($object, FactoryManagerInterface $manager)
7979
$this->container->set('related', strval($object->related));
8080
}
8181

82-
if ( property_exists($object, 'pagination') )
82+
// Pagination links
83+
84+
if ( property_exists($object, 'first') )
85+
{
86+
if ( ! is_string($object->first) and ! is_null($object->first) )
87+
{
88+
throw new ValidationException('property "first" has to be a string or null, "' . gettype($object->first) . '" given.');
89+
}
90+
91+
if ( ! is_null($object->first) )
92+
{
93+
$this->container->set('first', strval($object->first));
94+
}
95+
}
96+
97+
if ( property_exists($object, 'last') )
98+
{
99+
if ( ! is_string($object->last) and ! is_null($object->last) )
100+
{
101+
throw new ValidationException('property "last" has to be a string or null, "' . gettype($object->last) . '" given.');
102+
}
103+
104+
if ( ! is_null($object->last) )
105+
{
106+
$this->container->set('last', strval($object->last));
107+
}
108+
}
109+
110+
if ( property_exists($object, 'prev') )
83111
{
84-
$this->container->set('pagination', $this->manager->getFactory()->make(
85-
'Pagination',
86-
[$object->pagination, $this->manager]
87-
));
112+
if ( ! is_string($object->prev) and ! is_null($object->prev) )
113+
{
114+
throw new ValidationException('property "prev" has to be a string or null, "' . gettype($object->prev) . '" given.');
115+
}
116+
117+
if ( ! is_null($object->prev) )
118+
{
119+
$this->container->set('prev', strval($object->prev));
120+
}
121+
}
122+
123+
if ( property_exists($object, 'next') )
124+
{
125+
if ( ! is_string($object->next) and ! is_null($object->next) )
126+
{
127+
throw new ValidationException('property "next" has to be a string or null, "' . gettype($object->next) . '" given.');
128+
}
129+
130+
if ( ! is_null($object->next) )
131+
{
132+
$this->container->set('next', strval($object->next));
133+
}
88134
}
89135
}
90136

0 commit comments

Comments
 (0)