Skip to content

Commit adbfdde

Browse files
committed
Merge pull request #18 from Art4/DataContainer
Set all classes to final
2 parents dab463f + a6e8039 commit adbfdde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1258
-1279
lines changed

CHANGELOG.md

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

6-
## [Unreleased][]
6+
## [Unreleased]
77

88
### Added
99

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
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 Link object](objects-pagination-link.md)
21+
* [Pagination object](objects-pagination.md)
2222
* [Jsonapi object](objects-jsonapi.md)
2323
* [Meta object](objects-meta.md)
2424

docs/objects-document-link.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ _[Symbols definition](objects-introduction.md#symbols)_
1616
--- | ---- | ----- | ----
1717
? | self | `string` |
1818
? | related | `string` |
19-
? | pagination | [Pagination Link object](objects-pagination-link.md) |
19+
? | pagination | [Pagination object](objects-pagination.md) |

docs/objects-introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ 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 Link object](objects-pagination-link.md)
37+
1. [Pagination object](objects-pagination.md)
3838
1. [Jsonapi object](objects-jsonapi.md)
3939
1. [Meta object](objects-meta.md)
4040

docs/objects-pagination-link.md renamed to docs/objects-pagination.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# PaginationLink
1+
# Pagination
22
[Back to Navigation](README.md)
33

44
## Description
55

6-
The `PaginationLink` represents a [pagination object](http://jsonapi.org/format/#fetching-pagination).
6+
The `Pagination` represents a [pagination object](http://jsonapi.org/format/#fetching-pagination).
77

88
Property of:
99
- [Document Link object](objects-document-link.md)

docs/objects-relationship-link.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ _[Symbols definition](objects-introduction.md#symbols)_
1616
--- | ---- | ----- | ----
1717
# | self | `string` |
1818
# | related | `string` |
19-
? | pagination | [Pagination Link object](objects-pagination-link.md) | Only exists if the parent relationship object represents a to-many relationship
19+
? | pagination | [Pagination object](objects-pagination.md) | Only exists if the parent relationship object represents a to-many relationship

docs/utils-factory.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ Assuming you want a `toJson()` functionality in your document object. First crea
1919

2020
```php
2121
namespace My\Own
22-
class Document extends \Art4\JsonApiClient\Document
22+
class Document implements \Art4\JsonApiClient\DocumentInterface
2323
{
24+
// Implement the \Art4\JsonApiClient\DocumentInterface here
25+
/*
26+
public function get($key);
27+
public function has($key);
28+
public function getKeys();
29+
public function asArray();
30+
*/
31+
32+
// your new method
2433
public function toJson()
2534
{
2635
return json_encode($this->asArray(true));

src/Attributes.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
namespace Art4\JsonApiClient;
44

5+
use Art4\JsonApiClient\Utils\AccessTrait;
6+
use Art4\JsonApiClient\Utils\DataContainer;
57
use Art4\JsonApiClient\Utils\FactoryManagerInterface;
8+
use Art4\JsonApiClient\Exception\AccessException;
69
use Art4\JsonApiClient\Exception\ValidationException;
710

811
/**
912
* Attributes Object
1013
*
1114
* @see http://jsonapi.org/format/#document-resource-object-attributes
1215
*/
13-
class Attributes extends Meta
16+
final class Attributes implements AttributesInterface
1417
{
18+
use AccessTrait;
19+
20+
/**
21+
* @var DataContainerInterface
22+
*/
23+
protected $container;
24+
1525
/**
1626
* @var FactoryManagerInterface
1727
*/
@@ -36,6 +46,40 @@ public function __construct($object, FactoryManagerInterface $manager)
3646
throw new ValidationException('These properties are not allowed in attributes: `type`, `id`, `relationships`, `links`');
3747
}
3848

39-
return parent::__construct($object, $manager);
49+
$this->manager = $manager;
50+
51+
$this->container = new DataContainer();
52+
53+
$object_vars = get_object_vars($object);
54+
55+
if ( count($object_vars) === 0 )
56+
{
57+
return $this;
58+
}
59+
60+
foreach ($object_vars as $name => $value)
61+
{
62+
$this->container->set($name, $value);
63+
}
64+
65+
return $this;
66+
}
67+
68+
/**
69+
* Get a value by the key of this object
70+
*
71+
* @param string $key The key of the value
72+
* @return mixed The value
73+
*/
74+
public function get($key)
75+
{
76+
try
77+
{
78+
return $this->container->get($key);
79+
}
80+
catch (AccessException $e)
81+
{
82+
throw new AccessException('"' . $key . '" doesn\'t exist in this object.');
83+
}
4084
}
4185
}

src/AttributesInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Art4\JsonApiClient;
4+
5+
/**
6+
* Attributes Interface
7+
*/
8+
interface AttributesInterface extends AccessInterface { }

0 commit comments

Comments
 (0)