1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xmf\Jwt;
13:
14: use Firebase\JWT\JWT;
15: use Xmf\Key\Basic;
16: use Xmf\Key\FileStorage;
17:
18: /**
19: * Build a key to be used for JSON Web Token processing
20: *
21: * @category Xmf\Jwt\KeyFactory
22: * @package Xmf
23: * @author Richard Griffith <richard@geekwright.com>
24: * @copyright 2016 XOOPS Project (http://xoops.org)
25: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
26: * @link http://xoops.org
27: */
28: class KeyFactory
29: {
30: /**
31: * Create a Key object for JWT use based on default choices. If the key has not been
32: * established, create it.
33: *
34: * @param string $keyName name of the key
35: *
36: * @return Basic
37: */
38: public static function build($keyName)
39: {
40: if (empty($keyName) || !is_string($keyName)) {
41: throw new \InvalidArgumentException('keyName must be a non-empty string');
42: }
43: $key = new Basic(new FileStorage(), $keyName);
44: $key->create(); // will automatically skip if key has already been generated
45: return $key;
46: }
47: }
48: