55namespace Strobotti \JWK \Key ;
66
77/**
8- * @package Strobotti\JWK
98 * @author Juha Jantunen <[email protected] > 109 * @license https://opensource.org/licenses/MIT MIT
11- * @link https://github.com/Strobotti/php-jwk
10+ *
11+ * @see https://github.com/Strobotti/php-jwk
12+ * @since 1.0.0
1213 */
1314abstract class AbstractKey implements KeyInterface
1415{
@@ -40,8 +41,20 @@ abstract class AbstractKey implements KeyInterface
4041 */
4142 private $ alg ;
4243
44+ /**
45+ * @since 1.0.0
46+ *
47+ * @return false|string
48+ */
49+ public function __toString ()
50+ {
51+ return \json_encode ($ this ->jsonSerialize (), JSON_PRETTY_PRINT );
52+ }
53+
4354 /**
4455 * {@inheritdoc}
56+ *
57+ * @since 1.0.0
4558 */
4659 public function getKeyType (): string
4760 {
@@ -50,6 +63,8 @@ public function getKeyType(): string
5063
5164 /**
5265 * {@inheritdoc}
66+ *
67+ * @since 1.0.0
5368 */
5469 public function getKeyId (): string
5570 {
@@ -58,6 +73,8 @@ public function getKeyId(): string
5873
5974 /**
6075 * {@inheritdoc}
76+ *
77+ * @since 1.0.0
6178 */
6279 public function getPublicKeyUse (): string
6380 {
@@ -66,26 +83,18 @@ public function getPublicKeyUse(): string
6683
6784 /**
6885 * {@inheritdoc}
86+ *
87+ * @since 1.0.0
6988 */
7089 public function getAlgorithm (): string
7190 {
7291 return $ this ->alg ;
7392 }
7493
7594 /**
76- * @param string $kty
95+ * Returns an array presentation of the key.
7796 *
78- * @return self
79- */
80- protected function setKeyType (string $ kty ): self
81- {
82- $ this ->kty = $ kty ;
83-
84- return $ this ;
85- }
86-
87- /**
88- * Returns an array presentation of the key
97+ * @since 1.0.0
8998 *
9099 * @return array An assoc to be passed to json_encode
91100 */
@@ -105,10 +114,7 @@ public function jsonSerialize(): array
105114 }
106115
107116 /**
108- * @param string $json
109- * @param KeyInterface|null $prototype
110- *
111- * @return KeyInterface
117+ * @since 1.0.0
112118 */
113119 public static function createFromJSON (string $ json , KeyInterface $ prototype = null ): KeyInterface
114120 {
@@ -136,10 +142,12 @@ public static function createFromJSON(string $json, KeyInterface $prototype = nu
136142 }
137143
138144 /**
139- * @return false|string
145+ * @since 1.0.0
140146 */
141- public function __toString ()
147+ protected function setKeyType ( string $ kty ): self
142148 {
143- return json_encode ($ this ->jsonSerialize (), JSON_PRETTY_PRINT );
149+ $ this ->kty = $ kty ;
150+
151+ return $ this ;
144152 }
145153}
0 commit comments