1
|
|
|
<?php namespace nyx\notify; |
2
|
|
|
|
3
|
|
|
// External dependencies |
4
|
|
|
use Illuminate\Contracts\Foundation\Application; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Notify Service Provider |
8
|
|
|
* |
9
|
|
|
* @package Nyx\Notify |
10
|
|
|
* @version 0.1.0 |
11
|
|
|
* @author Michal Chojnacki <[email protected]> |
12
|
|
|
* @copyright 2012-2017 Nyx Dev Team |
13
|
|
|
* @link https://github.com/unyx/nyx |
14
|
|
|
* @todo Make 'mailer' subservice registration optional? Drop the "mailer" name for the FQN of the interface? |
15
|
|
|
* @todo Queue support for the Mailer? |
16
|
|
|
*/ |
17
|
|
|
class Service extends \Illuminate\Support\ServiceProvider |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
*/ |
22
|
|
|
public function register() |
23
|
|
|
{ |
24
|
|
|
$this->app->singleton(TransportManager::class, function (Application $app) { |
25
|
|
|
return new TransportManager($app); |
|
|
|
|
26
|
|
|
}); |
27
|
|
|
|
28
|
|
|
$this->app->alias(TransportManager::class, interfaces\Dispatcher::class); |
29
|
|
|
|
30
|
|
|
// Mailer (currently - see the to-do) gets made available as a standalone subservice. Subject to change. |
31
|
|
|
$this->registerMailer(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Registers the Mail subcomponent as a standalone service for situations where Messages may need to get sent |
36
|
|
|
* bypassing the way Notifications are otherwise handled. |
37
|
|
|
*/ |
38
|
|
|
protected function registerMailer() |
39
|
|
|
{ |
40
|
|
|
$this->app->singleton('mailer', function (Application $app) { |
41
|
|
|
|
42
|
|
|
$mailer = new transports\mail\Mailer($app->make('mailer.transport'), $app->make('view')); |
43
|
|
|
|
44
|
|
|
// Set the 'always from' and 'always to' options on the Mailer if they have been configured. |
45
|
|
|
$config = $app->make('config')->get('mail'); |
46
|
|
|
|
47
|
|
|
if (isset($config['from'])) { |
48
|
|
|
$mailer->setAlwaysFrom($config['from']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (isset($config['to'])) { |
52
|
|
|
$mailer->setAlwaysTo($config['to']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $mailer; |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
// Make the humanized name an alias for the Mailer Interface's FQN so both can be used interchangeably. |
59
|
|
|
$this->app->alias('mailer', transports\mail\interfaces\Mailer::class); |
60
|
|
|
|
61
|
|
|
// We are going to need to instantiate the Mailer with a proper Driver. |
62
|
|
|
// @todo Drop the DriverManager in favour of handling the logic in this very Service Provider itself? |
63
|
|
|
$this->app->bind('mailer.transport', $this->app->share(function (Application $app) { |
|
|
|
|
64
|
|
|
return (new transports\mail\DriverManager($app))->driver(); |
|
|
|
|
65
|
|
|
})); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: