1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FondBot\Foundation\Providers; |
6
|
|
|
|
7
|
|
|
use ReflectionClass; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
use FondBot\Conversation\Intent; |
10
|
|
|
use FondBot\Framework\Application; |
11
|
|
|
use Symfony\Component\Finder\Finder; |
12
|
|
|
use Illuminate\Support\ServiceProvider; |
13
|
|
|
use FondBot\Conversation\FallbackIntent; |
14
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
15
|
|
|
use FondBot\Contracts\Conversation\Manager; |
16
|
|
|
use FondBot\Conversation\ConversationManager; |
17
|
|
|
use Illuminate\Contracts\Cache\Repository as Cache; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @property Application $app |
21
|
|
|
*/ |
22
|
|
|
class ConversationServiceProvider extends ServiceProvider |
23
|
|
|
{ |
24
|
|
|
protected $intents = []; |
25
|
|
|
protected $fallbackIntent = FallbackIntent::class; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Register application services. |
29
|
|
|
*/ |
30
|
88 |
|
public function register(): void |
31
|
|
|
{ |
32
|
88 |
|
$this->registerManager(); |
33
|
88 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Boot application services. |
37
|
|
|
*/ |
38
|
88 |
|
public function boot(): void |
39
|
|
|
{ |
40
|
|
|
/** @var Manager $manager */ |
41
|
88 |
|
$manager = $this->app['conversation']; |
42
|
|
|
|
43
|
88 |
|
foreach ($this->intents as $intent) { |
44
|
|
|
$manager->registerIntent($intent); |
45
|
|
|
} |
46
|
|
|
|
47
|
88 |
|
$manager->registerFallbackIntent($this->fallbackIntent); |
48
|
|
|
|
49
|
88 |
|
if (method_exists($this, 'configure')) { |
50
|
|
|
$this->configure(); |
|
|
|
|
51
|
|
|
} |
52
|
88 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Load intents from path. |
56
|
|
|
* |
57
|
|
|
* @param string $path |
58
|
|
|
*/ |
59
|
|
|
protected function load(string $path): void |
60
|
|
|
{ |
61
|
|
|
$namespace = $this->app->getNamespace(); |
62
|
|
|
|
63
|
|
|
/** @var SplFileInfo[] $files */ |
64
|
|
|
$files = (new Finder)->in($path)->files(); |
65
|
|
|
|
66
|
|
|
foreach ($files as $file) { |
67
|
|
|
$file = $namespace.str_replace( |
68
|
|
|
['/', '.php'], |
69
|
|
|
['\\', ''], |
70
|
|
|
Str::after($file->getPathname(), app_path().DIRECTORY_SEPARATOR) |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
if (is_subclass_of($file, Intent::class) && !(new ReflectionClass($file))->isAbstract()) { |
|
|
|
|
74
|
|
|
$this->app['conversation']->registerIntent($file); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function registerManager(): void |
80
|
|
|
{ |
81
|
88 |
|
$this->app->singleton('conversation', function () { |
82
|
88 |
|
return new ConversationManager($this->app, $this->app[Cache::class]); |
83
|
88 |
|
}); |
84
|
|
|
|
85
|
88 |
|
$this->app->alias('conversation', Manager::class); |
86
|
88 |
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.