Skip to content

Commit 0058e24

Browse files
committed
Add StandardObjectInterface, closes #4
1 parent 3f9347d commit 0058e24

File tree

2 files changed

+114
-2
lines changed

2 files changed

+114
-2
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2015 Cloud Creativity Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace CloudCreativity\JsonApi\Contracts\Object;
20+
21+
/**
22+
* Interface StandardObjectInterface
23+
* @package CloudCreativity\JsonApi
24+
*/
25+
interface StandardObjectInterface extends \Traversable, \Countable
26+
{
27+
28+
/**
29+
* @param $key
30+
* @param $default
31+
* @return mixed
32+
*/
33+
public function get($key, $default = null);
34+
35+
/**
36+
* @param array $keys
37+
* @param $default
38+
* @return array
39+
*/
40+
public function getProperties(array $keys, $default = null);
41+
42+
/**
43+
* @param $key
44+
* @param $value
45+
* @return $this
46+
*/
47+
public function set($key, $value);
48+
49+
/**
50+
* @param array $values
51+
* @return $this
52+
*/
53+
public function setProperties(array $values);
54+
55+
/**
56+
* @param $key
57+
* @return bool
58+
*/
59+
public function has($key);
60+
61+
/**
62+
* Whether the object has all of the specified keys.
63+
*
64+
* @param array $keys
65+
* @return bool
66+
*/
67+
public function hasAll(array $keys);
68+
69+
/**
70+
* Whether the object has any (at least one) of the specified keys.
71+
*
72+
* @param array $keys
73+
* @return bool
74+
*/
75+
public function hasAny(array $keys);
76+
77+
/**
78+
* @param $key
79+
* @return $this
80+
*/
81+
public function remove($key);
82+
83+
/**
84+
* @param array $keys
85+
* @return $this
86+
*/
87+
public function removeProperties(array $keys);
88+
89+
/**
90+
* Reduce this object so that it only has the supplied allowed keys.
91+
*
92+
* @param array $keys
93+
* @return $this
94+
*/
95+
public function reduce(array $keys);
96+
97+
/**
98+
* Get a list of the object's keys.
99+
*
100+
* @return string[]
101+
*/
102+
public function keys();
103+
104+
/**
105+
* Get the object's property values as an array.
106+
*
107+
* @return array
108+
*/
109+
public function toArray();
110+
}

src/Object/StandardObject.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
namespace CloudCreativity\JsonApi\Object;
2020

21+
use CloudCreativity\JsonApi\Contracts\Object\StandardObjectInterface;
22+
2123
/**
2224
* Class StandardObject
2325
* @package CloudCreativity\JsonApi
2426
*/
25-
class StandardObject implements \IteratorAggregate, \Countable
27+
class StandardObject implements \IteratorAggregate, StandardObjectInterface
2628
{
2729

2830
use ObjectProxyTrait;
@@ -95,4 +97,4 @@ public function count()
9597
{
9698
return count($this->toArray());
9799
}
98-
}
100+
}

0 commit comments

Comments
 (0)