Skip to content

Commit 74021d3

Browse files
committed
Add exception and deprecated factory method "createExternalApiClient"
1 parent eea8f44 commit 74021d3

File tree

4 files changed

+76
-9
lines changed

4 files changed

+76
-9
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Ang3\Component\OdooApiClient\Exception;
4+
5+
use Throwable;
6+
7+
/**
8+
* @author Joanis ROUANET
9+
*/
10+
class ClientConfigException extends OdooException
11+
{
12+
/**
13+
* @var array
14+
*/
15+
private $config;
16+
17+
/**
18+
* Constructor of the exception.
19+
*
20+
* @param string $message
21+
* @param array $config
22+
* @param Throwable|null $previous
23+
*/
24+
public function __construct(string $message, array $config = [], Throwable $previous = null)
25+
{
26+
// Hydratation
27+
$this->config = $config;
28+
29+
// Construction de l'exception parent
30+
parent::__construct($message, 0, $previous);
31+
}
32+
33+
/**
34+
* @return array
35+
*/
36+
public function getConfig()
37+
{
38+
return $this->config;
39+
}
40+
}

src/Exception/OdooException.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Ang3\Component\OdooApiClient\Exception;
4+
5+
use RuntimeException;
6+
7+
/**
8+
* @author Joanis ROUANET
9+
*/
10+
class OdooException extends RuntimeException
11+
{
12+
}

src/Exception/RequestException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace Ang3\Component\OdooApiClient\Exception;
44

5-
use RuntimeException;
65
use Throwable;
76
use Ang3\Component\OdooApiClient\ExternalApiClient;
87

98
/**
109
* @author Joanis ROUANET
1110
*/
12-
class RequestException extends RuntimeException
11+
class RequestException extends OdooException
1312
{
1413
/**
1514
* @var ExternalApiClient
@@ -45,6 +44,7 @@ class RequestException extends RuntimeException
4544
* @param array $parameters
4645
* @param array $options
4746
* @param array $result
47+
* @param Throwable|null $previous
4848
*/
4949
public function __construct(ExternalApiClient $client, $method, $modelName, array $parameters = [], array $options = [], array $result = [], Throwable $previous = null)
5050
{

src/Factory/ApiClientFactory.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Ang3\Component\OdooApiClient\Factory;
44

5-
use InvalidArgumentException;
5+
use Ang3\Component\OdooApiClient\Exception\ClientConfigException;
66
use Ang3\Component\OdooApiClient\ExternalApiClient;
77

88
/**
@@ -12,36 +12,51 @@
1212
*/
1313
class ApiClientFactory
1414
{
15+
/**
16+
* @deprecated This method will be removed in 3.0. Please use method "create" instead.
17+
*
18+
* @param array $parameters
19+
* @param array $options
20+
*
21+
* @return ExternalApiClient
22+
*/
23+
public function createExternalApiClient(array $parameters = [], array $options = [])
24+
{
25+
trigger_error(sprintf('The method %s:%s() is deprecated and will be removed in 3.0. Please use %s:create() instead.', __CLASS__, __METHOD__, __CLASS__), E_USER_DEPRECATED);
26+
27+
return $this->create($parameters, $options);
28+
}
29+
1530
/**
1631
* Create external API client for Odoo from config array.
1732
*
1833
* @param array $parameters
1934
* @param array $options
2035
*
21-
* @throws InvalidArgumentException when a required parameter is missing
36+
* @throws ClientConfigException when a required parameter is missing
2237
*
2338
* @return ExternalApiClient
2439
*/
25-
public function createExternalApiClient(array $parameters = [], array $options = [])
40+
public function create(array $parameters = [], array $options = [])
2641
{
2742
// Si pas d'URL
2843
if (!array_key_exists('url', $parameters)) {
29-
throw new InvalidArgumentException('Missing required parameter "url".');
44+
throw new ClientConfigException('Missing required parameter "url".');
3045
}
3146

3247
// Si pas de nom de base de données Odoo
3348
if (!array_key_exists('database', $parameters)) {
34-
throw new InvalidArgumentException('Missing required parameter "database".');
49+
throw new ClientConfigException('Missing required parameter "database".');
3550
}
3651

3752
// Si pas d'utilisateur
3853
if (!array_key_exists('user', $parameters)) {
39-
throw new InvalidArgumentException('Missing required parameter "user".');
54+
throw new ClientConfigException('Missing required parameter "user".');
4055
}
4156

4257
// Si pas de mot de passe
4358
if (!array_key_exists('password', $parameters)) {
44-
throw new InvalidArgumentException('Missing required parameter "password".');
59+
throw new ClientConfigException('Missing required parameter "password".');
4560
}
4661

4762
// Récupération des options éventuelles du client

0 commit comments

Comments
 (0)