Skip to content

Commit 6d3a368

Browse files
committed
Initial Hooks
0 parents  commit 6d3a368

13 files changed

+509
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/php-webhooks/vendor/

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# php-webhooks
2+
PHP Webhooks

build/build.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
echo -e "\033[4mUpdating PHP Webhooks Library...\033[0m"
4+
5+
rm -rf ./tmp_webhooks
6+
(git clone https://github.com/fident/webhooks.git tmp_webhooks && cd ./tmp_webhooks)
7+
8+
php ./v1.php
9+
rm -rf ./tmp_webhooks

build/v1.changelog.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
####Build Process @ 2020-03-31 11:24:47
2+
####New Classes
3+
- LoginLink
4+
- ResetPasswordLink
5+
- VerifyAccount
6+
- VerifySetPasswordLink
7+
- Webhook
8+
9+
####Build Process @ 2020-03-31 11:33:41
10+
####New Classes
11+
- LoginLink
12+
- ResetPasswordLink
13+
- VerifyAccount
14+
- VerifySetPasswordLink
15+
- Webhook
16+

build/v1.php

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
use Packaged\Helpers\Strings;
4+
5+
require dirname(__DIR__) . '/vendor/autoload.php';
6+
7+
$outputDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src'
8+
. DIRECTORY_SEPARATOR . 'Generated' . DIRECTORY_SEPARATOR . 'V1';
9+
if(!file_exists($outputDir))
10+
{
11+
mkdir($outputDir, 0777, true);
12+
}
13+
$files = glob(__DIR__ . DIRECTORY_SEPARATOR . 'tmp_webhooks/*.json');
14+
$mutations = ['UPDATE' => [], 'CREATE' => []];
15+
$mutationCount = 0;
16+
17+
function filenameToClass($file)
18+
{
19+
return ucfirst($file);
20+
}
21+
22+
foreach($files as $file)
23+
{
24+
$json = json_decode(file_get_contents($file));
25+
$filename = basename($file, '.json');
26+
$className = filenameToClass($json->name ?? $filename);
27+
28+
$src = [];
29+
$src[] = '<?php';
30+
$src[] = 'namespace Fident\\Webhooks\\Generated\\V1;';
31+
$src[] = '';
32+
$src[] = 'use Fident\\Webhooks\\WebhookFoundation;';
33+
$src[] = '';
34+
if(isset($json->description))
35+
{
36+
$src[] = '/**';
37+
$src[] = ' * ' . $json->description;
38+
$src[] = ' */';
39+
}
40+
$src[] = 'class ' . $className . ' extends WebhookFoundation';
41+
$src[] = '{';
42+
43+
$setters = [];
44+
45+
foreach($json->properties as $property => $propertyDefinition)
46+
{
47+
if(isset($propertyDefinition->enum))
48+
{
49+
foreach($propertyDefinition->enum as $enum)
50+
{
51+
$src[] = ' const '
52+
. strtoupper(str_replace(' ', '_', Strings::splitOnCamelCase($property . '_' . $enum)))
53+
. ' = "' . addslashes($enum) . '";';
54+
}
55+
}
56+
57+
$docBlock = [];
58+
if(isset($propertyDefinition->description))
59+
{
60+
$docBlock[] = ' * ' . $propertyDefinition->description;
61+
$docBlock[] = ' *';
62+
}
63+
64+
if(isset($propertyDefinition->type))
65+
{
66+
if($propertyDefinition->type == "array" && isset($propertyDefinition->items))
67+
{
68+
if(isset($propertyDefinition->items->{'$ref'}))
69+
{
70+
$ref = $propertyDefinition->items->{'$ref'};
71+
$class = filenameToClass(basename($ref, '.json'));
72+
$docBlock[] = ' * @var ' . $class . '[]';
73+
$setters[$property] = "$class::manyFromSource(\$value)";
74+
}
75+
else if(isset($propertyDefinition->items->type))
76+
{
77+
$docBlock[] = ' * @var ' . $propertyDefinition->items->type . '[]';
78+
}
79+
}
80+
else
81+
{
82+
$docBlock[] = ' * @var ' . $propertyDefinition->type;
83+
}
84+
}
85+
else if(isset($propertyDefinition->{'$ref'}))
86+
{
87+
$ref = $propertyDefinition->{'$ref'};
88+
$class = filenameToClass(basename($ref, '.json'));
89+
$docBlock[] = ' * @var ' . $class;
90+
$setters[$property] = "$class::fromSource(\$value)";
91+
}
92+
93+
if(!empty($docBlock))
94+
{
95+
$src[] = ' /**';
96+
$src = array_merge($src, $docBlock);
97+
$src[] = ' */';
98+
}
99+
100+
$src[] = ' public $' . $property . ';';
101+
$src[] = '';
102+
}
103+
104+
if(!empty($setters))
105+
{
106+
$src[] = ' protected function _set($property, $value)';
107+
$src[] = ' {';
108+
foreach($setters as $property => $setter)
109+
{
110+
$src[] = ' if($property == \'' . $property . '\')';
111+
$src[] = ' {';
112+
$src[] = ' $this->' . $property . ' = ' . $setter . ';';
113+
$src[] = ' return;';
114+
$src[] = ' }';
115+
$src[] = '';
116+
}
117+
$src[] = ' parent::_set($property, $value);';
118+
$src[] = ' }';
119+
}
120+
121+
$src[] = '}';
122+
$src[] = '';
123+
124+
$outputFile = $outputDir . DIRECTORY_SEPARATOR . $className . '.php';
125+
$data = implode(PHP_EOL, $src);
126+
127+
$exists = file_exists($outputFile);
128+
if(!$exists || file_get_contents($outputFile) != $data)
129+
{
130+
file_put_contents($outputFile, $data);
131+
$mutations[$exists ? 'UPDATE' : 'CREATE'][] = $className;
132+
$mutationCount++;
133+
}
134+
}
135+
136+
if($mutationCount > 0)
137+
{
138+
$file = fopen('v1.changelog.md', 'a+');
139+
if($file)
140+
{
141+
fwrite($file, "####Build Process @ " . date("Y-m-d H:i:s") . PHP_EOL);
142+
foreach(['CREATE' => 'New Classes', 'UPDATE' => 'Updated Classes'] as $state => $message)
143+
{
144+
145+
if(!empty($mutations[$state]))
146+
{
147+
fwrite($file, "####$message" . PHP_EOL);
148+
foreach($mutations[$state] as $class)
149+
{
150+
fwrite($file, "- $class" . PHP_EOL);
151+
}
152+
}
153+
}
154+
155+
fwrite($file, PHP_EOL);
156+
fclose($file);
157+
}
158+
}

composer.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "fident/php-webhooks",
3+
"description": "Fident webhook classes for php",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Fident\\Webhooks\\": "src"
9+
}
10+
},
11+
"require": {
12+
"php": ">=7.3",
13+
"ext-json": "*"
14+
},
15+
"require-dev": {
16+
"swaggest/json-schema": "^0.12.11",
17+
"packaged/helpers": "2.*"
18+
}
19+
}

src/Generated/V1/LoginLink.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Fident\Webhooks\Generated\V1;
3+
4+
use Fident\Webhooks\WebhookFoundation;
5+
6+
/**
7+
* A login link for a users account
8+
*/
9+
class LoginLink extends WebhookFoundation
10+
{
11+
/**
12+
* ID for the identity requesting a login link
13+
*
14+
* @var string
15+
*/
16+
public $identity;
17+
18+
/**
19+
* Link for the user to click to login to their account (Single Use)
20+
*
21+
* @var string
22+
*/
23+
public $loginLink;
24+
25+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Fident\Webhooks\Generated\V1;
3+
4+
use Fident\Webhooks\WebhookFoundation;
5+
6+
/**
7+
* A reset password link for a user
8+
*/
9+
class ResetPasswordLink extends WebhookFoundation
10+
{
11+
/**
12+
* ID for the identity requesting a login link
13+
*
14+
* @var string
15+
*/
16+
public $identity;
17+
18+
/**
19+
* Link for the user to click to login to their account, and reset their password (Single Use)
20+
*
21+
* @var string
22+
*/
23+
public $resetLink;
24+
25+
}

src/Generated/V1/VerifyAccount.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace Fident\Webhooks\Generated\V1;
3+
4+
use Fident\Webhooks\WebhookFoundation;
5+
6+
/**
7+
* A link for a user to verify their account
8+
*/
9+
class VerifyAccount extends WebhookFoundation
10+
{
11+
/**
12+
* ID for the identity requesting a login link
13+
*
14+
* @var string
15+
*/
16+
public $identity;
17+
18+
/**
19+
* Link for the user to click to verify their account (Single Use)
20+
*
21+
* @var string
22+
*/
23+
public $verifyLink;
24+
25+
/**
26+
* Users first name
27+
*
28+
* @var string
29+
*/
30+
public $firstName;
31+
32+
/**
33+
* Users last name
34+
*
35+
* @var string
36+
*/
37+
public $lastName;
38+
39+
/**
40+
* Users email address
41+
*
42+
* @var string
43+
*/
44+
public $emailAddress;
45+
46+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Fident\Webhooks\Generated\V1;
3+
4+
use Fident\Webhooks\WebhookFoundation;
5+
6+
/**
7+
* A set password link for a users account
8+
*/
9+
class VerifySetPasswordLink extends WebhookFoundation
10+
{
11+
/**
12+
* ID for the identity requesting a login link
13+
*
14+
* @var string
15+
*/
16+
public $identity;
17+
18+
/**
19+
* Link for the user to click to login to their account, verify their account and set their password (Single Use)
20+
*
21+
* @var string
22+
*/
23+
public $verifyAndSetLink;
24+
25+
}

0 commit comments

Comments
 (0)