1
|
|
|
<?php |
2
|
|
|
namespace VatNumberCheck\Controller; |
3
|
|
|
|
4
|
|
|
use Cake\Event\Event; |
5
|
|
|
use Cake\Network\Exception\InternalErrorException; |
6
|
|
|
use VatNumberCheck\Utility\VatNumberCheck; |
7
|
|
|
/** |
8
|
|
|
* VatNumberChecks Controller. |
9
|
|
|
* |
10
|
|
|
* @property \Cake\Controller\Component\RequestHandlerComponent $RequestHandler |
11
|
|
|
* @property \VatNumberCheck\Utility\VatNumberCheck $VatNumberCheck |
12
|
|
|
*/ |
13
|
|
|
class VatNumberChecksController extends AppController |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Constructor |
17
|
|
|
* |
18
|
|
|
* @param CakeRequest $request Request instance. |
|
|
|
|
19
|
|
|
* @param CakeResponse $response Response instance. |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
public function __construct($request = null, $response = null) { |
22
|
|
|
parent::__construct($request, $response); |
23
|
|
|
$this->constructClasses(); |
|
|
|
|
24
|
|
|
if (!$this->Components->attached('RequestHandler')) { |
|
|
|
|
25
|
|
|
$this->RequestHandler = $this->Components->load('RequestHandler'); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Called before the controller action. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function beforeFilter() { |
35
|
|
|
parent::beforeFilter(); |
|
|
|
|
36
|
|
|
if (in_array($this->request->action, ['check'], true)) { |
37
|
|
|
// Disable Security component checks |
38
|
|
|
if ($this->Components->enabled('Security')) { |
|
|
|
|
39
|
|
|
$this->Components->disable('Security'); |
40
|
|
|
} |
41
|
|
|
// Allow action without authentication |
42
|
|
|
if ($this->Components->enabled('Auth')) { |
43
|
|
|
$this->Auth->allow($this->request->action); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Checks a given vat number (from POST data). |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function check() { |
54
|
|
|
$vatNumber = $this->request->data('vatNumber') ?: ''; |
|
|
|
|
55
|
|
|
$vatNumber = $this->VatNumberCheck->normalize($vatNumber); |
|
|
|
|
56
|
|
|
$jsonData = array_merge(compact('vatNumber'), ['status' => 'failure']); |
57
|
|
|
try { |
58
|
|
|
$vatNumberValid = $this->VatNumberCheck->check($vatNumber); |
59
|
|
|
if ($vatNumberValid) { |
60
|
|
|
$jsonData = array_merge(compact('vatNumber'), ['status' => 'ok']); |
61
|
|
|
} |
62
|
|
|
} catch (Exception $e) { |
|
|
|
|
63
|
|
|
$this->response->statusCode(503); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
$this->set(compact('jsonData')); |
66
|
|
|
$this->set('_serialize', 'jsonData'); |
67
|
|
|
} |
68
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths