@@ -150,6 +150,9 @@ |
||
150 | 150 | ); |
151 | 151 | } |
152 | 152 | |
153 | + /** |
|
154 | + * @param string $contents |
|
155 | + */ |
|
153 | 156 | private function parseEmail($contents) |
154 | 157 | { |
155 | 158 | $addresses = $this->parseEmailAddress($contents); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $core = $scope->getEnvironment()->getContext(CoreContext::class); |
50 | 50 | /* @var FileTransport $transport */ |
51 | 51 | $transport = $core->getServiceManager()->get('Core/MailService')->getTransport(); |
52 | - $path = $transport->getOptions()->getPath() . '/*.eml'; |
|
52 | + $path = $transport->getOptions()->getPath().'/*.eml'; |
|
53 | 53 | foreach (glob($path) as $filename) { |
54 | 54 | unlink($filename); |
55 | 55 | } |
@@ -105,25 +105,25 @@ discard block |
||
105 | 105 | $regex = '/.*('.preg_quote($text).').*/im'; |
106 | 106 | $matches = []; |
107 | 107 | $multiMessages = false; |
108 | - if(count($this->messages) > 1){ |
|
108 | + if (count($this->messages) > 1) { |
|
109 | 109 | $multiMessages = true; |
110 | 110 | } |
111 | 111 | $content = ""; |
112 | - foreach($this->messages as $key=>$definition){ |
|
112 | + foreach ($this->messages as $key=>$definition) { |
|
113 | 113 | $content = $definition['contents']; |
114 | - if(preg_match($regex,$content,$match)){ |
|
114 | + if (preg_match($regex, $content, $match)) { |
|
115 | 115 | $matches[] = $match; |
116 | 116 | } |
117 | 117 | } |
118 | - $failMessage = sprintf('Can not find text "%s" in any email sent',$text); |
|
119 | - if(!$multiMessages){ |
|
118 | + $failMessage = sprintf('Can not find text "%s" in any email sent', $text); |
|
119 | + if (!$multiMessages) { |
|
120 | 120 | $failMessage = sprintf( |
121 | 121 | 'Can not find text "%s" in sent email. Here\'s the email content: %s', |
122 | 122 | $text, |
123 | 123 | PHP_EOL.PHP_EOL.$content |
124 | 124 | ); |
125 | 125 | } |
126 | - Assert::true(count($matches)>0,$failMessage); |
|
126 | + Assert::true(count($matches) > 0, $failMessage); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -136,16 +136,16 @@ discard block |
||
136 | 136 | |
137 | 137 | $path = $transport->getOptions()->getPath().'/*.eml'; |
138 | 138 | |
139 | - foreach(glob($path) as $filename){ |
|
139 | + foreach (glob($path) as $filename) { |
|
140 | 140 | $id = md5($filename); |
141 | - if(!isset($this->messages[$id])){ |
|
141 | + if (!isset($this->messages[$id])) { |
|
142 | 142 | $contents = file_get_contents($filename); |
143 | - $this->messages[$id] = $this->parseEmail($contents); |
|
143 | + $this->messages[$id] = $this->parseEmail($contents); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | 147 | Assert::true( |
148 | - count($this->messages)>0, |
|
148 | + count($this->messages) > 0, |
|
149 | 149 | 'No email have been sent' |
150 | 150 | ); |
151 | 151 | } |
@@ -153,28 +153,28 @@ discard block |
||
153 | 153 | private function parseEmail($contents) |
154 | 154 | { |
155 | 155 | $addresses = $this->parseEmailAddress($contents); |
156 | - $subject =$this->parseSubject($contents); |
|
156 | + $subject = $this->parseSubject($contents); |
|
157 | 157 | |
158 | 158 | $contents = strip_tags($contents); |
159 | 159 | $contents = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $contents); |
160 | 160 | |
161 | - return array_merge($addresses,$subject,['contents' => $contents]); |
|
161 | + return array_merge($addresses, $subject, ['contents' => $contents]); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | private function parseEmailAddress($contents) |
165 | 165 | { |
166 | 166 | // pattern to get email address |
167 | - $radd = '(\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\b)'; |
|
167 | + $radd = '(\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\b)'; |
|
168 | 168 | |
169 | 169 | // get email from address |
170 | - $regex = sprintf('/^From\:.*%s/im',$radd); |
|
171 | - $hasMatch = preg_match($regex,$contents,$matches); |
|
172 | - $fromAddress = $hasMatch ? $matches[1]:null; |
|
170 | + $regex = sprintf('/^From\:.*%s/im', $radd); |
|
171 | + $hasMatch = preg_match($regex, $contents, $matches); |
|
172 | + $fromAddress = $hasMatch ? $matches[1] : null; |
|
173 | 173 | |
174 | 174 | // get email to address |
175 | - $regex = sprintf('/^To\:\s+%s/im',$radd); |
|
176 | - $hasMatch = preg_match($regex,$contents,$matches); |
|
177 | - $toAddress = $hasMatch ? $matches[1]:null; |
|
175 | + $regex = sprintf('/^To\:\s+%s/im', $radd); |
|
176 | + $hasMatch = preg_match($regex, $contents, $matches); |
|
177 | + $toAddress = $hasMatch ? $matches[1] : null; |
|
178 | 178 | |
179 | 179 | $this->fromMails[] = $fromAddress; |
180 | 180 | $this->toMails[] = $toAddress; |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | private function parseSubject($contents) |
189 | 189 | { |
190 | 190 | $pattern = '/Subject\:(.*)/i'; |
191 | - preg_match($pattern,$contents,$matches); |
|
192 | - $subject = isset($matches[1]) ? $matches[1]:null; |
|
191 | + preg_match($pattern, $contents, $matches); |
|
192 | + $subject = isset($matches[1]) ? $matches[1] : null; |
|
193 | 193 | $this->subjects[] = $subject; |
194 | 194 | return [ |
195 | 195 | 'subject' => trim($subject) |
@@ -32,7 +32,7 @@ |
||
32 | 32 | { |
33 | 33 | $options = $this->options; |
34 | 34 | $filename = call_user_func($options->getCallback(), $this); |
35 | - $file = $options->getPath() . DIRECTORY_SEPARATOR . $filename; |
|
35 | + $file = $options->getPath().DIRECTORY_SEPARATOR.$filename; |
|
36 | 36 | |
37 | 37 | |
38 | 38 | $contents = $message->toString(); |
@@ -26,41 +26,41 @@ |
||
26 | 26 | */ |
27 | 27 | class MailServiceFactory implements FactoryInterface |
28 | 28 | { |
29 | - public function __invoke( ContainerInterface $container, $requestedName, array $options = null ) |
|
30 | - { |
|
31 | - $config = $container->get('Config'); |
|
32 | - $mails = isset($config['mails']) ? $config['mails'] : []; |
|
29 | + public function __invoke( ContainerInterface $container, $requestedName, array $options = null ) |
|
30 | + { |
|
31 | + $config = $container->get('Config'); |
|
32 | + $mails = isset($config['mails']) ? $config['mails'] : []; |
|
33 | 33 | |
34 | - /* @var \Auth\Options\ModuleOptions $authOptions */ |
|
35 | - $authOptions = $container->get('Auth/Options'); |
|
34 | + /* @var \Auth\Options\ModuleOptions $authOptions */ |
|
35 | + $authOptions = $container->get('Auth/Options'); |
|
36 | 36 | |
37 | - /* @var \Core\Options\MailServiceOptions $mailServiceOptions */ |
|
38 | - $mailServiceOptions = $container->get('Core/MailServiceOptions'); |
|
37 | + /* @var \Core\Options\MailServiceOptions $mailServiceOptions */ |
|
38 | + $mailServiceOptions = $container->get('Core/MailServiceOptions'); |
|
39 | 39 | |
40 | - $configArray = [ |
|
41 | - 'from' => [ |
|
42 | - 'name' => $authOptions->getFromName(), |
|
43 | - 'email' => $authOptions->getFromEmail() |
|
44 | - ], |
|
45 | - ]; |
|
40 | + $configArray = [ |
|
41 | + 'from' => [ |
|
42 | + 'name' => $authOptions->getFromName(), |
|
43 | + 'email' => $authOptions->getFromEmail() |
|
44 | + ], |
|
45 | + ]; |
|
46 | 46 | |
47 | - $configArray['transport'] = $this->getTransport($mailServiceOptions); |
|
48 | - $configArray = array_merge($configArray, $mails); |
|
47 | + $configArray['transport'] = $this->getTransport($mailServiceOptions); |
|
48 | + $configArray = array_merge($configArray, $mails); |
|
49 | 49 | |
50 | - $config = new MailServiceConfig($configArray); |
|
51 | - $service = new MailService($container,$config->toArray()); |
|
52 | - $config->configureServiceManager($service); |
|
53 | - foreach($config->toArray() as $name=>$value){ |
|
54 | - $method = 'set'.$name; |
|
55 | - if(method_exists($service,$method)){ |
|
56 | - call_user_func([$service,$method],$value); |
|
57 | - } |
|
58 | - } |
|
50 | + $config = new MailServiceConfig($configArray); |
|
51 | + $service = new MailService($container,$config->toArray()); |
|
52 | + $config->configureServiceManager($service); |
|
53 | + foreach($config->toArray() as $name=>$value){ |
|
54 | + $method = 'set'.$name; |
|
55 | + if(method_exists($service,$method)){ |
|
56 | + call_user_func([$service,$method],$value); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - return $service; |
|
61 | - } |
|
60 | + return $service; |
|
61 | + } |
|
62 | 62 | |
63 | - public function getTransport(MailServiceOptions $mailServiceOptions) |
|
63 | + public function getTransport(MailServiceOptions $mailServiceOptions) |
|
64 | 64 | { |
65 | 65 | $type = $mailServiceOptions->getTransportClass(); |
66 | 66 | if (MailService::TRANSPORT_SMTP == $type) { |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | class MailServiceFactory implements FactoryInterface |
28 | 28 | { |
29 | - public function __invoke( ContainerInterface $container, $requestedName, array $options = null ) |
|
29 | + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
30 | 30 | { |
31 | 31 | $config = $container->get('Config'); |
32 | 32 | $mails = isset($config['mails']) ? $config['mails'] : []; |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | $configArray = array_merge($configArray, $mails); |
49 | 49 | |
50 | 50 | $config = new MailServiceConfig($configArray); |
51 | - $service = new MailService($container,$config->toArray()); |
|
51 | + $service = new MailService($container, $config->toArray()); |
|
52 | 52 | $config->configureServiceManager($service); |
53 | - foreach($config->toArray() as $name=>$value){ |
|
53 | + foreach ($config->toArray() as $name=>$value) { |
|
54 | 54 | $method = 'set'.$name; |
55 | - if(method_exists($service,$method)){ |
|
56 | - call_user_func([$service,$method],$value); |
|
55 | + if (method_exists($service, $method)) { |
|
56 | + call_user_func([$service, $method], $value); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | $type = $mailServiceOptions->getTransportClass(); |
66 | 66 | if (MailService::TRANSPORT_SMTP == $type) { |
67 | 67 | return new Smtp($mailServiceOptions); |
68 | - }elseif(MailService::TRANSPORT_FILE == $type){ |
|
68 | + }elseif (MailService::TRANSPORT_FILE == $type) { |
|
69 | 69 | $fileOptions = new FileOptions(); |
70 | 70 | $fileOptions->setPath($mailServiceOptions->getPath()); |
71 | 71 | return new FileTransport($fileOptions); |
72 | - }elseif(MailService::TRANSPORT_SENDMAIL == $type){ |
|
72 | + }elseif (MailService::TRANSPORT_SENDMAIL == $type) { |
|
73 | 73 | return new Sendmail(); |
74 | 74 | } |
75 | 75 |
@@ -65,11 +65,11 @@ |
||
65 | 65 | $type = $mailServiceOptions->getTransportClass(); |
66 | 66 | if (MailService::TRANSPORT_SMTP == $type) { |
67 | 67 | return new Smtp($mailServiceOptions); |
68 | - }elseif(MailService::TRANSPORT_FILE == $type){ |
|
68 | + } elseif(MailService::TRANSPORT_FILE == $type){ |
|
69 | 69 | $fileOptions = new FileOptions(); |
70 | 70 | $fileOptions->setPath($mailServiceOptions->getPath()); |
71 | 71 | return new FileTransport($fileOptions); |
72 | - }elseif(MailService::TRANSPORT_SENDMAIL == $type){ |
|
72 | + } elseif(MailService::TRANSPORT_SENDMAIL == $type){ |
|
73 | 73 | return new Sendmail(); |
74 | 74 | } |
75 | 75 |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | return $this; |
100 | 100 | } |
101 | 101 | |
102 | - public function getUsername(){ |
|
102 | + public function getUsername() { |
|
103 | 103 | return $this->connectionConfig['username']; |
104 | 104 | } |
105 | 105 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | return $this; |
111 | 111 | } |
112 | 112 | |
113 | - public function getPassword(){ |
|
113 | + public function getPassword() { |
|
114 | 114 | return $this->connectionConfig['password']; |
115 | 115 | } |
116 | 116 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return $this; |
122 | 122 | } |
123 | 123 | |
124 | - public function getSsl(){ |
|
124 | + public function getSsl() { |
|
125 | 125 | return $this->connectionConfig['ssl']; |
126 | 126 | } |
127 | 127 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | return $this; |
131 | 131 | } |
132 | 132 | |
133 | - public function getTransportClass(){ |
|
133 | + public function getTransportClass() { |
|
134 | 134 | return $this->transportClass; |
135 | 135 | } |
136 | 136 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function getPath() |
141 | 141 | { |
142 | - if(is_null($this->path)){ |
|
142 | + if (is_null($this->path)) { |
|
143 | 143 | $this->setPath(sys_get_temp_dir().'/yawik/mails'); |
144 | 144 | } |
145 | 145 | return $this->path; |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function setPath($path) |
153 | 153 | { |
154 | - if(!is_dir($path)){ |
|
155 | - mkdir($path,0777,true); |
|
156 | - chmod($path,0777); |
|
154 | + if (!is_dir($path)) { |
|
155 | + mkdir($path, 0777, true); |
|
156 | + chmod($path, 0777); |
|
157 | 157 | } |
158 | 158 | $this->path = $path; |
159 | 159 | return $this; |