Skip to content

Commit fe6cf2c

Browse files
authored
Merge pull request #1 from event-engine/feature/simplify-connections
Support sync of nodes
2 parents da05353 + fe27d19 commit fe6cf2c

23 files changed

+1241
-28
lines changed

.php-cs-fixer.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$config = new Prooph\CS\Config\Prooph();
6+
$finder = $config->getFinder();
7+
8+
$finder->exclude('vendor');
9+
$finder->in(__DIR__);
10+
$finder->append(['.php_cs']);
11+
12+
$cacheDir = \getenv('TRAVIS') ? \getenv('HOME') . '/.php-cs-fixer' : __DIR__;
13+
14+
$config->setCacheFile($cacheDir . '/.php_cs.cache');
15+
16+
return $config;

.php_cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Event Engine - PHP InspectIO Cody
22

3-
This is the repository of the Cody server. [InspectIO](https://github.com/event-engine/inspectio "InspectIO") can
4-
connect to a coding bot called [Cody](https://github.com/event-engine/inspectio/wiki/PHP-Cody-Tutorial "PHP Cody Tutorial").
3+
This is the repository of the Cody server. [prooph board](https://prooph-board.com/ "prooph board") can
4+
connect to a coding bot called [Cody](https://wiki.prooph-board.com/cody/php-cody-tutorial.html "PHP Cody Tutorial").
55
With its help you can generate working code from an event map.
66

77
Cody server runs at [http://localhost:3311](http://localhost:3311)
88

99
## Installation
1010

11+
> There is also an [Event Engine Cody Skeleton](https://github.com/proophboard/php-cody-engine-skeleton) available.
12+
1113
Please make sure you have installed [Docker](https://docs.docker.com/install/ "Install Docker")
1214
and [Docker Compose](https://docs.docker.com/compose/install/ "Install Docker Compose").
1315

14-
> An example usage / implementation of this library exists for [Event Engine](https://github.com/event-engine/php-code-generator-cody "Cody Bot for Event Engine").
15-
1616
It is recommended to create a new application for code generation which installs this library via Composer. This allows
1717
independence of your application code and avoids running in Composer dependency conflicts.
1818

@@ -36,7 +36,7 @@ cp vendor/event-engine/php-inspectio-cody/php-watcher.yml.dist .
3636
```
3737

3838
To mount our business application folder to the Cody server you have to update the `docker-compose.yml` file. Please
39-
take a look at the [Cody](https://github.com/event-engine/inspectio/wiki/PHP-Cody-Tutorial "PHP Cody Tutorial") for more
39+
take a look at the [Cody](https://wiki.prooph-board.com/cody/php-cody-tutorial.html "PHP Cody Tutorial") for more
4040
details.
4141

4242
## Start Cody Server

codyconfig.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@
1010

1111
use EventEngine\InspectioCody\CodyConfig;
1212

13-
$context = new stdClass(); // replace it with your own context class
13+
$context = new class() implements \EventEngine\InspectioCody\CodyContext {
14+
public function isFullSyncRequired(): bool
15+
{
16+
// TODO: Implement isFullSyncRequired() method.
17+
return false;
18+
}
19+
20+
public function clearGraph(): void
21+
{
22+
// TODO: Implement clearGraph() method.
23+
}
24+
}; // replace it with your own context class
1425

1526
return new CodyConfig(
1627
$context,
@@ -20,5 +31,14 @@
2031
// CodyConfig::HOOK_ON_EVENT => new EventHook(),
2132
// CodyConfig::HOOK_ON_POLICY => new PolicyHook(),
2233
// CodyConfig::HOOK_ON_DOCUMENT => new DocumentHook(),
34+
// CodyConfig::HOOK_ON_EXTERNAL_SYSTEM => new ExternalSystemHook(),
35+
// CodyConfig::HOOK_ON_HOT_SPOT => new HotSpotHook(),
36+
// CodyConfig::HOOK_ON_ROLE => new RoleHook(),
37+
// CodyConfig::HOOK_ON_UI => new UiHook(),
38+
// CodyConfig::HOOK_ON_FEATURE => new FeatureHook(),
39+
// CodyConfig::HOOK_ON_BOUNDED_CONTEXT => new BoundedContextHook(),
40+
// CodyConfig::HOOK_ON_SYNC => new SyncHook(),
41+
// CodyConfig::HOOK_ON_SYNC_UPDATED => new SyncHook(),
42+
// CodyConfig::HOOK_ON_SYNC_DELETED => new SyncDeletedHook(),
2343
]
2444
);

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"php": "^7.4 || ^8.0",
3434
"ext-json": "*",
3535
"christoph-kluge/reactphp-http-cors-middleware": "^2.0.0",
36-
"event-engine/php-inspectio-graph-cody": "dev-master",
36+
"event-engine/php-inspectio-graph-cody": "^0.1.0",
3737
"fig/http-message-util": "^1.1",
3838
"open-code-modeling/php-code-generator-transformator": "^0.1.0",
3939
"psr/http-message": "^1.0",
@@ -46,8 +46,8 @@
4646
"phpstan/phpstan": "^0.12.33",
4747
"phpstan/phpstan-strict-rules": "^0.12.4",
4848
"phpunit/phpunit": "^9.2.6",
49-
"prooph/php-cs-fixer-config": "^0.4",
50-
"roave/security-advisories": "dev-master"
49+
"prooph/php-cs-fixer-config": "^0.5.0",
50+
"roave/security-advisories": "dev-latest"
5151
},
5252
"minimum-stability": "dev",
5353
"prefer-stable": true,

src/CodyConfig.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,45 @@
1313
final class CodyConfig
1414
{
1515
public const HOOK_ON_COMMAND = 'onCommand';
16+
1617
public const HOOK_ON_AGGREGATE = 'onAggregate';
18+
1719
public const HOOK_ON_EVENT = 'onEvent';
20+
1821
public const HOOK_ON_POLICY = 'onPolicy';
22+
1923
public const HOOK_ON_DOCUMENT = 'onDocument';
24+
25+
public const HOOK_ON_EXTERNAL_SYSTEM = 'onExternalSystem';
26+
27+
public const HOOK_ON_HOT_SPOT = 'onHotSpot';
28+
29+
public const HOOK_ON_ROLE = 'onRole';
30+
2031
public const HOOK_ON_UI = 'onUi';
32+
2133
public const HOOK_ON_FEATURE = 'onFeature';
34+
2235
public const HOOK_ON_BOUNDED_CONTEXT = 'onBoundedContext';
2336

37+
public const HOOK_ON_SYNC = 'onSync';
38+
39+
public const HOOK_ON_SYNC_UPDATED = 'onSyncUpdated';
40+
41+
public const HOOK_ON_SYNC_DELETED = 'onSyncDeleted';
42+
2443
/**
2544
* @var array
2645
**/
2746
private $hooks;
2847

29-
private $context;
48+
private CodyContext $context;
3049

31-
public function __construct($context, array $hooks)
50+
/**
51+
* @param CodyContext $context Context which is provided to each hook
52+
* @param array $hooks List of implemented hooks
53+
*/
54+
public function __construct(CodyContext $context, array $hooks)
3255
{
3356
$this->context = $context;
3457
$this->hooks = $hooks;
@@ -44,10 +67,7 @@ public function hook(string $hookName)
4467
return $this->hooks[$hookName];
4568
}
4669

47-
/**
48-
* @return mixed
49-
*/
50-
public function context()
70+
public function context(): CodyContext
5171
{
5272
return $this->context;
5373
}

src/CodyContext.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* @see https://github.com/event-engine/php-inspectio-cody for the canonical source repository
5+
* @copyright https://github.com/event-engine/php-inspectio-cody/blob/master/COPYRIGHT.md
6+
* @license https://github.com/event-engine/php-inspectio-cody/blob/master/LICENSE.md MIT License
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace EventEngine\InspectioCody;
12+
13+
interface CodyContext
14+
{
15+
/**
16+
* Whether or not context has nodes e.g. to decide to trigger full sync
17+
*
18+
* @return bool
19+
*/
20+
public function isFullSyncRequired(): bool;
21+
22+
/**
23+
* Clear the graph because it's out of sync and needs complete new sync
24+
*
25+
* @return void
26+
*/
27+
public function clearGraph(): void;
28+
}

src/General/Greetings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static function greeting(string $user): CodyResponse
2323
'If you need guidance just ask me with: %c/help',
2424
'background-color: rgba(251, 159, 75, 0.2)',
2525
],
26+
CodyResponse::SYNC_REQUIRED
2627
);
2728
}
2829

src/Http/Message/CodyResponse.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@
1515
interface CodyResponse extends ResponseInterface
1616
{
1717
public const INFO = 'Info';
18+
1819
public const ERROR = 'Error';
20+
1921
public const WARNING = 'Warning';
22+
2023
public const QUESTION = 'Question';
2124

25+
public const EMPTY = 'Empty';
26+
27+
public const SYNC_REQUIRED = 'SyncRequired';
28+
2229
/**
2330
* @return string|string[]
2431
*/

src/Http/Message/Response.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ public static function error(string $error, array $details = []): CodyResponse
8686
);
8787
}
8888

89+
public static function empty(): CodyResponse
90+
{
91+
return self::fromCody(
92+
'',
93+
[],
94+
self::EMPTY
95+
);
96+
}
97+
98+
public static function syncRequired(): CodyResponse
99+
{
100+
return self::fromCody(
101+
'I need to sync all elements first.',
102+
["Lean back for a moment. I'll let you know when I'm done."],
103+
self::SYNC_REQUIRED
104+
);
105+
}
106+
89107
public static function noJsonRequest(): CodyResponse
90108
{
91109
return self::fromCody(

0 commit comments

Comments
 (0)